Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit844c05a

Browse files
committed
Remove variable "concurrent" from ReindexStmt
This node already handles multiple options using a bitmask, so having aseparate boolean flag is not necessary. This simplifies the code a bitwith less arguments to give to the reindex routines, by replacing theboolean with an equivalent bitmask value.Reviewed-by: Julien RouhaudDiscussion:https://postgr.es/m/20200902110326.GA14963@paquier.xyz
1 parent67a472d commit844c05a

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
structReindexIndexCallbackState
9999
{
100-
boolconcurrent;/*flag from statement */
100+
intoptions;/*options from statement */
101101
Oidlocked_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,intoptions,boolconcurrent)
2423+
ReindexIndex(RangeVar*indexRelation,intoptions)
24242424
{
24252425
structReindexIndexCallbackStatestate;
24262426
OidindOid;
@@ -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,intoptions,boolconcurrent)
2548+
ReindexTable(RangeVar*relation,intoptions)
25462549
{
25472550
OidheapOid;
25482551
boolresult;
@@ -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(constchar*objectName,ReindexObjectTypeobjectKind,
2597-
intoptions,boolconcurrent)
2602+
intoptions)
25982603
{
25992604
OidobjectOid;
26002605
RelationrelationRelation;
@@ -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
returnnewnode;
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
|REINDEXreindex_target_multitableopt_concurrentlyname
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_typeopt_concurrentlyqualified_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_multitableopt_concurrentlyname
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
caseREINDEX_OBJECT_INDEX:
929-
ReindexIndex(stmt->relation,stmt->options,stmt->concurrent);
929+
ReindexIndex(stmt->relation,stmt->options);
930930
break;
931931
caseREINDEX_OBJECT_TABLE:
932-
ReindexTable(stmt->relation,stmt->options,stmt->concurrent);
932+
ReindexTable(stmt->relation,stmt->options);
933933
break;
934934
caseREINDEX_OBJECT_SCHEMA:
935935
caseREINDEX_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
boolcheck_not_in_use,
3535
boolskip_build,
3636
boolquiet);
37-
externvoidReindexIndex(RangeVar*indexRelation,intoptions,boolconcurrent);
38-
externOidReindexTable(RangeVar*relation,intoptions,boolconcurrent);
37+
externvoidReindexIndex(RangeVar*indexRelation,intoptions);
38+
externOidReindexTable(RangeVar*relation,intoptions);
3939
externvoidReindexMultipleTables(constchar*objectName,ReindexObjectTypeobjectKind,
40-
intoptions,boolconcurrent);
40+
intoptions);
4141
externchar*makeObjectName(constchar*name1,constchar*name2,
4242
constchar*label);
4343
externchar*ChooseRelationName(constchar*name1,constchar*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
#defineREINDEXOPT_VERBOSE (1 << 0)/* print progress info */
33543354
#defineREINDEXOPT_REPORT_PROGRESS (1 << 1)/* report pgstat progress */
33553355
#defineREINDEXOPT_MISSING_OK (1 << 2)/* skip missing relations */
3356+
#defineREINDEXOPT_CONCURRENTLY (1 << 3)/* concurrent mode */
33563357

33573358
typedefenumReindexObjectType
33583359
{
@@ -3371,7 +3372,6 @@ typedef struct ReindexStmt
33713372
RangeVar*relation;/* Table or index to reindex */
33723373
constchar*name;/* name of database to reindex */
33733374
intoptions;/* Reindex options flags */
3374-
boolconcurrent;/* reindex concurrently? */
33753375
}ReindexStmt;
33763376

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp