v3-0005-Try-a-larger-CompactAttribute-struct-without-flag.patch
application/octet-stream
Filename: v3-0005-Try-a-larger-CompactAttribute-struct-without-flag.patch
Type: application/octet-stream
Part: 7
Message:
Re: Make tuple deformation faster
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v3-0005
Subject: Try a larger CompactAttribute struct without flags
| File | + | − |
|---|---|---|
| src/backend/access/common/tupdesc.c | 7 | 14 |
| src/include/access/tupdesc.h | 13 | 26 |
From d1ec19a46a480b0c75f9df468b2765ad4e51dce2 Mon Sep 17 00:00:00 2001
From: David Rowley <dgrowley@gmail.com>
Date: Tue, 3 Sep 2024 14:05:30 +1200
Subject: [PATCH v3 5/5] Try a larger CompactAttribute struct without flags
Benchmarks have shown that making the CompactAttribute struct larger and
getting rid of the flags to reduce the bitwise-ANDing requirements makes
things go faster.
---
src/backend/access/common/tupdesc.c | 21 ++++++----------
src/include/access/tupdesc.h | 39 ++++++++++-------------------
2 files changed, 20 insertions(+), 40 deletions(-)
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 74f22cffb9..95c92e6585 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -67,20 +67,13 @@ populate_compact_attribute(TupleDesc tupdesc, int i)
dst->attcacheoff = -1;
dst->attlen = src->attlen;
- dst->attflags = 0;
-
- if (src->attbyval)
- dst->attflags |= COMPACT_ATTR_FLAG_BYVAL;
- if (src->attstorage != TYPSTORAGE_PLAIN)
- dst->attflags |= COMPACT_ATTR_FLAG_IS_PACKABLE;
- if (src->atthasmissing)
- dst->attflags |= COMPACT_ATTR_FLAG_HAS_MISSING;
- if (src->attisdropped)
- dst->attflags |= COMPACT_ATTR_FLAG_IS_DROPPED;
- if (src->attgenerated)
- dst->attflags |= COMPACT_ATTR_FLAG_IS_GENERATED;
- if (src->attnotnull)
- dst->attflags |= COMPACT_ATTR_FLAG_IS_NOTNULL;
+
+ dst->attbyval = src->attbyval;
+ dst->attispackable = (src->attstorage != TYPSTORAGE_PLAIN);
+ dst->atthasmissing = src->atthasmissing;
+ dst->attisdropped = src->attisdropped;
+ dst->attgenerated = src->attgenerated;
+ dst->attnotnull = src->attnotnull;
switch (src->attalign)
{
diff --git a/src/include/access/tupdesc.h b/src/include/access/tupdesc.h
index dc0f64c6d2..7bff43b4f7 100644
--- a/src/include/access/tupdesc.h
+++ b/src/include/access/tupdesc.h
@@ -55,35 +55,22 @@ typedef struct CompactAttribute
int32 attcacheoff; /* fixed offset into tuple, if known, or -1 */
int16 attlen; /* attr len in bytes or -1 = varlen, -2 =
* cstring */
- uint8 attflags; /* bit flags for compact storage of bool
- * fields */
+ bool attbyval; /* as FormData_pg_attribute.attbyval */
+ bool attispackable; /* as FormData_pg_attribute.attstorage !=
+ * TYPSTORAGE_PLAIN */
+ bool atthasmissing; /* as FormData_pg_attribute.atthasmissing */
+ bool attisdropped; /* as FormData_pg_attribute.attisdropped */
+ bool attgenerated; /* as FormData_pg_attribute.attgenerated */
+ bool attnotnull; /* as FormData_pg_attribute.attnotnull */
uint8 attalignby; /* alignment requirement in bytes */
} CompactAttribute;
-#define COMPACT_ATTR_FLAG_BYVAL (1 << 0)
-#define COMPACT_ATTR_FLAG_IS_PACKABLE (1 << 1)
-#define COMPACT_ATTR_FLAG_HAS_MISSING (1 << 2)
-#define COMPACT_ATTR_FLAG_IS_DROPPED (1 << 3)
-#define COMPACT_ATTR_FLAG_IS_GENERATED (1 << 4)
-#define COMPACT_ATTR_FLAG_IS_NOTNULL (1 << 5)
-
-#define CompactAttrByVal(att) \
- (((att)->attflags & COMPACT_ATTR_FLAG_BYVAL) != 0)
-
-#define CompactAttrIsPackable(att) \
- (((att)->attflags & COMPACT_ATTR_FLAG_IS_PACKABLE) != 0)
-
-#define CompactAttrHasMissing(att) \
- (((att)->attflags & COMPACT_ATTR_FLAG_HAS_MISSING) != 0)
-
-#define CompactAttrIsDropped(att) \
- (((att)->attflags & COMPACT_ATTR_FLAG_IS_DROPPED) != 0)
-
-#define CompactAttrIsGenerated(att) \
- (((att)->attflags & COMPACT_ATTR_FLAG_IS_GENERATED) != 0)
-
-#define CompactAttrIsNotNull(att) \
- (((att)->attflags & COMPACT_ATTR_FLAG_IS_NOTNULL) != 0)
+#define CompactAttrByVal(att) ((att)->attbyval)
+#define CompactAttrIsPackable(att) ((att)->attispackable)
+#define CompactAttrHasMissing(att) ((att)->atthasmissing)
+#define CompactAttrIsDropped(att) ((att)->attisdropped)
+#define CompactAttrIsGenerated(att) ((att)->attgenerated)
+#define CompactAttrIsNotNull(att) ((att)->attnotnull)
/*
* This struct is passed around within the backend to describe the structure
--
2.43.0