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
This commit is contained in:
parent
d9fadbf131
commit
9ebe0572ce
|
@ -186,7 +186,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
|
||||||
heap_close(rel, NoLock);
|
heap_close(rel, NoLock);
|
||||||
|
|
||||||
/* Do the job. */
|
/* Do the job. */
|
||||||
cluster_rel(tableOid, indexOid, false, stmt->verbose);
|
cluster_rel(tableOid, indexOid, stmt->options);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -234,7 +234,8 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
|
||||||
/* functions in indexes may want a snapshot set */
|
/* functions in indexes may want a snapshot set */
|
||||||
PushActiveSnapshot(GetTransactionSnapshot());
|
PushActiveSnapshot(GetTransactionSnapshot());
|
||||||
/* Do the job. */
|
/* Do the job. */
|
||||||
cluster_rel(rvtc->tableOid, rvtc->indexOid, true, stmt->verbose);
|
cluster_rel(rvtc->tableOid, rvtc->indexOid,
|
||||||
|
stmt->options | CLUOPT_RECHECK);
|
||||||
PopActiveSnapshot();
|
PopActiveSnapshot();
|
||||||
CommitTransactionCommand();
|
CommitTransactionCommand();
|
||||||
}
|
}
|
||||||
|
@ -265,9 +266,11 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
|
||||||
* and error messages should refer to the operation as VACUUM not CLUSTER.
|
* and error messages should refer to the operation as VACUUM not CLUSTER.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cluster_rel(Oid tableOid, Oid indexOid, bool recheck, bool verbose)
|
cluster_rel(Oid tableOid, Oid indexOid, int options)
|
||||||
{
|
{
|
||||||
Relation OldHeap;
|
Relation OldHeap;
|
||||||
|
bool verbose = ((options & CLUOPT_VERBOSE) != 0);
|
||||||
|
bool recheck = ((options & CLUOPT_RECHECK) != 0);
|
||||||
|
|
||||||
/* Check for user-requested abort. */
|
/* Check for user-requested abort. */
|
||||||
CHECK_FOR_INTERRUPTS();
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
|
@ -1551,13 +1551,17 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
|
||||||
*/
|
*/
|
||||||
if (options & VACOPT_FULL)
|
if (options & VACOPT_FULL)
|
||||||
{
|
{
|
||||||
|
int options = 0;
|
||||||
|
|
||||||
/* close relation before vacuuming, but hold lock until commit */
|
/* close relation before vacuuming, but hold lock until commit */
|
||||||
relation_close(onerel, NoLock);
|
relation_close(onerel, NoLock);
|
||||||
onerel = NULL;
|
onerel = NULL;
|
||||||
|
|
||||||
|
if ((options & VACOPT_VERBOSE) != 0)
|
||||||
|
options |= CLUOPT_VERBOSE;
|
||||||
|
|
||||||
/* VACUUM FULL is now a variant of CLUSTER; see cluster.c */
|
/* VACUUM FULL is now a variant of CLUSTER; see cluster.c */
|
||||||
cluster_rel(relid, InvalidOid, false,
|
cluster_rel(relid, InvalidOid, options);
|
||||||
(options & VACOPT_VERBOSE) != 0);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
lazy_vacuum_rel(onerel, options, params, vac_strategy);
|
lazy_vacuum_rel(onerel, options, params, vac_strategy);
|
||||||
|
|
|
@ -3284,7 +3284,7 @@ _copyClusterStmt(const ClusterStmt *from)
|
||||||
|
|
||||||
COPY_NODE_FIELD(relation);
|
COPY_NODE_FIELD(relation);
|
||||||
COPY_STRING_FIELD(indexname);
|
COPY_STRING_FIELD(indexname);
|
||||||
COPY_SCALAR_FIELD(verbose);
|
COPY_SCALAR_FIELD(options);
|
||||||
|
|
||||||
return newnode;
|
return newnode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1206,7 +1206,7 @@ _equalClusterStmt(const ClusterStmt *a, const ClusterStmt *b)
|
||||||
{
|
{
|
||||||
COMPARE_NODE_FIELD(relation);
|
COMPARE_NODE_FIELD(relation);
|
||||||
COMPARE_STRING_FIELD(indexname);
|
COMPARE_STRING_FIELD(indexname);
|
||||||
COMPARE_SCALAR_FIELD(verbose);
|
COMPARE_SCALAR_FIELD(options);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10478,7 +10478,9 @@ ClusterStmt:
|
||||||
ClusterStmt *n = makeNode(ClusterStmt);
|
ClusterStmt *n = makeNode(ClusterStmt);
|
||||||
n->relation = $3;
|
n->relation = $3;
|
||||||
n->indexname = $4;
|
n->indexname = $4;
|
||||||
n->verbose = $2;
|
n->options = 0;
|
||||||
|
if ($2)
|
||||||
|
n->options |= CLUOPT_VERBOSE;
|
||||||
$$ = (Node*)n;
|
$$ = (Node*)n;
|
||||||
}
|
}
|
||||||
| CLUSTER opt_verbose
|
| CLUSTER opt_verbose
|
||||||
|
@ -10486,7 +10488,9 @@ ClusterStmt:
|
||||||
ClusterStmt *n = makeNode(ClusterStmt);
|
ClusterStmt *n = makeNode(ClusterStmt);
|
||||||
n->relation = NULL;
|
n->relation = NULL;
|
||||||
n->indexname = NULL;
|
n->indexname = NULL;
|
||||||
n->verbose = $2;
|
n->options = 0;
|
||||||
|
if ($2)
|
||||||
|
n->options |= CLUOPT_VERBOSE;
|
||||||
$$ = (Node*)n;
|
$$ = (Node*)n;
|
||||||
}
|
}
|
||||||
/* kept for pre-8.3 compatibility */
|
/* kept for pre-8.3 compatibility */
|
||||||
|
@ -10495,7 +10499,9 @@ ClusterStmt:
|
||||||
ClusterStmt *n = makeNode(ClusterStmt);
|
ClusterStmt *n = makeNode(ClusterStmt);
|
||||||
n->relation = $5;
|
n->relation = $5;
|
||||||
n->indexname = $3;
|
n->indexname = $3;
|
||||||
n->verbose = $2;
|
n->options = 0;
|
||||||
|
if ($2)
|
||||||
|
n->options |= CLUOPT_VERBOSE;
|
||||||
$$ = (Node*)n;
|
$$ = (Node*)n;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
extern void cluster(ClusterStmt *stmt, bool isTopLevel);
|
extern void cluster(ClusterStmt *stmt, bool isTopLevel);
|
||||||
extern void cluster_rel(Oid tableOid, Oid indexOid, bool recheck,
|
extern void cluster_rel(Oid tableOid, Oid indexOid, int options);
|
||||||
bool verbose);
|
|
||||||
extern void check_index_is_clusterable(Relation OldHeap, Oid indexOid,
|
extern void check_index_is_clusterable(Relation OldHeap, Oid indexOid,
|
||||||
bool recheck, LOCKMODE lockmode);
|
bool recheck, LOCKMODE lockmode);
|
||||||
extern void mark_index_clustered(Relation rel, Oid indexOid, bool is_internal);
|
extern void mark_index_clustered(Relation rel, Oid indexOid, bool is_internal);
|
||||||
|
|
|
@ -3112,12 +3112,18 @@ typedef struct AlterSystemStmt
|
||||||
* Cluster Statement (support pbrown's cluster index implementation)
|
* Cluster Statement (support pbrown's cluster index implementation)
|
||||||
* ----------------------
|
* ----------------------
|
||||||
*/
|
*/
|
||||||
|
typedef enum ClusterOption
|
||||||
|
{
|
||||||
|
CLUOPT_RECHECK, /* recheck relation state */
|
||||||
|
CLUOPT_VERBOSE /* print progress info */
|
||||||
|
} ClusterOption;
|
||||||
|
|
||||||
typedef struct ClusterStmt
|
typedef struct ClusterStmt
|
||||||
{
|
{
|
||||||
NodeTag type;
|
NodeTag type;
|
||||||
RangeVar *relation; /* relation being indexed, or NULL if all */
|
RangeVar *relation; /* relation being indexed, or NULL if all */
|
||||||
char *indexname; /* original index defined */
|
char *indexname; /* original index defined */
|
||||||
bool verbose; /* print progress info */
|
int options; /* OR of ClusterOption flags */
|
||||||
} ClusterStmt;
|
} ClusterStmt;
|
||||||
|
|
||||||
/* ----------------------
|
/* ----------------------
|
||||||
|
|
|
@ -330,6 +330,7 @@ ClosePortalStmt
|
||||||
ClosePtrType
|
ClosePtrType
|
||||||
Clump
|
Clump
|
||||||
ClusterInfo
|
ClusterInfo
|
||||||
|
ClusterOption
|
||||||
ClusterStmt
|
ClusterStmt
|
||||||
CmdType
|
CmdType
|
||||||
CoalesceExpr
|
CoalesceExpr
|
||||||
|
|
Loading…
Reference in New Issue