Skip to content

Commit 9ebe057

Browse files
committed
Refactor cluster_rel() to handle more options
This extends cluster_rel() in such a way that more options can be added in the future, which will reduce the amount of chunk code for an upcoming SKIP_LOCKED aimed for VACUUM. As VACUUM FULL is a different flavor of CLUSTER, we want to make that extensible to ease integration. This only reworks the API and its callers, without providing anything user-facing. Two options are present now: verbose mode and relation recheck when doing the cluster command work across multiple transactions. This could be used as well as a base to extend the grammar of CLUSTER later on. Author: Michael Paquier Reviewed-by: Nathan Bossart Discussion: https://postgr.es/m/20180723031058.GE2854@paquier.xyz
1 parent d9fadbf commit 9ebe057

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(Oid tableOid, Oid indexOid, bool recheck, bool verbose)
269+
cluster_rel(Oid tableOid, Oid indexOid, int options)
269270
{
270271
Relation OldHeap;
272+
bool verbose = ((options & CLUOPT_VERBOSE) != 0);
273+
bool recheck = ((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+
int options = 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
return newnode;
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
| CLUSTER opt_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
extern void cluster(ClusterStmt *stmt, bool isTopLevel);
22-
extern void cluster_rel(Oid tableOid, Oid indexOid, bool recheck,
23-
bool verbose);
22+
extern void cluster_rel(Oid tableOid, Oid indexOid, int options);
2423
extern void check_index_is_clusterable(Relation OldHeap, Oid indexOid,
2524
bool recheck, LOCKMODE lockmode);
2625
extern void mark_index_clustered(Relation rel, Oid indexOid, bool is_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+
typedef enum ClusterOption
3116+
{
3117+
CLUOPT_RECHECK, /* recheck relation state */
3118+
CLUOPT_VERBOSE /* print progress info */
3119+
} ClusterOption;
3120+
31153121
typedef struct ClusterStmt
31163122
{
31173123
NodeTag type;
31183124
RangeVar *relation; /* relation being indexed, or NULL if all */
31193125
char *indexname; /* original index defined */
3120-
bool verbose; /* print progress info */
3126+
int options; /* 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)
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