@@ -76,6 +76,8 @@ int default_statistics_target = 100;
76
76
/* A few variables that don't seem worth passing around as parameters */
77
77
static MemoryContext anl_context = NULL ;
78
78
static BufferAccessStrategy vac_strategy ;
79
+ static ScanAnalyzeNextBlockFunc scan_analyze_next_block ;
80
+ static ScanAnalyzeNextTupleFunc scan_analyze_next_tuple ;
79
81
80
82
81
83
static void do_analyze_rel (Relation onerel ,
@@ -88,9 +90,6 @@ static void compute_index_stats(Relation onerel, double totalrows,
88
90
MemoryContext col_context );
89
91
static VacAttrStats * examine_attribute (Relation onerel , int attnum ,
90
92
Node * index_expr );
91
- static int acquire_sample_rows (Relation onerel , int elevel ,
92
- HeapTuple * rows , int targrows ,
93
- double * totalrows , double * totaldeadrows );
94
93
static int compare_rows (const void * a , const void * b , void * arg );
95
94
static int acquire_inherited_sample_rows (Relation onerel , int elevel ,
96
95
HeapTuple * rows , int targrows ,
@@ -191,7 +190,10 @@ analyze_rel(Oid relid, RangeVar *relation,
191
190
if (onerel -> rd_rel -> relkind == RELKIND_RELATION ||
192
191
onerel -> rd_rel -> relkind == RELKIND_MATVIEW )
193
192
{
194
- /* Use row acquisition function provided by table AM */
193
+ /*
194
+ * Get row acquisition function, blocks and tuples iteration callbacks
195
+ * provided by table AM
196
+ */
195
197
table_relation_analyze (onerel , & acquirefunc ,
196
198
& relpages , vac_strategy );
197
199
}
@@ -1117,15 +1119,17 @@ block_sampling_read_stream_next(ReadStream *stream,
1117
1119
}
1118
1120
1119
1121
/*
1120
- * acquire_sample_rows -- acquire a random sample of rows from the heap
1122
+ * acquire_sample_rows -- acquire a random sample of rows from the
1123
+ * block-based relation
1121
1124
*
1122
1125
* Selected rows are returned in the caller-allocated array rows[], which
1123
1126
* must have at least targrows entries.
1124
1127
* The actual number of rows selected is returned as the function result.
1125
- * We also estimate the total numbers of live and dead rows in the heap ,
1128
+ * We also estimate the total numbers of live and dead rows in the relation ,
1126
1129
* and return them into *totalrows and *totaldeadrows, respectively.
1127
1130
*
1128
- * The returned list of tuples is in order by physical position in the heap.
1131
+ * The returned list of tuples is in order by physical position in the
1132
+ * relation.
1129
1133
* (We will rely on this later to derive correlation estimates.)
1130
1134
*
1131
1135
* As of May 2004 we use a new two-stage method: Stage one selects up
@@ -1147,7 +1151,7 @@ block_sampling_read_stream_next(ReadStream *stream,
1147
1151
* look at a statistically unbiased set of blocks, we should get
1148
1152
* unbiased estimates of the average numbers of live and dead rows per
1149
1153
* block. The previous sampling method put too much credence in the row
1150
- * density near the start of the heap .
1154
+ * density near the start of the relation .
1151
1155
*/
1152
1156
static int
1153
1157
acquire_sample_rows (Relation onerel , int elevel ,
@@ -1188,7 +1192,7 @@ acquire_sample_rows(Relation onerel, int elevel,
1188
1192
/* Prepare for sampling rows */
1189
1193
reservoir_init_selection_state (& rstate , targrows );
1190
1194
1191
- scan = heap_beginscan (onerel , NULL , 0 , NULL , NULL , SO_TYPE_ANALYZE );
1195
+ scan = table_beginscan_analyze (onerel );
1192
1196
slot = table_slot_create (onerel , NULL );
1193
1197
1194
1198
stream = read_stream_begin_relation (READ_STREAM_MAINTENANCE ,
@@ -1200,11 +1204,11 @@ acquire_sample_rows(Relation onerel, int elevel,
1200
1204
0 );
1201
1205
1202
1206
/* Outer loop over blocks to sample */
1203
- while (heapam_scan_analyze_next_block (scan , stream ))
1207
+ while (scan_analyze_next_block (scan , stream ))
1204
1208
{
1205
1209
vacuum_delay_point ();
1206
1210
1207
- while (heapam_scan_analyze_next_tuple (scan , OldestXmin , & liverows , & deadrows , slot ))
1211
+ while (scan_analyze_next_tuple (scan , OldestXmin , & liverows , & deadrows , slot ))
1208
1212
{
1209
1213
/*
1210
1214
* The first targrows sample rows are simply copied into the
@@ -1256,7 +1260,7 @@ acquire_sample_rows(Relation onerel, int elevel,
1256
1260
read_stream_end (stream );
1257
1261
1258
1262
ExecDropSingleTupleTableSlot (slot );
1259
- heap_endscan (scan );
1263
+ table_endscan (scan );
1260
1264
1261
1265
/*
1262
1266
* If we didn't find as many tuples as we wanted then we're done. No sort
@@ -1328,16 +1332,22 @@ compare_rows(const void *a, const void *b, void *arg)
1328
1332
}
1329
1333
1330
1334
/*
1331
- * heapam_analyze -- implementation of relation_analyze() table access method
1332
- * callback for heap
1335
+ * block_level_table_analyze -- implementation of relation_analyze() for
1336
+ * block-level table access methods
1333
1337
*/
1334
1338
void
1335
- heapam_analyze (Relation relation , AcquireSampleRowsFunc * func ,
1336
- BlockNumber * totalpages , BufferAccessStrategy bstrategy )
1339
+ block_level_table_analyze (Relation relation ,
1340
+ AcquireSampleRowsFunc * func ,
1341
+ BlockNumber * totalpages ,
1342
+ BufferAccessStrategy bstrategy ,
1343
+ ScanAnalyzeNextBlockFunc scan_analyze_next_block_cb ,
1344
+ ScanAnalyzeNextTupleFunc scan_analyze_next_tuple_cb )
1337
1345
{
1338
1346
* func = acquire_sample_rows ;
1339
1347
* totalpages = RelationGetNumberOfBlocks (relation );
1340
1348
vac_strategy = bstrategy ;
1349
+ scan_analyze_next_block = scan_analyze_next_block_cb ;
1350
+ scan_analyze_next_tuple = scan_analyze_next_tuple_cb ;
1341
1351
}
1342
1352
1343
1353
0 commit comments