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

Commit9ebe057

Browse files
committed
Refactor cluster_rel() to handle more options
This extends cluster_rel() in such a way that more options can be addedin the future, which will reduce the amount of chunk code for anupcoming SKIP_LOCKED aimed for VACUUM. As VACUUM FULL is a differentflavor of CLUSTER, we want to make that extensible to ease integration.This only reworks the API and its callers, without providing anythinguser-facing. Two options are present now: verbose mode and relationrecheck when doing the cluster command work across multipletransactions. This could be used as well as a base to extend thegrammar of CLUSTER later on.Author: Michael PaquierReviewed-by: Nathan BossartDiscussion:https://postgr.es/m/20180723031058.GE2854@paquier.xyz
1 parentd9fadbf commit9ebe057

File tree

8 files changed

+32
-13
lines changed

8 files changed

+32
-13
lines changed

‎src/backend/commands/cluster.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
186186
heap_close(rel,NoLock);
187187

188188
/* Do the job. */
189-
cluster_rel(tableOid,indexOid,false,stmt->verbose);
189+
cluster_rel(tableOid,indexOid,stmt->options);
190190
}
191191
else
192192
{
@@ -234,7 +234,8 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
234234
/* functions in indexes may want a snapshot set */
235235
PushActiveSnapshot(GetTransactionSnapshot());
236236
/* Do the job. */
237-
cluster_rel(rvtc->tableOid,rvtc->indexOid, true,stmt->verbose);
237+
cluster_rel(rvtc->tableOid,rvtc->indexOid,
238+
stmt->options |CLUOPT_RECHECK);
238239
PopActiveSnapshot();
239240
CommitTransactionCommand();
240241
}
@@ -265,9 +266,11 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
265266
* and error messages should refer to the operation as VACUUM not CLUSTER.
266267
*/
267268
void
268-
cluster_rel(OidtableOid,OidindexOid,boolrecheck,boolverbose)
269+
cluster_rel(OidtableOid,OidindexOid,intoptions)
269270
{
270271
RelationOldHeap;
272+
boolverbose= ((options&CLUOPT_VERBOSE)!=0);
273+
boolrecheck= ((options&CLUOPT_RECHECK)!=0);
271274

272275
/* Check for user-requested abort. */
273276
CHECK_FOR_INTERRUPTS();

‎src/backend/commands/vacuum.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,13 +1551,17 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
15511551
*/
15521552
if (options&VACOPT_FULL)
15531553
{
1554+
intoptions=0;
1555+
15541556
/* close relation before vacuuming, but hold lock until commit */
15551557
relation_close(onerel,NoLock);
15561558
onerel=NULL;
15571559

1560+
if ((options&VACOPT_VERBOSE)!=0)
1561+
options |=CLUOPT_VERBOSE;
1562+
15581563
/* VACUUM FULL is now a variant of CLUSTER; see cluster.c */
1559-
cluster_rel(relid,InvalidOid, false,
1560-
(options&VACOPT_VERBOSE)!=0);
1564+
cluster_rel(relid,InvalidOid,options);
15611565
}
15621566
else
15631567
lazy_vacuum_rel(onerel,options,params,vac_strategy);

‎src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3284,7 +3284,7 @@ _copyClusterStmt(const ClusterStmt *from)
32843284

32853285
COPY_NODE_FIELD(relation);
32863286
COPY_STRING_FIELD(indexname);
3287-
COPY_SCALAR_FIELD(verbose);
3287+
COPY_SCALAR_FIELD(options);
32883288

32893289
returnnewnode;
32903290
}

‎src/backend/nodes/equalfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ _equalClusterStmt(const ClusterStmt *a, const ClusterStmt *b)
12061206
{
12071207
COMPARE_NODE_FIELD(relation);
12081208
COMPARE_STRING_FIELD(indexname);
1209-
COMPARE_SCALAR_FIELD(verbose);
1209+
COMPARE_SCALAR_FIELD(options);
12101210

12111211
return true;
12121212
}

‎src/backend/parser/gram.y

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10478,15 +10478,19 @@ ClusterStmt:
1047810478
ClusterStmt *n = makeNode(ClusterStmt);
1047910479
n->relation =$3;
1048010480
n->indexname =$4;
10481-
n->verbose =$2;
10481+
n->options =0;
10482+
if ($2)
10483+
n->options |= CLUOPT_VERBOSE;
1048210484
$$ = (Node*)n;
1048310485
}
1048410486
|CLUSTERopt_verbose
1048510487
{
1048610488
ClusterStmt *n = makeNode(ClusterStmt);
1048710489
n->relation =NULL;
1048810490
n->indexname =NULL;
10489-
n->verbose =$2;
10491+
n->options =0;
10492+
if ($2)
10493+
n->options |= CLUOPT_VERBOSE;
1049010494
$$ = (Node*)n;
1049110495
}
1049210496
/* kept for pre-8.3 compatibility*/
@@ -10495,7 +10499,9 @@ ClusterStmt:
1049510499
ClusterStmt *n = makeNode(ClusterStmt);
1049610500
n->relation =$5;
1049710501
n->indexname =$3;
10498-
n->verbose =$2;
10502+
n->options =0;
10503+
if ($2)
10504+
n->options |= CLUOPT_VERBOSE;
1049910505
$$ = (Node*)n;
1050010506
}
1050110507
;

‎src/include/commands/cluster.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020

2121
externvoidcluster(ClusterStmt*stmt,boolisTopLevel);
22-
externvoidcluster_rel(OidtableOid,OidindexOid,boolrecheck,
23-
boolverbose);
22+
externvoidcluster_rel(OidtableOid,OidindexOid,intoptions);
2423
externvoidcheck_index_is_clusterable(RelationOldHeap,OidindexOid,
2524
boolrecheck,LOCKMODElockmode);
2625
externvoidmark_index_clustered(Relationrel,OidindexOid,boolis_internal);

‎src/include/nodes/parsenodes.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,12 +3112,18 @@ typedef struct AlterSystemStmt
31123112
*Cluster Statement (support pbrown's cluster index implementation)
31133113
* ----------------------
31143114
*/
3115+
typedefenumClusterOption
3116+
{
3117+
CLUOPT_RECHECK,/* recheck relation state */
3118+
CLUOPT_VERBOSE/* print progress info */
3119+
}ClusterOption;
3120+
31153121
typedefstructClusterStmt
31163122
{
31173123
NodeTagtype;
31183124
RangeVar*relation;/* relation being indexed, or NULL if all */
31193125
char*indexname;/* original index defined */
3120-
boolverbose;/*print progress info */
3126+
intoptions;/*OR of ClusterOption flags */
31213127
}ClusterStmt;
31223128

31233129
/* ----------------------

‎src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ ClosePortalStmt
330330
ClosePtrType
331331
Clump
332332
ClusterInfo
333+
ClusterOption
333334
ClusterStmt
334335
CmdType
335336
CoalesceExpr

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp