public inbox for [email protected]
help / color / mirror / Atom feed[PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
22+ 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; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* [PATCH v22 2/5] Deprecate ReindexStmt->concurrent..
@ 2020-08-11 06:41 Justin Pryzby <[email protected]>
0 siblings, 0 replies; 22+ 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] 22+ messages in thread
* Re: Changed behavior in rewriteheap
@ 2024-11-21 23:30 Matthias van de Meent <[email protected]>
2024-11-22 08:11 ` Re: Changed behavior in rewriteheap Erik Nordström <[email protected]>
0 siblings, 1 reply; 22+ messages in thread
From: Matthias van de Meent @ 2024-11-21 23:30 UTC (permalink / raw)
To: Erik Nordström <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Heikki Linnakangas <[email protected]>
On Thu, 21 Nov 2024, 17:18 Erik Nordström, <[email protected]> wrote:
> Hello,
>
> I've noticed a change in behavior of the heap rewrite functionality in
> PostgreSQL 17, used by, e.g., CLUSTER. I've been experimenting with the
> functionality to implement a way to merge partitions in TimescaleDB. I am
> using table_relation_copy_for_cluster() to write the data of several tables
> to a single merged table, and then I do a heap swap on one of the original
> tables while dropping the others. So, if you have 3 partitions and want to
> merge them to one, then I write all three partitions to a temporary heap,
> swap the new heap on partition 1 and then drop partitions 2 and 3.
>
> Now, this approach worked fine for PostgreSQL 15 and 16, but 17 introduced
> some changes that altered the behavior so that I only see data from one of
> the partitions after merge (the last one written).
>
> The commit that I think is responsible is the following:
> https://github.com/postgres/postgres/commit/8af256524893987a3e534c6578dd60edfb782a77
>
> Now, I realize that this is not a problem for PostgreSQL itself since the
> rewrite functionality isn't used for the purpose I am using it. To my
> defense, the rewrite code seems to imply that it should be possible to
> write more data to an existing heap according to this comment in
> begin_heap_rewrite: /* new_heap needn't be empty, just locked */.
>
> I've also tried recompiling PG17 with the rewriteheap.c file from PG16 and
> then it works again. I haven't yet been able to figure out exactly what is
> different but I will continue to try to narrow it down. In the meantime,
> maybe someone on the mailing list has some insight on what could be the
> issue and whether my approach is viable?
>
I think the origin of the issue is at bulk_write.c, in smgr_bulk_flush
(specifically after line 282), which assumes the bulk write system is used
exclusively on empty relations.
If you use a separate pair of begin/end_heap_rewrite for every relation you
merge into that heap, it'll re-initialize the bulk writer, which will thus
overwrite the previous rewrites' pages. The pre-PG17 rewriteheap.c doesn't
use that API, and thus isn't affected.
I've CC-ed Heikki as author of that patch; maybe a new API to indicate bulk
writes into an existing fork would make sense, to solve Timescale's issue
and fix rewriteheap's behavior?
Kind regards,
Matthias van de Meent
Neon (https://neon.tech)
^ permalink raw reply [nested|flat] 22+ messages in thread
* Re: Changed behavior in rewriteheap
2024-11-21 23:30 Re: Changed behavior in rewriteheap Matthias van de Meent <[email protected]>
@ 2024-11-22 08:11 ` Erik Nordström <[email protected]>
0 siblings, 0 replies; 22+ messages in thread
From: Erik Nordström @ 2024-11-22 08:11 UTC (permalink / raw)
To: Matthias van de Meent <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>; Heikki Linnakangas <[email protected]>
On Fri, Nov 22, 2024 at 12:30 AM Matthias van de Meent <
[email protected]> wrote:
> On Thu, 21 Nov 2024, 17:18 Erik Nordström, <[email protected]> wrote:
>
>> Hello,
>>
>> I've noticed a change in behavior of the heap rewrite functionality in
>> PostgreSQL 17, used by, e.g., CLUSTER. I've been experimenting with the
>> functionality to implement a way to merge partitions in TimescaleDB. I am
>> using table_relation_copy_for_cluster() to write the data of several tables
>> to a single merged table, and then I do a heap swap on one of the original
>> tables while dropping the others. So, if you have 3 partitions and want to
>> merge them to one, then I write all three partitions to a temporary heap,
>> swap the new heap on partition 1 and then drop partitions 2 and 3.
>>
>> Now, this approach worked fine for PostgreSQL 15 and 16, but 17
>> introduced some changes that altered the behavior so that I only see data
>> from one of the partitions after merge (the last one written).
>>
>> The commit that I think is responsible is the following:
>> https://github.com/postgres/postgres/commit/8af256524893987a3e534c6578dd60edfb782a77
>>
>> Now, I realize that this is not a problem for PostgreSQL itself since the
>> rewrite functionality isn't used for the purpose I am using it. To my
>> defense, the rewrite code seems to imply that it should be possible to
>> write more data to an existing heap according to this comment in
>> begin_heap_rewrite: /* new_heap needn't be empty, just locked */.
>>
>> I've also tried recompiling PG17 with the rewriteheap.c file from PG16
>> and then it works again. I haven't yet been able to figure out exactly what
>> is different but I will continue to try to narrow it down. In the meantime,
>> maybe someone on the mailing list has some insight on what could be the
>> issue and whether my approach is viable?
>>
>
> I think the origin of the issue is at bulk_write.c, in smgr_bulk_flush
> (specifically after line 282), which assumes the bulk write system is used
> exclusively on empty relations.
>
> If you use a separate pair of begin/end_heap_rewrite for every relation
> you merge into that heap, it'll re-initialize the bulk writer, which will
> thus overwrite the previous rewrites' pages. The pre-PG17 rewriteheap.c
> doesn't use that API, and thus isn't affected.
>
> I've CC-ed Heikki as author of that patch; maybe a new API to indicate
> bulk writes into an existing fork would make sense, to solve Timescale's
> issue and fix rewriteheap's behavior?
>
>
> Kind regards,
>
> Matthias van de Meent
> Neon (https://neon.tech)
>
Yes, looks like it is that code that zeros out the initial pages if the
write doesn't start at block 0. And it looks like I don't have access to
the bulk write state to set pages_written to trick it to believe those
pages have already been written. Maybe it is possible to add an option to
the bulkwriter to skip zero-initialization? The comment for that code seems
to indicate it isn't strictly necessary anyway.
Regards,
Erik
^ permalink raw reply [nested|flat] 22+ messages in thread
end of thread, other threads:[~2024-11-22 08:11 UTC | newest]
Thread overview: 22+ 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]>
2024-11-21 23:30 Re: Changed behavior in rewriteheap Matthias van de Meent <[email protected]>
2024-11-22 08:11 ` Re: Changed behavior in rewriteheap Erik Nordström <[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