agora inbox for [email protected]
help / color / mirror / Atom feedFrom: Julien Rouhaud <[email protected]>
Subject: [PATCH v1 4/5] Debugging: automatically shuffle all table attributes physical position.
Date: Sun, 5 Jun 2022 03:06:55 +0800
Author: Julien Rouhaud
Reviewed-by: FIXME
Discussion: FIXME
---
src/backend/commands/tablecmds.c | 55 ++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 007e355d9d..06b9733717 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -635,6 +635,18 @@ static void ATDetachCheckNoForeignKeyRefs(Relation partition);
static char GetAttributeCompression(Oid atttypid, char *compression);
+static int
+cmp_att_reversed(const void *a, const void *b)
+{
+ FormData_pg_attribute *atta = (FormData_pg_attribute *) a;
+ FormData_pg_attribute *attb = (FormData_pg_attribute *) b;
+
+ return (atta->attphysnum > attb->attphysnum) ? -1
+ : (atta->attphysnum == attb->attphysnum) ? 0
+ : 1;
+}
+
+
/* ----------------------------------------------------------------
* DefineRelation
* Creates a new relation.
@@ -933,6 +945,49 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
colDef->compression);
}
+ /*
+ * FIXME
+ * testing mode: inverse all attribute positions. This has to be done
+ * after that defaults have been computed.
+ */
+ if (relkind == RELKIND_RELATION && inheritOids == NIL
+ && descriptor->natts > 1
+ /* lame attempt to discard CTAS */
+ && queryString != NULL)
+ {
+ AttrNumber *mappings;
+
+ mappings = palloc(sizeof(AttrNumber) * (descriptor->natts + 1));
+
+ qsort(descriptor->attrs, descriptor->natts,
+ sizeof(FormData_pg_attribute),
+ cmp_att_reversed);
+
+ for (int i = 0; i < descriptor->natts; i++)
+ {
+ Form_pg_attribute att = TupleDescAttr(descriptor, i);
+
+ mappings[att->attphysnum] = i + 1;
+
+ att->attnum = att->attphysnum;
+ att->attphysnum = i + 1;
+ }
+
+ /* Fixup the defautls references */
+ foreach(listptr, rawDefaults)
+ {
+ RawColumnDefault *rowEnt = lfirst(listptr);
+
+ rowEnt->attphysnum = mappings[rowEnt->attphysnum];
+ }
+ foreach(listptr, cookedDefaults)
+ {
+ CookedConstraint *cooked = lfirst(listptr);
+
+ cooked->attphysnum = mappings[cooked->attphysnum];
+ }
+ }
+
/*
* If the statement hasn't specified an access method, but we're defining
* a type of relation that needs one, use the default.
--
2.33.1
--niuvl3z5xzutv25e
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v1-0005-POC-Add-naive-grammar-to-specify-the-column-logic.patch"
view thread (3+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [PATCH v1 4/5] Debugging: automatically shuffle all table attributes physical position.
In-Reply-To: <no-message-id-128329@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox