public inbox for [email protected]help / color / mirror / Atom feed
[PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. 23+ messages / 3 participants [nested] [flat]
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. @ 2020-08-11 06:41 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Justin Pryzby @ 2020-08-11 06:41 UTC (permalink / raw) ..since parenthesized syntax is the modern syntax, remove the special field for handling nonparenthesized option. --- src/backend/commands/indexcmds.c | 20 +++++++++++--------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/parser/gram.y | 16 ++++++++++++---- src/backend/tcop/utility.c | 6 +++--- src/include/nodes/parsenodes.h | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a22b32fc74..097d8720a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); */ struct ReindexIndexCallbackState { - bool concurrent; /* flag from statement */ + bool concurrent; /* flag from statement XXX */ Oid locked_table_oid; /* tracks previously locked table */ }; @@ -2438,10 +2438,10 @@ ReindexIndex(ReindexStmt *stmt) * upgrade the lock, but that's OK, because other sessions can't hold * locks on our temporary table. */ - state.concurrent = stmt->concurrent; + state.concurrent = (stmt->options & REINDEXOPT_CONCURRENT); state.locked_table_oid = InvalidOid; indOid = RangeVarGetRelidExtended(indexRelation, - stmt->concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, + state.concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock, 0, RangeVarCallbackForReindexIndex, &state); @@ -2461,7 +2461,7 @@ ReindexIndex(ReindexStmt *stmt) persistence = irel->rd_rel->relpersistence; index_close(irel, NoLock); - if (stmt->concurrent && persistence != RELPERSISTENCE_TEMP) + if (state.concurrent && persistence != RELPERSISTENCE_TEMP) ReindexRelationConcurrently(indOid, stmt->options); else reindex_index(indOid, false, persistence, @@ -2548,6 +2548,7 @@ ReindexTable(ReindexStmt *stmt) RangeVar *relation = stmt->relation; Oid heapOid; bool result; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); /* * The lock level used here should match reindex_relation(). @@ -2558,11 +2559,11 @@ ReindexTable(ReindexStmt *stmt) * locks on our temporary table. */ heapOid = RangeVarGetRelidExtended(relation, - stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock, + concurrent ? ShareUpdateExclusiveLock : ShareLock, 0, RangeVarCallbackOwnsTable, NULL); - if (stmt->concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP) { result = ReindexRelationConcurrently(heapOid, stmt->options); @@ -2610,13 +2611,14 @@ ReindexMultipleTables(ReindexStmt *stmt) ListCell *l; int num_keys; bool concurrent_warning = false; + bool concurrent = (stmt->options & REINDEXOPT_CONCURRENT); AssertArg(objectName); Assert(objectKind == REINDEX_OBJECT_SCHEMA || objectKind == REINDEX_OBJECT_SYSTEM || objectKind == REINDEX_OBJECT_DATABASE); - if (objectKind == REINDEX_OBJECT_SYSTEM && stmt->concurrent) + if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot reindex system catalogs concurrently"))); @@ -2727,7 +2729,7 @@ ReindexMultipleTables(ReindexStmt *stmt) * Skip system tables, since index_create() would reject indexing them * concurrently (and it would likely fail if we tried). */ - if (stmt->concurrent && + if (concurrent && IsCatalogRelationOid(relid)) { if (!concurrent_warning) @@ -2769,7 +2771,7 @@ ReindexMultipleTables(ReindexStmt *stmt) /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - if (stmt->concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) + if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP) { (void) ReindexRelationConcurrently(relid, stmt->options); /* ReindexRelationConcurrently() does the verbose output */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 71548acc0c..a67e637c37 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -4452,7 +4452,6 @@ _copyReindexStmt(const ReindexStmt *from) COPY_STRING_FIELD(name); COPY_SCALAR_FIELD(options); COPY_NODE_FIELD(params); - COPY_SCALAR_FIELD(concurrent); return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index de48a42cdd..efcb23c12e 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -2137,7 +2137,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b) COMPARE_STRING_FIELD(name); COMPARE_SCALAR_FIELD(options); COMPARE_NODE_FIELD(params); - COMPARE_SCALAR_FIELD(concurrent); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index b909b161a6..ac489c03c3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -8176,40 +8176,48 @@ ReindexStmt: { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->relation = $4; n->name = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $2; - n->concurrent = $3; n->name = $4; n->relation = NULL; n->params = NIL; + if ($3) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @3)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_type opt_concurrently qualified_name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->relation = $7; n->name = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } | REINDEX '(' vac_analyze_option_list ')' reindex_target_multitable opt_concurrently name { ReindexStmt *n = makeNode(ReindexStmt); n->kind = $5; - n->concurrent = $6; n->name = $7; n->relation = NULL; n->params = $3; + if ($6) + n->params = lappend(n->params, + makeDefElem("concurrently", (Node *)makeString("concurrently"), @6)); $$ = (Node *)n; } ; diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index c48983a5de..639b6fce74 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -543,7 +543,7 @@ void parse_reindex_params(ParseState *pstate, ReindexStmt *stmt) stmt->options &= ~REINDEXOPT_VERBOSE; } else if (strcmp(opt->defname, "concurrently") == 0) - stmt->concurrent = true; + stmt->options |= REINDEXOPT_CONCURRENT; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -946,11 +946,11 @@ standard_ProcessUtility(PlannedStmt *pstmt, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - if (stmt->concurrent) + parse_reindex_params(pstate, stmt); + if (stmt->options & REINDEXOPT_CONCURRENT) PreventInTransactionBlock(isTopLevel, "REINDEX CONCURRENTLY"); - parse_reindex_params(pstate, stmt); switch (stmt->kind) { case REINDEX_OBJECT_INDEX: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 295c2802a4..ba685139ef 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3352,6 +3352,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ #define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */ +#define REINDEXOPT_CONCURRENT (1 << 2) /* reindex CONCURRENTLY */ typedef enum ReindexObjectType { @@ -3371,7 +3372,6 @@ typedef struct ReindexStmt const char *name; /* name of database to reindex */ int options; /* Reindex options flags */ List *params; /* Params not further parsed by the grammer */ - bool concurrent; /* reindex concurrently? */ } ReindexStmt; /* ---------------------- -- 2.17.0 --g7w8+K/95kPelPD2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v22-0003-Allow-REINDEX-to-change-tablespace.patch" ^ permalink raw reply [nested|flat] 23+ messages in thread
* Improving the heapgetpage function improves performance in common scenarios @ 2023-08-24 10:55 Quan Zongliang <[email protected]> 0 siblings, 1 reply; 23+ messages in thread From: Quan Zongliang @ 2023-08-24 10:55 UTC (permalink / raw) To: pgsql-hackers Hi In the function heapgetpage. If a table is not updated very frequently. Many actions in tuple loops are superfluous. For all_visible pages, loctup does not need to be assigned, nor does the "valid" variable. CheckForSerializableConflictOutNeeded from HeapCheckForSerializableConflictOut function, it only need to inspect at the beginning of the cycle only once. Using vtune you can clearly see the result (attached heapgetpage.jpg). So by splitting the loop logic into two parts, the vtune results show significant improvement (attached heapgetpage-allvis.jpg). The test data uses TPC-H's table "orders" with a scale=20, 30 million rows. Quan Zongliang diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 7ed72abe59..21ac1da8ab 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -451,30 +451,43 @@ heapgetpage(TableScanDesc sscan, BlockNumber block) */ all_visible = PageIsAllVisible(page) && !snapshot->takenDuringRecovery; - for (lineoff = FirstOffsetNumber; lineoff <= lines; lineoff++) + if (all_visible && !CheckForSerializableConflictOutNeeded(scan->rs_base.rs_rd, snapshot)) { - ItemId lpp = PageGetItemId(page, lineoff); - HeapTupleData loctup; - bool valid; + for (lineoff = FirstOffsetNumber; lineoff <= lines; lineoff++) + { + if (!ItemIdIsNormal(PageGetItemId(page, lineoff))) + continue; - if (!ItemIdIsNormal(lpp)) - continue; + scan->rs_vistuples[ntup++] = lineoff; + } + } + else + { + for (lineoff = FirstOffsetNumber; lineoff <= lines; lineoff++) + { + ItemId lpp = PageGetItemId(page, lineoff); + HeapTupleData loctup; + bool valid; - loctup.t_tableOid = RelationGetRelid(scan->rs_base.rs_rd); - loctup.t_data = (HeapTupleHeader) PageGetItem(page, lpp); - loctup.t_len = ItemIdGetLength(lpp); - ItemPointerSet(&(loctup.t_self), block, lineoff); + if (!ItemIdIsNormal(lpp)) + continue; - if (all_visible) - valid = true; - else - valid = HeapTupleSatisfiesVisibility(&loctup, snapshot, buffer); + loctup.t_tableOid = RelationGetRelid(scan->rs_base.rs_rd); + loctup.t_data = (HeapTupleHeader) PageGetItem(page, lpp); + loctup.t_len = ItemIdGetLength(lpp); + ItemPointerSet(&(loctup.t_self), block, lineoff); + + if (all_visible) + valid = true; + else + valid = HeapTupleSatisfiesVisibility(&loctup, snapshot, buffer); - HeapCheckForSerializableConflictOut(valid, scan->rs_base.rs_rd, - &loctup, buffer, snapshot); + HeapCheckForSerializableConflictOut(valid, scan->rs_base.rs_rd, + &loctup, buffer, snapshot); - if (valid) - scan->rs_vistuples[ntup++] = lineoff; + if (valid) + scan->rs_vistuples[ntup++] = lineoff; + } } LockBuffer(buffer, BUFFER_LOCK_UNLOCK); Attachments: [image/jpeg] heapgetpage-allvis.jpg (43.0K, ../../[email protected]/2-heapgetpage-allvis.jpg) download | view image [image/jpeg] heapgetpage.jpg (99.9K, ../../[email protected]/3-heapgetpage.jpg) download | view image [text/plain] heapgetpage.patch (2.1K, ../../[email protected]/4-heapgetpage.patch) download | inline diff: diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 7ed72abe59..21ac1da8ab 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -451,30 +451,43 @@ heapgetpage(TableScanDesc sscan, BlockNumber block) */ all_visible = PageIsAllVisible(page) && !snapshot->takenDuringRecovery; - for (lineoff = FirstOffsetNumber; lineoff <= lines; lineoff++) + if (all_visible && !CheckForSerializableConflictOutNeeded(scan->rs_base.rs_rd, snapshot)) { - ItemId lpp = PageGetItemId(page, lineoff); - HeapTupleData loctup; - bool valid; + for (lineoff = FirstOffsetNumber; lineoff <= lines; lineoff++) + { + if (!ItemIdIsNormal(PageGetItemId(page, lineoff))) + continue; - if (!ItemIdIsNormal(lpp)) - continue; + scan->rs_vistuples[ntup++] = lineoff; + } + } + else + { + for (lineoff = FirstOffsetNumber; lineoff <= lines; lineoff++) + { + ItemId lpp = PageGetItemId(page, lineoff); + HeapTupleData loctup; + bool valid; - loctup.t_tableOid = RelationGetRelid(scan->rs_base.rs_rd); - loctup.t_data = (HeapTupleHeader) PageGetItem(page, lpp); - loctup.t_len = ItemIdGetLength(lpp); - ItemPointerSet(&(loctup.t_self), block, lineoff); + if (!ItemIdIsNormal(lpp)) + continue; - if (all_visible) - valid = true; - else - valid = HeapTupleSatisfiesVisibility(&loctup, snapshot, buffer); + loctup.t_tableOid = RelationGetRelid(scan->rs_base.rs_rd); + loctup.t_data = (HeapTupleHeader) PageGetItem(page, lpp); + loctup.t_len = ItemIdGetLength(lpp); + ItemPointerSet(&(loctup.t_self), block, lineoff); + + if (all_visible) + valid = true; + else + valid = HeapTupleSatisfiesVisibility(&loctup, snapshot, buffer); - HeapCheckForSerializableConflictOut(valid, scan->rs_base.rs_rd, - &loctup, buffer, snapshot); + HeapCheckForSerializableConflictOut(valid, scan->rs_base.rs_rd, + &loctup, buffer, snapshot); - if (valid) - scan->rs_vistuples[ntup++] = lineoff; + if (valid) + scan->rs_vistuples[ntup++] = lineoff; + } } LockBuffer(buffer, BUFFER_LOCK_UNLOCK); ^ permalink raw reply [nested|flat] 23+ messages in thread
* Re: Improving the heapgetpage function improves performance in common scenarios @ 2023-09-05 08:15 John Naylor <[email protected]> parent: Quan Zongliang <[email protected]> 0 siblings, 1 reply; 23+ messages in thread From: John Naylor @ 2023-09-05 08:15 UTC (permalink / raw) To: Quan Zongliang <[email protected]>; +Cc: pgsql-hackers On Thu, Aug 24, 2023 at 5:55 PM Quan Zongliang <[email protected]> wrote: > In the function heapgetpage. If a table is not updated very frequently. > Many actions in tuple loops are superfluous. For all_visible pages, > loctup does not need to be assigned, nor does the "valid" variable. > CheckForSerializableConflictOutNeeded from > HeapCheckForSerializableConflictOut function, it only need to inspect at Thanks for submitting! A few weeks before this, there was another proposal, which specializes code for all paths, not just one. That patch also does so without duplicating the loop: https://www.postgresql.org/message-id/[email protected] > the beginning of the cycle only once. Using vtune you can clearly see > the result (attached heapgetpage.jpg). > > So by splitting the loop logic into two parts, the vtune results show > significant improvement (attached heapgetpage-allvis.jpg). For future reference, it's not clear at all from the screenshots what the improvement will be for the user. In the above thread, the author shares testing methodology as well as timing measurements. This is useful for reproducibilty, as well as convincing others that the change is important. -- John Naylor EDB: http://www.enterprisedb.com ^ permalink raw reply [nested|flat] 23+ messages in thread
* Re: Improving the heapgetpage function improves performance in common scenarios @ 2023-09-05 09:27 Quan Zongliang <[email protected]> parent: John Naylor <[email protected]> 0 siblings, 0 replies; 23+ messages in thread From: Quan Zongliang @ 2023-09-05 09:27 UTC (permalink / raw) To: John Naylor <[email protected]>; +Cc: pgsql-hackers On 2023/9/5 16:15, John Naylor wrote: > > On Thu, Aug 24, 2023 at 5:55 PM Quan Zongliang <[email protected] > <mailto:[email protected]>> wrote: > > > In the function heapgetpage. If a table is not updated very frequently. > > Many actions in tuple loops are superfluous. For all_visible pages, > > loctup does not need to be assigned, nor does the "valid" variable. > > CheckForSerializableConflictOutNeeded from > > HeapCheckForSerializableConflictOut function, it only need to inspect at > > Thanks for submitting! A few weeks before this, there was another > proposal, which specializes code for all paths, not just one. That patch > also does so without duplicating the loop: > > https://www.postgresql.org/message-id/[email protected] <https://www.postgresql.org/message-id/[email protected]; > Nice patch. I'm sorry I didn't notice it before. > > the beginning of the cycle only once. Using vtune you can clearly see > > the result (attached heapgetpage.jpg). > > > > So by splitting the loop logic into two parts, the vtune results show > > significant improvement (attached heapgetpage-allvis.jpg). > > For future reference, it's not clear at all from the screenshots what > the improvement will be for the user. In the above thread, the author > shares testing methodology as well as timing measurements. This is > useful for reproducibilty, as well as convincing others that the change > is important. > Here's how I test it EXPLAIN ANALYZE SELECT * FROM orders; Maybe the test wasn't good enough. Although the modified optimal result looks good. Because it fluctuates a lot. It's hard to compare. The results of vtune are therefore used. My patch is mainly to eliminate: 1, Assignment of "loctup" struct variable (in vtune you can see that these 4 lines have a significant overhead: 0.4 1.0 0.2 0.4). 2. Assignment of the "valid" variable.(overhead 0.6) 3. HeapCheckForSerializableConflictOut function call.(overhead 0.6) Although these are not the same overhead from test to test. But all are too obvious to ignore. The screenshots are mainly to show the three improvements mentioned above. I'll also try Andres Freund's test method next. > -- > John Naylor > EDB: http://www.enterprisedb.com <http://www.enterprisedb.com; ^ permalink raw reply [nested|flat] 23+ messages in thread
end of thread, other threads:[~2023-09-05 09:27 UTC | newest] Thread overview: 23+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2020-08-11 06:41 [PATCH v22 2/5] Deprecate ReindexStmt->concurrent.. Justin Pryzby <[email protected]> 2023-08-24 10:55 Improving the heapgetpage function improves performance in common scenarios Quan Zongliang <[email protected]> 2023-09-05 08:15 ` Re: Improving the heapgetpage function improves performance in common scenarios John Naylor <[email protected]> 2023-09-05 09:27 ` Re: Improving the heapgetpage function improves performance in common scenarios Quan Zongliang <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox