Skip to content

Commit 844c05a

Browse files
committed
Remove variable "concurrent" from ReindexStmt
This node already handles multiple options using a bitmask, so having a separate boolean flag is not necessary. This simplifies the code a bit with less arguments to give to the reindex routines, by replacing the boolean with an equivalent bitmask value. Reviewed-by: Julien Rouhaud Discussion: https://postgr.es/m/20200902110326.GA14963@paquier.xyz
1 parent 67a472d commit 844c05a

File tree

7 files changed

+36
-27
lines changed

7 files changed

+36
-27
lines changed

src/backend/commands/indexcmds.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts);
9797
*/
9898
struct ReindexIndexCallbackState
9999
{
100-
bool concurrent; /* flag from statement */
100+
int options; /* options from statement */
101101
Oid locked_table_oid; /* tracks previously locked table */
102102
};
103103

@@ -2420,7 +2420,7 @@ ChooseIndexColumnNames(List *indexElems)
24202420
* Recreate a specific index.
24212421
*/
24222422
void
2423-
ReindexIndex(RangeVar *indexRelation, int options, bool concurrent)
2423+
ReindexIndex(RangeVar *indexRelation, int options)
24242424
{
24252425
struct ReindexIndexCallbackState state;
24262426
Oid indOid;
@@ -2437,10 +2437,11 @@ ReindexIndex(RangeVar *indexRelation, int options, bool concurrent)
24372437
* upgrade the lock, but that's OK, because other sessions can't hold
24382438
* locks on our temporary table.
24392439
*/
2440-
state.concurrent = concurrent;
2440+
state.options = options;
24412441
state.locked_table_oid = InvalidOid;
24422442
indOid = RangeVarGetRelidExtended(indexRelation,
2443-
concurrent ? ShareUpdateExclusiveLock : AccessExclusiveLock,
2443+
(options & REINDEXOPT_CONCURRENTLY) != 0 ?
2444+
ShareUpdateExclusiveLock : AccessExclusiveLock,
24442445
0,
24452446
RangeVarCallbackForReindexIndex,
24462447
&state);
@@ -2460,7 +2461,8 @@ ReindexIndex(RangeVar *indexRelation, int options, bool concurrent)
24602461
persistence = irel->rd_rel->relpersistence;
24612462
index_close(irel, NoLock);
24622463

2463-
if (concurrent && persistence != RELPERSISTENCE_TEMP)
2464+
if ((options & REINDEXOPT_CONCURRENTLY) != 0 &&
2465+
persistence != RELPERSISTENCE_TEMP)
24642466
ReindexRelationConcurrently(indOid, options);
24652467
else
24662468
reindex_index(indOid, false, persistence,
@@ -2485,7 +2487,8 @@ RangeVarCallbackForReindexIndex(const RangeVar *relation,
24852487
* non-concurrent case and table locks used by index_concurrently_*() for
24862488
* concurrent case.
24872489
*/
2488-
table_lockmode = state->concurrent ? ShareUpdateExclusiveLock : ShareLock;
2490+
table_lockmode = ((state->options & REINDEXOPT_CONCURRENTLY) != 0) ?
2491+
ShareUpdateExclusiveLock : ShareLock;
24892492

24902493
/*
24912494
* If we previously locked some other index's heap, and the name we're
@@ -2542,7 +2545,7 @@ RangeVarCallbackForReindexIndex(const RangeVar *relation,
25422545
* Recreate all indexes of a table (and of its toast table, if any)
25432546
*/
25442547
Oid
2545-
ReindexTable(RangeVar *relation, int options, bool concurrent)
2548+
ReindexTable(RangeVar *relation, int options)
25462549
{
25472550
Oid heapOid;
25482551
bool result;
@@ -2556,11 +2559,13 @@ ReindexTable(RangeVar *relation, int options, bool concurrent)
25562559
* locks on our temporary table.
25572560
*/
25582561
heapOid = RangeVarGetRelidExtended(relation,
2559-
concurrent ? ShareUpdateExclusiveLock : ShareLock,
2562+
(options & REINDEXOPT_CONCURRENTLY) != 0 ?
2563+
ShareUpdateExclusiveLock : ShareLock,
25602564
0,
25612565
RangeVarCallbackOwnsTable, NULL);
25622566

2563-
if (concurrent && get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP)
2567+
if ((options & REINDEXOPT_CONCURRENTLY) != 0 &&
2568+
get_rel_persistence(heapOid) != RELPERSISTENCE_TEMP)
25642569
{
25652570
result = ReindexRelationConcurrently(heapOid, options);
25662571

@@ -2594,7 +2599,7 @@ ReindexTable(RangeVar *relation, int options, bool concurrent)
25942599
*/
25952600
void
25962601
ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
2597-
int options, bool concurrent)
2602+
int options)
25982603
{
25992604
Oid objectOid;
26002605
Relation relationRelation;
@@ -2613,7 +2618,8 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
26132618
objectKind == REINDEX_OBJECT_SYSTEM ||
26142619
objectKind == REINDEX_OBJECT_DATABASE);
26152620

2616-
if (objectKind == REINDEX_OBJECT_SYSTEM && concurrent)
2621+
if (objectKind == REINDEX_OBJECT_SYSTEM &&
2622+
(options & REINDEXOPT_CONCURRENTLY) != 0)
26172623
ereport(ERROR,
26182624
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
26192625
errmsg("cannot reindex system catalogs concurrently")));
@@ -2724,7 +2730,7 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
27242730
* Skip system tables, since index_create() would reject indexing them
27252731
* concurrently (and it would likely fail if we tried).
27262732
*/
2727-
if (concurrent &&
2733+
if ((options & REINDEXOPT_CONCURRENTLY) != 0 &&
27282734
IsCatalogRelationOid(relid))
27292735
{
27302736
if (!concurrent_warning)
@@ -2774,7 +2780,8 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
27742780
continue;
27752781
}
27762782

2777-
if (concurrent && get_rel_persistence(relid) != RELPERSISTENCE_TEMP)
2783+
if ((options & REINDEXOPT_CONCURRENTLY) != 0 &&
2784+
get_rel_persistence(relid) != RELPERSISTENCE_TEMP)
27782785
{
27792786
(void) ReindexRelationConcurrently(relid,
27802787
options |

src/backend/nodes/copyfuncs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4450,7 +4450,6 @@ _copyReindexStmt(const ReindexStmt *from)
44504450
COPY_NODE_FIELD(relation);
44514451
COPY_STRING_FIELD(name);
44524452
COPY_SCALAR_FIELD(options);
4453-
COPY_SCALAR_FIELD(concurrent);
44544453

44554454
return newnode;
44564455
}

src/backend/nodes/equalfuncs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,6 @@ _equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b)
21352135
COMPARE_NODE_FIELD(relation);
21362136
COMPARE_STRING_FIELD(name);
21372137
COMPARE_SCALAR_FIELD(options);
2138-
COMPARE_SCALAR_FIELD(concurrent);
21392138

21402139
return true;
21412140
}

src/backend/parser/gram.y

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8177,40 +8177,44 @@ ReindexStmt:
81778177
{
81788178
ReindexStmt *n = makeNode(ReindexStmt);
81798179
n->kind = $2;
8180-
n->concurrent = $3;
81818180
n->relation = $4;
81828181
n->name = NULL;
81838182
n->options = 0;
8183+
if ($3)
8184+
n->options |= REINDEXOPT_CONCURRENTLY;
81848185
$$ = (Node *)n;
81858186
}
81868187
| REINDEX reindex_target_multitable opt_concurrently name
81878188
{
81888189
ReindexStmt *n = makeNode(ReindexStmt);
81898190
n->kind = $2;
8190-
n->concurrent = $3;
81918191
n->name = $4;
81928192
n->relation = NULL;
81938193
n->options = 0;
8194+
if ($3)
8195+
n->options |= REINDEXOPT_CONCURRENTLY;
81948196
$$ = (Node *)n;
81958197
}
81968198
| REINDEX '(' reindex_option_list ')' reindex_target_type opt_concurrently qualified_name
81978199
{
81988200
ReindexStmt *n = makeNode(ReindexStmt);
81998201
n->kind = $5;
8200-
n->concurrent = $6;
82018202
n->relation = $7;
82028203
n->name = NULL;
82038204
n->options = $3;
8205+
if ($6)
8206+
n->options |= REINDEXOPT_CONCURRENTLY;
82048207
$$ = (Node *)n;
82058208
}
82068209
| REINDEX '(' reindex_option_list ')' reindex_target_multitable opt_concurrently name
82078210
{
82088211
ReindexStmt *n = makeNode(ReindexStmt);
82098212
n->kind = $5;
8210-
n->concurrent = $6;
82118213
n->name = $7;
82128214
n->relation = NULL;
82138215
n->options = $3;
8216+
if ($6)
8217+
n->options |= REINDEXOPT_CONCURRENTLY;
82148218
$$ = (Node *)n;
82158219
}
82168220
;

src/backend/tcop/utility.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,17 +919,17 @@ standard_ProcessUtility(PlannedStmt *pstmt,
919919
{
920920
ReindexStmt *stmt = (ReindexStmt *) parsetree;
921921

922-
if (stmt->concurrent)
922+
if ((stmt->options & REINDEXOPT_CONCURRENTLY) != 0)
923923
PreventInTransactionBlock(isTopLevel,
924924
"REINDEX CONCURRENTLY");
925925

926926
switch (stmt->kind)
927927
{
928928
case REINDEX_OBJECT_INDEX:
929-
ReindexIndex(stmt->relation, stmt->options, stmt->concurrent);
929+
ReindexIndex(stmt->relation, stmt->options);
930930
break;
931931
case REINDEX_OBJECT_TABLE:
932-
ReindexTable(stmt->relation, stmt->options, stmt->concurrent);
932+
ReindexTable(stmt->relation, stmt->options);
933933
break;
934934
case REINDEX_OBJECT_SCHEMA:
935935
case REINDEX_OBJECT_SYSTEM:
@@ -945,7 +945,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
945945
(stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
946946
(stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
947947
"REINDEX DATABASE");
948-
ReindexMultipleTables(stmt->name, stmt->kind, stmt->options, stmt->concurrent);
948+
ReindexMultipleTables(stmt->name, stmt->kind, stmt->options);
949949
break;
950950
default:
951951
elog(ERROR, "unrecognized object type: %d",

src/include/commands/defrem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ extern ObjectAddress DefineIndex(Oid relationId,
3434
bool check_not_in_use,
3535
bool skip_build,
3636
bool quiet);
37-
extern void ReindexIndex(RangeVar *indexRelation, int options, bool concurrent);
38-
extern Oid ReindexTable(RangeVar *relation, int options, bool concurrent);
37+
extern void ReindexIndex(RangeVar *indexRelation, int options);
38+
extern Oid ReindexTable(RangeVar *relation, int options);
3939
extern void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
40-
int options, bool concurrent);
40+
int options);
4141
extern char *makeObjectName(const char *name1, const char *name2,
4242
const char *label);
4343
extern char *ChooseRelationName(const char *name1, const char *name2,

src/include/nodes/parsenodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,7 @@ typedef struct ConstraintsSetStmt
33533353
#define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */
33543354
#define REINDEXOPT_REPORT_PROGRESS (1 << 1) /* report pgstat progress */
33553355
#define REINDEXOPT_MISSING_OK (1 << 2) /* skip missing relations */
3356+
#define REINDEXOPT_CONCURRENTLY (1 << 3) /* concurrent mode */
33563357

33573358
typedef enum ReindexObjectType
33583359
{
@@ -3371,7 +3372,6 @@ typedef struct ReindexStmt
33713372
RangeVar *relation; /* Table or index to reindex */
33723373
const char *name; /* name of database to reindex */
33733374
int options; /* Reindex options flags */
3374-
bool concurrent; /* reindex concurrently? */
33753375
} ReindexStmt;
33763376

33773377
/* ----------------------

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy