mirror of
https://github.com/postgres/postgres.git
synced 2025-08-24 09:27:52 +03:00
Report progress of CREATE INDEX operations
This uses the progress reporting infrastructure added by c16dc1aca5
,
adding support for CREATE INDEX and CREATE INDEX CONCURRENTLY.
There are two pieces to this: one is index-AM-agnostic, and the other is
AM-specific. The latter is fairly elaborate for btrees, including
reportage for parallel index builds and the separate phases that btree
index creation uses; other index AMs, which are much simpler in their
building procedures, have simplistic reporting only, but that seems
sufficient, at least for non-concurrent builds.
The index-AM-agnostic part is fairly complete, providing insight into
the CONCURRENTLY wait phases as well as block-based progress during the
index validation table scan. (The index validation index scan requires
patching each AM, which has not been included here.)
Reviewers: Rahila Syed, Pavan Deolasee, Tatsuro Yamada
Discussion: https://postgr.es/m/20181220220022.mg63bhk26zdpvmcj@alvherre.pgsql
This commit is contained in:
@@ -108,6 +108,9 @@ typedef bool (*amproperty_function) (Oid index_oid, int attno,
|
||||
IndexAMProperty prop, const char *propname,
|
||||
bool *res, bool *isnull);
|
||||
|
||||
/* name of phase as used in progress reporting */
|
||||
typedef char *(*ambuildphasename_function) (int64 phasenum);
|
||||
|
||||
/* validate definition of an opclass for this AM */
|
||||
typedef bool (*amvalidate_function) (Oid opclassoid);
|
||||
|
||||
@@ -213,6 +216,7 @@ typedef struct IndexAmRoutine
|
||||
amcostestimate_function amcostestimate;
|
||||
amoptions_function amoptions;
|
||||
amproperty_function amproperty; /* can be NULL */
|
||||
ambuildphasename_function ambuildphasename; /* can be NULL */
|
||||
amvalidate_function amvalidate;
|
||||
ambeginscan_function ambeginscan;
|
||||
amrescan_function amrescan;
|
||||
|
@@ -45,6 +45,7 @@ typedef struct IndexVacuumInfo
|
||||
{
|
||||
Relation index; /* the index being vacuumed */
|
||||
bool analyze_only; /* ANALYZE (without any actual vacuum) */
|
||||
bool report_progress; /* emit progress.h status reports */
|
||||
bool estimated_count; /* num_heap_tuples is an estimate */
|
||||
int message_level; /* ereport level for progress messages */
|
||||
double num_heap_tuples; /* tuples remaining in heap */
|
||||
|
@@ -671,6 +671,16 @@ typedef BTScanOpaqueData *BTScanOpaque;
|
||||
#define SK_BT_DESC (INDOPTION_DESC << SK_BT_INDOPTION_SHIFT)
|
||||
#define SK_BT_NULLS_FIRST (INDOPTION_NULLS_FIRST << SK_BT_INDOPTION_SHIFT)
|
||||
|
||||
/*
|
||||
* Constant definition for progress reporting. Phase numbers must match
|
||||
* btbuildphasename.
|
||||
*/
|
||||
/* PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE is 1 (see progress.h) */
|
||||
#define PROGRESS_BTREE_PHASE_INDEXBUILD_TABLESCAN 2
|
||||
#define PROGRESS_BTREE_PHASE_PERFORMSORT_1 3
|
||||
#define PROGRESS_BTREE_PHASE_PERFORMSORT_2 4
|
||||
#define PROGRESS_BTREE_PHASE_LEAF_LOAD 5
|
||||
|
||||
/*
|
||||
* external entry points for btree, in nbtree.c
|
||||
*/
|
||||
@@ -784,6 +794,7 @@ extern bytea *btoptions(Datum reloptions, bool validate);
|
||||
extern bool btproperty(Oid index_oid, int attno,
|
||||
IndexAMProperty prop, const char *propname,
|
||||
bool *res, bool *isnull);
|
||||
extern char *btbuildphasename(int64 phasenum);
|
||||
extern IndexTuple _bt_truncate(Relation rel, IndexTuple lastleft,
|
||||
IndexTuple firstright, BTScanInsert itup_key);
|
||||
extern int _bt_keep_natts_fast(Relation rel, IndexTuple lastleft,
|
||||
|
@@ -507,6 +507,7 @@ typedef struct TableAmRoutine
|
||||
struct IndexInfo *index_nfo,
|
||||
bool allow_sync,
|
||||
bool anyvisible,
|
||||
bool progress,
|
||||
BlockNumber start_blockno,
|
||||
BlockNumber end_blockno,
|
||||
IndexBuildCallback callback,
|
||||
@@ -1369,6 +1370,8 @@ table_scan_analyze_next_tuple(TableScanDesc scan, TransactionId OldestXmin,
|
||||
* so here because the AM might reject some of the tuples for its own reasons,
|
||||
* such as being unable to store NULLs.
|
||||
*
|
||||
* If 'progress', the PROGRESS_SCAN_BLOCKS_TOTAL counter is updated when
|
||||
* starting the scan, and PROGRESS_SCAN_BLOCKS_DONE is updated as we go along.
|
||||
*
|
||||
* A side effect is to set indexInfo->ii_BrokenHotChain to true if we detect
|
||||
* any potentially broken HOT chains. Currently, we set this if there are any
|
||||
@@ -1382,6 +1385,7 @@ table_index_build_scan(Relation heap_rel,
|
||||
Relation index_rel,
|
||||
struct IndexInfo *index_nfo,
|
||||
bool allow_sync,
|
||||
bool progress,
|
||||
IndexBuildCallback callback,
|
||||
void *callback_state,
|
||||
TableScanDesc scan)
|
||||
@@ -1391,6 +1395,7 @@ table_index_build_scan(Relation heap_rel,
|
||||
index_nfo,
|
||||
allow_sync,
|
||||
false,
|
||||
progress,
|
||||
0,
|
||||
InvalidBlockNumber,
|
||||
callback,
|
||||
@@ -1414,6 +1419,7 @@ table_index_build_range_scan(Relation heap_rel,
|
||||
struct IndexInfo *index_nfo,
|
||||
bool allow_sync,
|
||||
bool anyvisible,
|
||||
bool progress,
|
||||
BlockNumber start_blockno,
|
||||
BlockNumber numblocks,
|
||||
IndexBuildCallback callback,
|
||||
@@ -1425,6 +1431,7 @@ table_index_build_range_scan(Relation heap_rel,
|
||||
index_nfo,
|
||||
allow_sync,
|
||||
anyvisible,
|
||||
progress,
|
||||
start_blockno,
|
||||
numblocks,
|
||||
callback,
|
||||
|
Reference in New Issue
Block a user