@ -35,6 +35,7 @@
# include "catalog/pg_namespace.h"
# include "catalog/pg_namespace.h"
# include "catalog/pg_statistic_ext.h"
# include "catalog/pg_statistic_ext.h"
# include "commands/dbcommands.h"
# include "commands/dbcommands.h"
# include "commands/progress.h"
# include "commands/tablecmds.h"
# include "commands/tablecmds.h"
# include "commands/vacuum.h"
# include "commands/vacuum.h"
# include "executor/executor.h"
# include "executor/executor.h"
@ -251,6 +252,8 @@ analyze_rel(Oid relid, RangeVar *relation,
LWLockAcquire ( ProcArrayLock , LW_EXCLUSIVE ) ;
LWLockAcquire ( ProcArrayLock , LW_EXCLUSIVE ) ;
MyPgXact - > vacuumFlags | = PROC_IN_ANALYZE ;
MyPgXact - > vacuumFlags | = PROC_IN_ANALYZE ;
LWLockRelease ( ProcArrayLock ) ;
LWLockRelease ( ProcArrayLock ) ;
pgstat_progress_start_command ( PROGRESS_COMMAND_ANALYZE ,
RelationGetRelid ( onerel ) ) ;
/*
/*
* Do the normal non - recursive ANALYZE . We can skip this for partitioned
* Do the normal non - recursive ANALYZE . We can skip this for partitioned
@ -275,6 +278,8 @@ analyze_rel(Oid relid, RangeVar *relation,
*/
*/
relation_close ( onerel , NoLock ) ;
relation_close ( onerel , NoLock ) ;
pgstat_progress_end_command ( ) ;
/*
/*
* Reset my PGXACT flag . Note : we need this here , and not in vacuum_rel ,
* Reset my PGXACT flag . Note : we need this here , and not in vacuum_rel ,
* because the vacuum flag is cleared by the end - of - xact code .
* because the vacuum flag is cleared by the end - of - xact code .
@ -506,6 +511,9 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
* Acquire the sample rows
* Acquire the sample rows
*/
*/
rows = ( HeapTuple * ) palloc ( targrows * sizeof ( HeapTuple ) ) ;
rows = ( HeapTuple * ) palloc ( targrows * sizeof ( HeapTuple ) ) ;
pgstat_progress_update_param ( PROGRESS_ANALYZE_PHASE ,
inh ? PROGRESS_ANALYZE_PHASE_ACQUIRE_SAMPLE_ROWS_INH :
PROGRESS_ANALYZE_PHASE_ACQUIRE_SAMPLE_ROWS ) ;
if ( inh )
if ( inh )
numrows = acquire_inherited_sample_rows ( onerel , elevel ,
numrows = acquire_inherited_sample_rows ( onerel , elevel ,
rows , targrows ,
rows , targrows ,
@ -526,6 +534,9 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
MemoryContext col_context ,
MemoryContext col_context ,
old_context ;
old_context ;
pgstat_progress_update_param ( PROGRESS_ANALYZE_PHASE ,
PROGRESS_ANALYZE_PHASE_COMPUTE_STATS ) ;
col_context = AllocSetContextCreate ( anl_context ,
col_context = AllocSetContextCreate ( anl_context ,
" Analyze Column " ,
" Analyze Column " ,
ALLOCSET_DEFAULT_SIZES ) ;
ALLOCSET_DEFAULT_SIZES ) ;
@ -596,6 +607,9 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
attr_cnt , vacattrstats ) ;
attr_cnt , vacattrstats ) ;
}
}
pgstat_progress_update_param ( PROGRESS_ANALYZE_PHASE ,
PROGRESS_ANALYZE_PHASE_FINALIZE_ANALYZE ) ;
/*
/*
* Update pages / tuples stats in pg_class . . . but not if we ' re doing
* Update pages / tuples stats in pg_class . . . but not if we ' re doing
* inherited stats .
* inherited stats .
@ -1034,6 +1048,8 @@ acquire_sample_rows(Relation onerel, int elevel,
ReservoirStateData rstate ;
ReservoirStateData rstate ;
TupleTableSlot * slot ;
TupleTableSlot * slot ;
TableScanDesc scan ;
TableScanDesc scan ;
BlockNumber nblocks ;
BlockNumber blksdone = 0 ;
Assert ( targrows > 0 ) ;
Assert ( targrows > 0 ) ;
@ -1043,7 +1059,12 @@ acquire_sample_rows(Relation onerel, int elevel,
OldestXmin = GetOldestXmin ( onerel , PROCARRAY_FLAGS_VACUUM ) ;
OldestXmin = GetOldestXmin ( onerel , PROCARRAY_FLAGS_VACUUM ) ;
/* Prepare for sampling block numbers */
/* Prepare for sampling block numbers */
BlockSampler_Init ( & bs , totalblocks , targrows , random ( ) ) ;
nblocks = BlockSampler_Init ( & bs , totalblocks , targrows , random ( ) ) ;
/* Report sampling block numbers */
pgstat_progress_update_param ( PROGRESS_ANALYZE_BLOCKS_TOTAL ,
nblocks ) ;
/* Prepare for sampling rows */
/* Prepare for sampling rows */
reservoir_init_selection_state ( & rstate , targrows ) ;
reservoir_init_selection_state ( & rstate , targrows ) ;
@ -1104,6 +1125,9 @@ acquire_sample_rows(Relation onerel, int elevel,
samplerows + = 1 ;
samplerows + = 1 ;
}
}
pgstat_progress_update_param ( PROGRESS_ANALYZE_BLOCKS_DONE ,
+ + blksdone ) ;
}
}
ExecDropSingleTupleTableSlot ( slot ) ;
ExecDropSingleTupleTableSlot ( slot ) ;
@ -1332,6 +1356,8 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
* rels have radically different free - space percentages , but it ' s not
* rels have radically different free - space percentages , but it ' s not
* clear that it ' s worth working harder . )
* clear that it ' s worth working harder . )
*/
*/
pgstat_progress_update_param ( PROGRESS_ANALYZE_CHILD_TABLES_TOTAL ,
nrels ) ;
numrows = 0 ;
numrows = 0 ;
* totalrows = 0 ;
* totalrows = 0 ;
* totaldeadrows = 0 ;
* totaldeadrows = 0 ;
@ -1341,6 +1367,9 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
AcquireSampleRowsFunc acquirefunc = acquirefuncs [ i ] ;
AcquireSampleRowsFunc acquirefunc = acquirefuncs [ i ] ;
double childblocks = relblocks [ i ] ;
double childblocks = relblocks [ i ] ;
pgstat_progress_update_param ( PROGRESS_ANALYZE_CURRENT_CHILD_TABLE_RELID ,
RelationGetRelid ( childrel ) ) ;
if ( childblocks > 0 )
if ( childblocks > 0 )
{
{
int childtargrows ;
int childtargrows ;
@ -1396,6 +1425,8 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
* pointers to their TOAST tables in the sampled rows .
* pointers to their TOAST tables in the sampled rows .
*/
*/
table_close ( childrel , NoLock ) ;
table_close ( childrel , NoLock ) ;
pgstat_progress_update_param ( PROGRESS_ANALYZE_CHILD_TABLES_DONE ,
i + 1 ) ;
}
}
return numrows ;
return numrows ;