Skip to content

Commit 305a9c1

Browse files
committed
Fix fast analyze for PAX tables and simplify acquisition function selection
This commit addresses several issues with fast analyze: 1. For PAX tables, we now properly estimate the number of blocks by using table_relation_estimate_size() rather than RelationGetNumberOfBlocks(), since PAX uses non-fixed block layout. This provides more accurate sampling for PAX tables. 2. Simplified the acquisition function selection logic by always using gp_acquire_sample_rows_func for regular tables, removing the conditional check for rd_tableam->relation_acquire_sample_rows. This makes the code more straightforward and consistent. 3. Fixed an issue in datumstream.c by resetting blockRowCount when closing a file during analyze operations.
1 parent 635c06f commit 305a9c1

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/backend/commands/analyze.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,11 @@ analyze_rel_internal(Oid relid, RangeVar *relation,
358358
onerel->rd_rel->relkind == RELKIND_MATVIEW ||
359359
onerel->rd_rel->relkind == RELKIND_DIRECTORY_TABLE)
360360
{
361-
/* Regular table, so we'll use the regular row acquisition function */
362-
if (onerel->rd_tableam)
363-
acquirefunc = onerel->rd_tableam->relation_acquire_sample_rows;
364-
365361
/*
366362
* If the TableAmRoutine's gp_acquire_sample_rows_func if NULL, we use
367363
* gp_acquire_sample_rows_func as default.
368364
*/
369-
if (acquirefunc == NULL)
370-
acquirefunc = gp_acquire_sample_rows_func;
365+
acquirefunc = gp_acquire_sample_rows_func;
371366

372367
/* Also get regular table's size */
373368
relpages = AcquireNumberOfBlocks(onerel);
@@ -1716,8 +1711,24 @@ acquire_sample_rows(Relation onerel, int elevel,
17161711
* the relation should not be an AO/CO table.
17171712
*/
17181713
Assert(!RelationIsAppendOptimized(onerel));
1714+
if (RelationIsPax(onerel))
1715+
{
1716+
/* PAX use non-fixed block layout */
1717+
BlockNumber pages;
1718+
double tuples;
1719+
double allvisfrac;
1720+
int32 attr_widths;
17191721

1720-
totalblocks = RelationGetNumberOfBlocks(onerel);
1722+
table_relation_estimate_size(onerel, &attr_widths, &pages,
1723+
&tuples, &allvisfrac);
1724+
1725+
if (tuples > UINT_MAX)
1726+
tuples = UINT_MAX;
1727+
1728+
totalblocks = (BlockNumber)tuples;
1729+
}
1730+
else
1731+
totalblocks = RelationGetNumberOfBlocks(onerel);
17211732

17221733
/* Need a cutoff xmin for HeapTupleSatisfiesVacuum */
17231734
OldestXmin = GetOldestNonRemovableTransactionId(onerel);
@@ -2055,16 +2066,8 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
20552066
childrel->rd_rel->relkind == RELKIND_MATVIEW ||
20562067
childrel->rd_rel->relkind == RELKIND_DIRECTORY_TABLE)
20572068
{
2058-
/* Regular table, so use the regular row acquisition function */
2059-
if (childrel->rd_tableam)
2060-
acquirefunc = childrel->rd_tableam->relation_acquire_sample_rows;
2061-
2062-
/*
2063-
* If the TableAmRoutine's relation_acquire_sample_rows if NULL, we use
2064-
* relation_acquire_sample_rows as default.
2065-
*/
2066-
if (acquirefunc == NULL)
2067-
acquirefunc = gp_acquire_sample_rows_func;
2069+
/* use relation_acquire_sample_rows as default. */
2070+
acquirefunc = gp_acquire_sample_rows_func;
20682071

20692072
relpages = AcquireNumberOfBlocks(childrel);
20702073
}

src/backend/utils/datumstream/datumstream.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ datumstreamread_close_file(DatumStreamRead * ds)
876876
{
877877
AppendOnlyStorageRead_CloseFile(&ds->ao_read);
878878

879+
ds->blockRowCount = 0;
879880
ds->need_close_file = false;
880881
}
881882

0 commit comments

Comments
 (0)