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,24 +1348,24 @@ ColumnarProcessUtility(PlannedStmt *pstmt,
{ {
IndexStmt *indexStmt = (IndexStmt *) parsetree; IndexStmt *indexStmt = (IndexStmt *) parsetree;
/* Relation rel = relation_openrv(indexStmt->relation,
* We should reject CREATE INDEX CONCURRENTLY before DefineIndex() is GetCreateIndexRelationLockMode(indexStmt));
* called. Erroring in callbacks called from DefineIndex() will create if (rel->rd_tableam == GetColumnarTableAmRoutine())
* the index and mark it as INVALID, which will cause segfault during
* inserts.
*/
if (indexStmt->concurrent)
{ {
Relation rel = relation_openrv(indexStmt->relation, /*
ShareUpdateExclusiveLock); * We should reject CREATE INDEX CONCURRENTLY before DefineIndex() is
if (rel->rd_tableam == GetColumnarTableAmRoutine()) * 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), 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,

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);