From 10d71a23e40758cedc80f9348e8482ac0ddc71f3 Mon Sep 17 00:00:00 2001 From: wuyuechuan Date: Mon, 4 Dec 2023 17:17:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPBE=E5=86=97=E4=BD=99?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=88=86=E5=8C=BA=E8=A1=A8=E5=A4=B1=E6=95=88?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/catalog/index.cpp | 7 +++ .../optimizer/commands/tablecmds.cpp | 15 ++++++ src/gausskernel/optimizer/plan/setrefs.cpp | 54 ------------------- 3 files changed, 22 insertions(+), 54 deletions(-) diff --git a/src/common/backend/catalog/index.cpp b/src/common/backend/catalog/index.cpp index a0c236857..73818ce8b 100644 --- a/src/common/backend/catalog/index.cpp +++ b/src/common/backend/catalog/index.cpp @@ -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(); { diff --git a/src/gausskernel/optimizer/commands/tablecmds.cpp b/src/gausskernel/optimizer/commands/tablecmds.cpp index ba25732d1..a0a2e5348 100755 --- a/src/gausskernel/optimizer/commands/tablecmds.cpp +++ b/src/gausskernel/optimizer/commands/tablecmds.cpp @@ -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 */ diff --git a/src/gausskernel/optimizer/plan/setrefs.cpp b/src/gausskernel/optimizer/plan/setrefs.cpp index 67653c84e..a88b0333a 100644 --- a/src/gausskernel/optimizer/plan/setrefs.cpp +++ b/src/gausskernel/optimizer/plan/setrefs.cpp @@ -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); - } } }