From 94f30a04284d7170c21071809a3ad717dc910d89 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Tue, 1 Jun 2021 02:19:55 +0300 Subject: [PATCH] Refactor index check in ColumnarProcessUtility --- src/backend/columnar/columnar_tableam.c | 24 ++++++++++++------------ src/backend/distributed/commands/index.c | 3 +-- src/include/distributed/commands.h | 1 + 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/backend/columnar/columnar_tableam.c b/src/backend/columnar/columnar_tableam.c index 9977a66a8..e6cf2c0e3 100644 --- a/src/backend/columnar/columnar_tableam.c +++ b/src/backend/columnar/columnar_tableam.c @@ -1348,24 +1348,24 @@ ColumnarProcessUtility(PlannedStmt *pstmt, { IndexStmt *indexStmt = (IndexStmt *) parsetree; - /* - * We should reject CREATE INDEX CONCURRENTLY before DefineIndex() is - * called. Erroring in callbacks called from DefineIndex() will create - * the index and mark it as INVALID, which will cause segfault during - * inserts. - */ - if (indexStmt->concurrent) + Relation rel = relation_openrv(indexStmt->relation, + GetCreateIndexRelationLockMode(indexStmt)); + if (rel->rd_tableam == GetColumnarTableAmRoutine()) { - Relation rel = relation_openrv(indexStmt->relation, - ShareUpdateExclusiveLock); - if (rel->rd_tableam == GetColumnarTableAmRoutine()) + /* + * We should reject CREATE INDEX CONCURRENTLY before DefineIndex() is + * called. Erroring in callbacks called from DefineIndex() will create + * the index and mark it as INVALID, which will cause segfault during + * inserts. + */ + if (indexStmt->concurrent) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("indexes not supported for columnar tables"))); } - - RelationClose(rel); } + + RelationClose(rel); } PrevProcessUtilityHook(pstmt, queryString, context, diff --git a/src/backend/distributed/commands/index.c b/src/backend/distributed/commands/index.c index 1f66e512b..ee553de1e 100644 --- a/src/backend/distributed/commands/index.c +++ b/src/backend/distributed/commands/index.c @@ -62,7 +62,6 @@ static List * GenerateIndexParameters(IndexStmt *createIndexStatement); static DDLJob * GenerateCreateIndexDDLJob(IndexStmt *createIndexStatement, const char *createIndexCommand); static Oid CreateIndexStmtGetRelationId(IndexStmt *createIndexStatement); -static LOCKMODE GetCreateIndexRelationLockMode(IndexStmt *createIndexStatement); static List * CreateIndexTaskList(IndexStmt *indexStmt); static List * CreateReindexTaskList(Oid relationId, ReindexStmt *reindexStmt); static void RangeVarCallbackForDropIndex(const RangeVar *rel, Oid relOid, Oid oldRelOid, @@ -502,7 +501,7 @@ CreateIndexStmtGetRelationId(IndexStmt *createIndexStatement) * GetCreateIndexRelationLockMode returns required lock mode to open the * relation that given CREATE INDEX command operates on. */ -static LOCKMODE +LOCKMODE GetCreateIndexRelationLockMode(IndexStmt *createIndexStatement) { if (createIndexStatement->concurrent) diff --git a/src/include/distributed/commands.h b/src/include/distributed/commands.h index 4810e5915..a5070f2ad 100644 --- a/src/include/distributed/commands.h +++ b/src/include/distributed/commands.h @@ -266,6 +266,7 @@ extern char * ChooseIndexName(const char *tabname, Oid namespaceId, bool primary, bool isconstraint); extern char * ChooseIndexNameAddition(List *colnames); extern List * ChooseIndexColumnNames(List *indexElems); +extern LOCKMODE GetCreateIndexRelationLockMode(IndexStmt *createIndexStatement); extern List * PreprocessReindexStmt(Node *ReindexStatement, const char *ReindexCommand, ProcessUtilityContext processUtilityContext);