Skip to content

Commit

Permalink
PG16: Handle DefineIndex's new parameter
Browse files Browse the repository at this point in the history
PG16 adds a new parameter to DefineIndex, total_parts, that takes in the
total number of direct and indirect partitions of the relation. Updated
all the callers to pass either the actual number if it is known or -1 if
it is unknown at that point.

postgres/postgres@27f5c712
  • Loading branch information
lkshminarayanan committed Aug 8, 2023
1 parent 3af0d28 commit 2eb0a38
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 40 deletions.
53 changes: 53 additions & 0 deletions src/compat/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,4 +795,57 @@ RelationGetSmgr(Relation rel)
#endif
#endif

/*
* PG16 adds a new parameter to DefineIndex, total_parts, that takes
* in the total number of direct and indirect partitions of the relation.
*
* https://github.com/postgres/postgres/commit/27f5c712
*/
#if PG16_LT
#define DefineIndexCompat(relationId, \
stmt, \
indexRelationId, \
parentIndexId, \
parentConstraintId, \
total_parts, \
is_alter_table, \
check_rights, \
check_not_in_use, \
skip_build, \
quiet) \
DefineIndex(relationId, \
stmt, \
indexRelationId, \
parentIndexId, \
parentConstraintId, \
is_alter_table, \
check_rights, \
check_not_in_use, \
skip_build, \
quiet)
#else
#define DefineIndexCompat(relationId, \
stmt, \
indexRelationId, \
parentIndexId, \
parentConstraintId, \
total_parts, \
is_alter_table, \
check_rights, \
check_not_in_use, \
skip_build, \
quiet) \
DefineIndex(relationId, \
stmt, \
indexRelationId, \
parentIndexId, \
parentConstraintId, \
total_parts, \
is_alter_table, \
check_rights, \
check_not_in_use, \
skip_build, \
quiet)
#endif

#endif /* TIMESCALEDB_COMPAT_H */
45 changes: 25 additions & 20 deletions src/indexing.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,17 @@ create_default_index(const Hypertable *ht, List *indexelems)
.indexParams = indexelems,
};

DefineIndex(ht->main_table_relid,
&stmt,
InvalidOid, /* indexRelationId */
InvalidOid, /* parentIndexId */
InvalidOid, /* parentConstraintId */
false, /* is_alter_table */
false, /* check_rights */
false, /* check_not_in_use */
false, /* skip_build */
true); /* quiet */
DefineIndexCompat(ht->main_table_relid,
&stmt,
InvalidOid, /* indexRelationId */
InvalidOid, /* parentIndexId */
InvalidOid, /* parentConstraintId */
-1, /* total_parts */
false, /* is_alter_table */
false, /* check_rights */
false, /* check_not_in_use */
false, /* skip_build */
true); /* quiet */
}

static const Node *
Expand Down Expand Up @@ -293,6 +294,7 @@ ts_indexing_root_table_create_index(IndexStmt *stmt, const char *queryString,
Oid relid;
LOCKMODE lockmode;
ObjectAddress root_table_address;
int total_parts = -1;

if (stmt->concurrent)
PreventInTransactionBlock(true, "CREATE INDEX CONCURRENTLY");
Expand Down Expand Up @@ -346,6 +348,7 @@ ts_indexing_root_table_create_index(IndexStmt *stmt, const char *queryString,
errdetail("Table \"%s\" contains chunks of the wrong type.",
stmt->relation->relname)));
}
total_parts = list_length(inheritors) - 1;
list_free(inheritors);
}

Expand All @@ -355,16 +358,18 @@ ts_indexing_root_table_create_index(IndexStmt *stmt, const char *queryString,
/* ... and do it */
EventTriggerAlterTableStart((Node *) stmt);

root_table_address = DefineIndex(relid, /* OID of heap relation */
stmt,
InvalidOid, /* no predefined OID */
InvalidOid, /* parentIndexId */
InvalidOid, /* parentConstraintId */
false, /* is_alter_table */
true, /* check_rights */
false, /* check_not_in_use */
false, /* skip_build */
false); /* quiet */
(void) total_parts;
root_table_address = DefineIndexCompat(relid, /* OID of heap relation */
stmt,
InvalidOid, /* no predefined OID */
InvalidOid, /* parentIndexId */
InvalidOid, /* parentConstraintId */
total_parts, /* total_parts */
false, /* is_alter_table */
true, /* check_rights */
false, /* check_not_in_use */
false, /* skip_build */
false); /* quiet */

return root_table_address;
}
Expand Down
21 changes: 11 additions & 10 deletions tsl/src/compression/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,16 +475,17 @@ create_compressed_table_indexes(Oid compresstable_relid, CompressColInfo *compre
indexcols = lappend(indexcols, &sequence_num_elem);

stmt.indexParams = indexcols;
index_addr = DefineIndex(ht->main_table_relid,
&stmt,
InvalidOid, /* IndexRelationId */
InvalidOid, /* parentIndexId */
InvalidOid, /* parentConstraintId */
false, /* is_alter_table */
false, /* check_rights */
false, /* check_not_in_use */
false, /* skip_build */
false); /* quiet */
index_addr = DefineIndexCompat(ht->main_table_relid,
&stmt,
InvalidOid, /* IndexRelationId */
InvalidOid, /* parentIndexId */
InvalidOid, /* parentConstraintId */
-1, /* total_parts */
false, /* is_alter_table */
false, /* check_rights */
false, /* check_not_in_use */
false, /* skip_build */
false); /* quiet */
index_tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(index_addr.objectId));

if (!HeapTupleIsValid(index_tuple))
Expand Down
21 changes: 11 additions & 10 deletions tsl/src/continuous_aggs/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,17 @@ mattablecolumninfo_add_mattable_index(MatTableColumnInfo *matcolinfo, Hypertable
char *grpcolname = (char *) lfirst(le);
IndexElem grpelem = { .type = T_IndexElem, .name = grpcolname };
stmt.indexParams = list_make2(&grpelem, &timeelem);
indxaddr = DefineIndex(ht->main_table_relid,
&stmt,
InvalidOid, /* indexRelationId */
InvalidOid, /* parentIndexId */
InvalidOid, /* parentConstraintId */
false, /* is_alter_table */
false, /* check_rights */
false, /* check_not_in_use */
false, /* skip_build */
false); /* quiet */
indxaddr = DefineIndexCompat(ht->main_table_relid,
&stmt,
InvalidOid, /* indexRelationId */
InvalidOid, /* parentIndexId */
InvalidOid, /* parentConstraintId */
-1, /* total_parts */
false, /* is_alter_table */
false, /* check_rights */
false, /* check_not_in_use */
false, /* skip_build */
false); /* quiet */
indxtuple = SearchSysCache1(RELOID, ObjectIdGetDatum(indxaddr.objectId));

if (!HeapTupleIsValid(indxtuple))
Expand Down

0 comments on commit 2eb0a38

Please sign in to comment.