Refactor index check in ColumnarProcessUtility

pull/4950/head
Onur Tirtir 2021-06-01 02:19:55 +03:00
parent 4f3c672ebe
commit 94f30a0428
3 changed files with 14 additions and 14 deletions

View File

@ -1348,6 +1348,10 @@ ColumnarProcessUtility(PlannedStmt *pstmt,
{ {
IndexStmt *indexStmt = (IndexStmt *) parsetree; IndexStmt *indexStmt = (IndexStmt *) parsetree;
Relation rel = relation_openrv(indexStmt->relation,
GetCreateIndexRelationLockMode(indexStmt));
if (rel->rd_tableam == GetColumnarTableAmRoutine())
{
/* /*
* We should reject CREATE INDEX CONCURRENTLY before DefineIndex() is * We should reject CREATE INDEX CONCURRENTLY before DefineIndex() is
* called. Erroring in callbacks called from DefineIndex() will create * called. Erroring in callbacks called from DefineIndex() will create
@ -1355,18 +1359,14 @@ ColumnarProcessUtility(PlannedStmt *pstmt,
* inserts. * inserts.
*/ */
if (indexStmt->concurrent) if (indexStmt->concurrent)
{
Relation rel = relation_openrv(indexStmt->relation,
ShareUpdateExclusiveLock);
if (rel->rd_tableam == GetColumnarTableAmRoutine())
{ {
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("indexes not supported for columnar tables"))); errmsg("indexes not supported for columnar tables")));
} }
}
RelationClose(rel); RelationClose(rel);
} }
}
PrevProcessUtilityHook(pstmt, queryString, context, PrevProcessUtilityHook(pstmt, queryString, context,
params, queryEnv, dest, completionTag); params, queryEnv, dest, completionTag);

View File

@ -62,7 +62,6 @@ static List * GenerateIndexParameters(IndexStmt *createIndexStatement);
static DDLJob * GenerateCreateIndexDDLJob(IndexStmt *createIndexStatement, static DDLJob * GenerateCreateIndexDDLJob(IndexStmt *createIndexStatement,
const char *createIndexCommand); const char *createIndexCommand);
static Oid CreateIndexStmtGetRelationId(IndexStmt *createIndexStatement); static Oid CreateIndexStmtGetRelationId(IndexStmt *createIndexStatement);
static LOCKMODE GetCreateIndexRelationLockMode(IndexStmt *createIndexStatement);
static List * CreateIndexTaskList(IndexStmt *indexStmt); static List * CreateIndexTaskList(IndexStmt *indexStmt);
static List * CreateReindexTaskList(Oid relationId, ReindexStmt *reindexStmt); static List * CreateReindexTaskList(Oid relationId, ReindexStmt *reindexStmt);
static void RangeVarCallbackForDropIndex(const RangeVar *rel, Oid relOid, Oid oldRelOid, 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 * GetCreateIndexRelationLockMode returns required lock mode to open the
* relation that given CREATE INDEX command operates on. * relation that given CREATE INDEX command operates on.
*/ */
static LOCKMODE LOCKMODE
GetCreateIndexRelationLockMode(IndexStmt *createIndexStatement) GetCreateIndexRelationLockMode(IndexStmt *createIndexStatement)
{ {
if (createIndexStatement->concurrent) if (createIndexStatement->concurrent)

View File

@ -266,6 +266,7 @@ extern char * ChooseIndexName(const char *tabname, Oid namespaceId,
bool primary, bool isconstraint); bool primary, bool isconstraint);
extern char * ChooseIndexNameAddition(List *colnames); extern char * ChooseIndexNameAddition(List *colnames);
extern List * ChooseIndexColumnNames(List *indexElems); extern List * ChooseIndexColumnNames(List *indexElems);
extern LOCKMODE GetCreateIndexRelationLockMode(IndexStmt *createIndexStatement);
extern List * PreprocessReindexStmt(Node *ReindexStatement, extern List * PreprocessReindexStmt(Node *ReindexStatement,
const char *ReindexCommand, const char *ReindexCommand,
ProcessUtilityContext processUtilityContext); ProcessUtilityContext processUtilityContext);