17
17
#include <math.h>
18
18
19
19
#include "access/detoast.h"
20
- #include "access/heapam.h"
21
20
#include "access/genam.h"
22
21
#include "access/multixact.h"
23
22
#include "access/relation.h"
@@ -76,8 +75,6 @@ int default_statistics_target = 100;
76
75
/* A few variables that don't seem worth passing around as parameters */
77
76
static MemoryContext anl_context = NULL ;
78
77
static BufferAccessStrategy vac_strategy ;
79
- static ScanAnalyzeNextBlockFunc scan_analyze_next_block ;
80
- static ScanAnalyzeNextTupleFunc scan_analyze_next_tuple ;
81
78
82
79
83
80
static void do_analyze_rel (Relation onerel ,
@@ -90,6 +87,9 @@ static void compute_index_stats(Relation onerel, double totalrows,
90
87
MemoryContext col_context );
91
88
static VacAttrStats * examine_attribute (Relation onerel , int attnum ,
92
89
Node * index_expr );
90
+ static int acquire_sample_rows (Relation onerel , int elevel ,
91
+ HeapTuple * rows , int targrows ,
92
+ double * totalrows , double * totaldeadrows );
93
93
static int compare_rows (const void * a , const void * b , void * arg );
94
94
static int acquire_inherited_sample_rows (Relation onerel , int elevel ,
95
95
HeapTuple * rows , int targrows ,
@@ -190,12 +190,10 @@ analyze_rel(Oid relid, RangeVar *relation,
190
190
if (onerel -> rd_rel -> relkind == RELKIND_RELATION ||
191
191
onerel -> rd_rel -> relkind == RELKIND_MATVIEW )
192
192
{
193
- /*
194
- * Get row acquisition function, blocks and tuples iteration callbacks
195
- * provided by table AM
196
- */
197
- table_relation_analyze (onerel , & acquirefunc ,
198
- & relpages , vac_strategy );
193
+ /* Regular table, so we'll use the regular row acquisition function */
194
+ acquirefunc = acquire_sample_rows ;
195
+ /* Also get regular table's size */
196
+ relpages = RelationGetNumberOfBlocks (onerel );
199
197
}
200
198
else if (onerel -> rd_rel -> relkind == RELKIND_FOREIGN_TABLE )
201
199
{
@@ -1119,17 +1117,15 @@ block_sampling_read_stream_next(ReadStream *stream,
1119
1117
}
1120
1118
1121
1119
/*
1122
- * acquire_sample_rows -- acquire a random sample of rows from the
1123
- * block-based relation
1120
+ * acquire_sample_rows -- acquire a random sample of rows from the table
1124
1121
*
1125
1122
* Selected rows are returned in the caller-allocated array rows[], which
1126
1123
* must have at least targrows entries.
1127
1124
* The actual number of rows selected is returned as the function result.
1128
- * We also estimate the total numbers of live and dead rows in the relation ,
1125
+ * We also estimate the total numbers of live and dead rows in the table ,
1129
1126
* and return them into *totalrows and *totaldeadrows, respectively.
1130
1127
*
1131
- * The returned list of tuples is in order by physical position in the
1132
- * relation.
1128
+ * The returned list of tuples is in order by physical position in the table.
1133
1129
* (We will rely on this later to derive correlation estimates.)
1134
1130
*
1135
1131
* As of May 2004 we use a new two-stage method: Stage one selects up
@@ -1151,7 +1147,7 @@ block_sampling_read_stream_next(ReadStream *stream,
1151
1147
* look at a statistically unbiased set of blocks, we should get
1152
1148
* unbiased estimates of the average numbers of live and dead rows per
1153
1149
* block. The previous sampling method put too much credence in the row
1154
- * density near the start of the relation .
1150
+ * density near the start of the table .
1155
1151
*/
1156
1152
static int
1157
1153
acquire_sample_rows (Relation onerel , int elevel ,
@@ -1204,11 +1200,11 @@ acquire_sample_rows(Relation onerel, int elevel,
1204
1200
0 );
1205
1201
1206
1202
/* Outer loop over blocks to sample */
1207
- while (scan_analyze_next_block (scan , stream ))
1203
+ while (table_scan_analyze_next_block (scan , stream ))
1208
1204
{
1209
1205
vacuum_delay_point ();
1210
1206
1211
- while (scan_analyze_next_tuple (scan , OldestXmin , & liverows , & deadrows , slot ))
1207
+ while (table_scan_analyze_next_tuple (scan , OldestXmin , & liverows , & deadrows , slot ))
1212
1208
{
1213
1209
/*
1214
1210
* The first targrows sample rows are simply copied into the
@@ -1331,25 +1327,6 @@ compare_rows(const void *a, const void *b, void *arg)
1331
1327
return 0 ;
1332
1328
}
1333
1329
1334
- /*
1335
- * block_level_table_analyze -- implementation of relation_analyze() for
1336
- * block-level table access methods
1337
- */
1338
- void
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 )
1345
- {
1346
- * func = acquire_sample_rows ;
1347
- * totalpages = RelationGetNumberOfBlocks (relation );
1348
- vac_strategy = bstrategy ;
1349
- scan_analyze_next_block = scan_analyze_next_block_cb ;
1350
- scan_analyze_next_tuple = scan_analyze_next_tuple_cb ;
1351
- }
1352
-
1353
1330
1354
1331
/*
1355
1332
* acquire_inherited_sample_rows -- acquire sample rows from inheritance tree
@@ -1439,9 +1416,9 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
1439
1416
if (childrel -> rd_rel -> relkind == RELKIND_RELATION ||
1440
1417
childrel -> rd_rel -> relkind == RELKIND_MATVIEW )
1441
1418
{
1442
- /* Use row acquisition function provided by table AM */
1443
- table_relation_analyze ( childrel , & acquirefunc ,
1444
- & relpages , vac_strategy );
1419
+ /* Regular table, so use the regular row acquisition function */
1420
+ acquirefunc = acquire_sample_rows ;
1421
+ relpages = RelationGetNumberOfBlocks ( childrel );
1445
1422
}
1446
1423
else if (childrel -> rd_rel -> relkind == RELKIND_FOREIGN_TABLE )
1447
1424
{
0 commit comments