mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Remove pg_constraint.conincluding
This column was added in commit 8224de4f42
("Indexes with INCLUDE
columns and their support in B-tree") to ease writing the ruleutils.c
supporting code for that feature, but it turns out to be unnecessary --
we can do the same thing with just one more syscache lookup.
Even the documentation for the new column being removed in this commit
is awkward.
Discussion: https://postgr.es/m/20180902165018.33otxftp3olgtu4t@alvherre.pgsql
This commit is contained in:
@ -315,7 +315,7 @@ static char *deparse_expression_pretty(Node *expr, List *dpcontext,
|
||||
static char *pg_get_viewdef_worker(Oid viewoid,
|
||||
int prettyFlags, int wrapColumn);
|
||||
static char *pg_get_triggerdef_worker(Oid trigid, bool pretty);
|
||||
static void decompile_column_index_array(Datum column_index_array, Oid relId,
|
||||
static int decompile_column_index_array(Datum column_index_array, Oid relId,
|
||||
StringInfo buf);
|
||||
static char *pg_get_ruledef_worker(Oid ruleoid, int prettyFlags);
|
||||
static char *pg_get_indexdef_worker(Oid indexrelid, int colno,
|
||||
@ -2055,6 +2055,8 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
|
||||
Datum val;
|
||||
bool isnull;
|
||||
Oid indexId;
|
||||
int keyatts;
|
||||
HeapTuple indtup;
|
||||
|
||||
/* Start off the constraint definition */
|
||||
if (conForm->contype == CONSTRAINT_PRIMARY)
|
||||
@ -2069,24 +2071,52 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
|
||||
elog(ERROR, "null conkey for constraint %u",
|
||||
constraintId);
|
||||
|
||||
decompile_column_index_array(val, conForm->conrelid, &buf);
|
||||
keyatts = decompile_column_index_array(val, conForm->conrelid, &buf);
|
||||
|
||||
appendStringInfoChar(&buf, ')');
|
||||
|
||||
/* Fetch and build including column list */
|
||||
isnull = true;
|
||||
val = SysCacheGetAttr(CONSTROID, tup,
|
||||
Anum_pg_constraint_conincluding, &isnull);
|
||||
if (!isnull)
|
||||
indexId = get_constraint_index(constraintId);
|
||||
|
||||
/* Build including column list (from pg_index.indkeys) */
|
||||
indtup = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexId));
|
||||
if (!HeapTupleIsValid(indtup))
|
||||
elog(ERROR, "cache lookup failed for index %u", indexId);
|
||||
val = SysCacheGetAttr(INDEXRELID, indtup,
|
||||
Anum_pg_index_indnatts, &isnull);
|
||||
if (isnull)
|
||||
elog(ERROR, "null indnatts for index %u", indexId);
|
||||
if (DatumGetInt32(val) > keyatts)
|
||||
{
|
||||
Datum cols;
|
||||
Datum *keys;
|
||||
int nKeys;
|
||||
int j;
|
||||
|
||||
appendStringInfoString(&buf, " INCLUDE (");
|
||||
|
||||
decompile_column_index_array(val, conForm->conrelid, &buf);
|
||||
cols = SysCacheGetAttr(INDEXRELID, indtup,
|
||||
Anum_pg_index_indkey, &isnull);
|
||||
if (isnull)
|
||||
elog(ERROR, "null indkey for index %u", indexId);
|
||||
|
||||
deconstruct_array(DatumGetArrayTypeP(cols),
|
||||
INT2OID, 2, true, 's',
|
||||
&keys, NULL, &nKeys);
|
||||
|
||||
for (j = keyatts; j < nKeys; j++)
|
||||
{
|
||||
char *colName;
|
||||
|
||||
colName = get_attname(conForm->conrelid,
|
||||
DatumGetInt16(keys[j]), false);
|
||||
if (j > keyatts)
|
||||
appendStringInfoString(&buf, ", ");
|
||||
appendStringInfoString(&buf, quote_identifier(colName));
|
||||
}
|
||||
|
||||
appendStringInfoChar(&buf, ')');
|
||||
}
|
||||
|
||||
indexId = get_constraint_index(constraintId);
|
||||
ReleaseSysCache(indtup);
|
||||
|
||||
/* XXX why do we only print these bits if fullCommand? */
|
||||
if (fullCommand && OidIsValid(indexId))
|
||||
@ -2232,9 +2262,10 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
|
||||
|
||||
/*
|
||||
* Convert an int16[] Datum into a comma-separated list of column names
|
||||
* for the indicated relation; append the list to buf.
|
||||
* for the indicated relation; append the list to buf. Returns the number
|
||||
* of keys.
|
||||
*/
|
||||
static void
|
||||
static int
|
||||
decompile_column_index_array(Datum column_index_array, Oid relId,
|
||||
StringInfo buf)
|
||||
{
|
||||
@ -2258,6 +2289,8 @@ decompile_column_index_array(Datum column_index_array, Oid relId,
|
||||
else
|
||||
appendStringInfo(buf, ", %s", quote_identifier(colName));
|
||||
}
|
||||
|
||||
return nKeys;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user