修复PBE冗余绑定分区表失效消息注册

This commit is contained in:
wuyuechuan
2023-12-04 17:17:19 +08:00
parent 4caf252446
commit 10d71a23e4
3 changed files with 22 additions and 54 deletions

View File

@ -5497,6 +5497,8 @@ void reindex_index(Oid indexId, Oid indexPartId, bool skip_constraint_checks,
{
if (OidIsValid(indexPartId)) {
reindex_indexpart_internal(heapRelation, iRel, indexInfo, indexPartId, baseDesc);
/* Register invalidation of the relation's relcache entry. */
CacheInvalidateRelcacheByRelid(indexId);
} else if (RelationIsGlobalIndex(iRel)) {
ReindexGlobalIndexInternal(heapRelation, iRel, indexInfo, baseDesc);
} else {
@ -6113,6 +6115,9 @@ bool reindexPartition(Oid relid, Oid partOid, int flags, int reindexType)
PG_END_TRY();
ResetReindexPending();
/* Register invalidation of the relation's relcache entry. */
CacheInvalidateRelcache(rel);
/*
* Close rel, but continue to hold the lock.
*/
@ -6278,6 +6283,8 @@ static void reindexPartIndex(Oid indexId, Oid partOid, bool skip_constraint_chec
// step 2: reset indisusable state of index partition
ATExecSetIndexUsableState(PartitionRelationId, indexPartOid, true);
/* Register invalidation of the relation's relcache entry. */
CacheInvalidateRelcacheByRelid(indexId);
}
PG_CATCH();
{

View File

@ -8881,6 +8881,14 @@ static void sqlcmd_alter_exec_convert_charset(AlteredTableInfo* tab, Relation re
heap_close(attrelation, RowExclusiveLock);
}
static bool sqlcmd_partition_index_ddl_cmd(AlterTableType cmd)
{
/* AT_UnusableAllIndexOnSubPartition is not supported */
return ((cmd) == AT_UnusableIndexPartition || (cmd) == AT_UnusableAllIndexOnPartition ||
(cmd) == AT_UnusableIndex || (cmd) == AT_AddIndex || (cmd) == AT_ReAddIndex ||
(cmd) == AT_AddIndexConstraint);
}
static void ATCreateColumComments(Oid relOid, ColumnDef* columnDef)
{
List *columnOptions = columnDef->columnOptions;
@ -8905,11 +8913,18 @@ static void ATExecCmd(List** wqueue, AlteredTableInfo* tab, Relation rel, AlterT
elog(ES_LOGLEVEL, "[ATExecCmd] cmd subtype: %d", cmd->subtype);
if (PARTITION_DDL_CMD(cmd->subtype) && RELATION_IS_PARTITIONED(rel)) {
/* Register invalidation of the relation's relcache entry. */
CacheInvalidateRelcache(rel);
int partitionno = -GetCurrentPartitionNo(RelOidGetPartitionTupleid(rel->rd_id));
if (!PARTITIONNO_IS_VALID(partitionno)) {
RelationResetPartitionno(rel->rd_id, ShareUpdateExclusiveLock);
}
}
if (sqlcmd_partition_index_ddl_cmd(cmd->subtype) && RelationIsIndex(rel)) {
Oid rel_id = IndexGetRelation(rel->rd_id, false);
CacheInvalidateRelcacheByRelid(rel_id);
}
switch (cmd->subtype) {
case AT_AddColumn: /* ADD COLUMN */

View File

@ -2375,27 +2375,6 @@ void extract_query_dependencies(
*hasHdfs = glob.vectorized;
}
static List *get_partition_indexoid_list(List *partitionOidList)
{
if (partitionOidList == NULL) {
return NULL;
}
ListCell *cell = NULL;
List *indexOidList = NIL;
foreach (cell, partitionOidList) {
Oid partOid = (Oid)lfirst_oid(cell);
List *partIndexlist = searchPartitionIndexesByblid(partOid);
ListCell *indexCell = NULL;
foreach (indexCell, partIndexlist) {
HeapTuple partIndexTuple = (HeapTuple)lfirst(indexCell);
Oid indexOid = HeapTupleGetOid(partIndexTuple);
indexOidList = lappend_oid(indexOidList, indexOid);
}
freePartList(partIndexlist);
}
return indexOidList;
}
/*
* Tree walker for extract_query_dependencies.
*
@ -2439,39 +2418,6 @@ static bool extract_query_dependencies_walker(Node* node, PlannerInfo* context)
/* use glob.vectorized here to mark if we contain hdfs table */
if (REL_PAX_ORIENTED == rte->orientation)
context->glob->vectorized = true;
/* To partition table, need append all partition Oids to relationOids.
* When partition tables are altered, partitionId will be append to transInvalInfo in
* function RegisterPartcacheInvalidation.
* On transaction start, if this table has been altered. Plansource->is_valid will be set
* to false.
*/
if (rte->ispartrel) {
List *partitionOid = getPartitionObjectIdList(rte->relid, PART_OBJ_TYPE_TABLE_PARTITION);
Relation partTableRel = relation_open(rte->relid, AccessShareLock);
if (RelationIsSubPartitioned(partTableRel)) {
ListCell *cell = NULL;
foreach (cell, partitionOid) {
Oid partOid = (Oid)lfirst_oid(cell);
List *subPartitionOidList =
getPartitionObjectIdList(partOid, PART_OBJ_TYPE_TABLE_SUB_PARTITION);
List *subPartIndexOidList = get_partition_indexoid_list(subPartitionOidList);
// add subpartition index oid
context->glob->relationOids = list_concat(context->glob->relationOids, subPartIndexOidList);
// add subpartition oid
context->glob->relationOids = list_concat(context->glob->relationOids, subPartitionOidList);
}
// add partition oid
context->glob->relationOids = list_concat(context->glob->relationOids, partitionOid);
} else {
List *partIndexOidList = get_partition_indexoid_list(partitionOid);
// add partition index oid
context->glob->relationOids = list_concat(context->glob->relationOids, partIndexOidList);
// add partition oid
context->glob->relationOids = list_concat(context->glob->relationOids, partitionOid);
}
relation_close(partTableRel, AccessShareLock);
}
}
}