Skip to content

Commit 6e33101

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 23aef44 commit 6e33101

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

src/backend/access/aocs/aocsam.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ aocs_blkdirscan_init(AOCSScanDesc scan)
478478
if (scan->aocsfetch == NULL)
479479
{
480480
int natts = RelationGetNumberOfAttributes(scan->rs_base.rs_rd);
481-
scan->proj = palloc(natts * sizeof(*scan->proj));
482-
MemSet(scan->proj, true, natts * sizeof(*scan->proj));
481+
scan->proj = palloc(natts * sizeof(bool));
482+
MemSet(scan->proj, true, natts * sizeof(bool));
483483

484484
scan->aocsfetch = aocs_fetch_init(scan->rs_base.rs_rd,
485485
scan->rs_base.rs_snapshot,
@@ -662,10 +662,9 @@ aocs_beginscan_internal(Relation relation,
662662
AccessShareLock,
663663
appendOnlyMetaDataSnapshot);
664664

665-
if ((flags & SO_TYPE_ANALYZE) != 0)
665+
if ((flags & SO_TYPE_ANALYZE) != 0 && OidIsValid(blkdirrelid))
666666
{
667-
if (OidIsValid(blkdirrelid))
668-
aocs_blkdirscan_init(scan);
667+
aocs_blkdirscan_init(scan);
669668
}
670669
}
671670

@@ -752,6 +751,12 @@ aocs_locate_target_segment(AOCSScanDesc scan, int64 targrow)
752751
if (rowcount <= 0)
753752
continue;
754753

754+
if (scan->seginfo[i]->state == AOSEG_STATE_AWAITING_DROP)
755+
{
756+
/* skip this segment, it is awaiting drop */
757+
continue;
758+
}
759+
755760
if (scan->segfirstrow + rowcount - 1 >= targrow)
756761
{
757762
/* found the target segment */

src/backend/access/appendonly/appendonlyam.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,12 @@ appendonly_locate_target_segment(AppendOnlyScanDesc scan, int64 targrow)
11321132
if (rowcount <= 0)
11331133
continue;
11341134

1135+
if (scan->aos_segfile_arr[i]->state == AOSEG_STATE_AWAITING_DROP)
1136+
{
1137+
/* skip this segment, it is awaiting drop */
1138+
continue;
1139+
}
1140+
11351141
if (scan->segfirstrow + rowcount - 1 >= targrow)
11361142
{
11371143
/* found the target segment */

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)