Repository navigation
Conversation
On a PAX table whose column is entirely NULL within a micro-partition, DELETE recomputes the micro-partition statistics used by the sparse filter. The recompute reader projected only the minmax / bloomfilter columns, but MicroPartitionStats::AddRow maintains null counts for every column. For a table with no minmax / bloomfilter columns the projection is empty, OrcGroup takes the CTID-only read path and never fills tts_isnull, so the refreshed stats record hasnull=false for the all-NULL column. ExecNullTests then drops the whole block for an IS NULL qual and the query returns too few rows (pax.enable_sparse_filter=off is correct). Project every attribute when refreshing stats after DELETE so the per-column null counts stay correct. This also subsumes the issue apache#1749 fix (minmax / bloomfilter columns are covered). Add regression test delete_null_stats covering the minimal reproducer, larger all-NULL int/text columns, a mixed NULL/non-NULL column, and a table whose minmax_columns omit the all-NULL column. It fails on unpatched main and passes with the fix. See: Issue#2091 <apache#2091> Signed-off-by: Hayne01 <1518598411@qq.com>
There was a problem hiding this comment.
Hi, @Hayne01 welcome!🎊 Thanks for taking the effort to make our project better! 🙌 Keep making such awesome contributions!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2091
What does this PR do?
On a PAX table, after a
DELETEremoves a row from a micro-partition whosecolumn is entirely NULL, a query
WHERE <col> IS NULLreturns fewer rows thanexpected — the whole block is skipped. With
SET pax.enable_sparse_filter = offthe result is correct. This is a wrong-result bug in the storage layer, surfaced
by SQLancer (QUERY_PARTITIONING / TLP).
Minimal reproducer (from the issue):
Root cause. When a DELETE touches a micro-partition,
TableDeleter::DeleteWithVisibilityMaprecomputes the micro-partition statisticsthat the sparse filter relies on. The recompute reader is built with a column
projection limited to the minmax ∪ bloomfilter columns. But
MicroPartitionStats::AddRowmaintains null counts(
hasnull/allnull/nonnullrows) for every column, readingslot->tts_isnull[i]for alli. The two assumptions are incompatible:index set is empty.
PaxFilter::SetColumnProjection(cols, natts)treats"read all" as
cols.size() == natts, so an empty set yieldsproj_ = {false, false}(read nothing), not read-all.OrcFormatReader::ReadStripethen appendsnullptrfor every column.OrcGroup::ReadTuplesees an emptyproj_col_index_and takes the CTID-onlypath (
if (!pax_columns[index]) continue;), so it never writesslot->tts_isnull. The slot is created once withMakeTupleTableSlot(zero-initialized) and never cleared in the updater loop, so
tts_isnullstays
false.AddRowreadstts_isnull[c0] == false→AddNonNullColumn→ the recomputedstats claim
hasnull = falsefor the all-NULL columnc0.PaxSparseFilter::ExecNullTests,SK_SEARCHNULLbranch:if (!hasnull) return false;→ the whole block is dropped →IS NULLreturns 0.
Groups without invisible tuples take the
MergeRawInfobranch (old, correctstats) and are unaffected; the reproducer's only group contains the deleted row,
so it takes the recompute branch. The ORC data itself round-trips correctly
(hence
sparse_filter = offreturns the right answer) — only the recomputed auxstatistics are wrong.
This is the same class of bug as #1749 (projection not covering columns that
AddRowreads). #1749 covered the minmax ∪ bloomfilter columns; it did notaccount for
AddRowreading the null flag of all columns.Fix. The recompute reader must load every column, because null counts are
maintained for every column. Build the projection over all attribute indexes so
that
SetColumnProjectionclears the projection (read-all). This also subsumesthe #1749 fix.
min_max_col_idxs/bf_col_idxsare still passed toMicroPartitionStatsUpdater::Update→Initialize, so minmax/sum/bloom statesremain gated to the declared columns; only the null-count accounting (which is
per-column anyway) now sees correct
tts_isnullvalues.Type of Change
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelNew regression test
contrib/pax_storage/sql/delete_null_stats.sql(+
expected/delete_null_stats.out, wired intopax_schedule). It covers fourcases under
pax.enable_sparse_filter = on:c0all NULL):IS NULLmust return 2 (returns 0 before the fix).int/textcolumns with a partial DELETE:IS NULLreturnsthe remaining rows,
IS NOT NULLreturns 0.hasnullandnonnullrows.minmax_columnsomit the all-NULL column (non-empty projectionthat still misses the all-NULL column): returns 0 before the fix.
The test fails on unpatched
mainand passes with the fix.The PAX regression suite (
make -C contrib/pax_storage pax-test, thepax_schedulesuite) was run on the same demo cluster twice — once on unpatchedmainwith the new test added, once after applying the fix and rebuildingpax.so. The only difference between the two failure sets isdelete_null_statsgoing from FAILED to ok; the patched failure set is a strict subset of the
baseline (no new failures). The #1749 test (
delete_bloom_stats),delete_sum_stats,filter,statistics_bloom_filter,statistics/*,visimap_vec_compact,visimap_vec_storageandupdatepass in both runs.(
cbdb_parallel,filter_tree_root_quals,cluster,db_size_functionsfailin both runs — they are sensitive to the demo-cluster configuration and unrelated
to this change.)
Impact
Performance: DELETE stats recompute now reads full column data instead of
just the minmax/bloomfilter columns. Correctness takes priority over the previous
projection optimization, which produced corrupt statistics. A follow-up could
read only the PRESENT bitmaps for non-key columns to recover most of the I/O
saving; that is a larger change and is left out of this fix.
User-facing changes: Fixes a wrong-result bug —
WHERE <col> IS NULLon aPAX table after DELETE now returns the correct rows with the sparse filter at its
default (on).
Dependencies: None.
Checklist
Additional Context
Runtime before/after on
main(debug build, assertions on, demo cluster withoutmirrors), same commit and same cluster: run the reproducer BEFORE the fix, apply
the patch, rebuild
contrib/pax_storage, restart, run AFTER the fix.WHERE c0 IS NULL(sparse on, default)Assertion
before_count='0' after_count='2'→ PASS, and the PAX suiteno-regression assertion → PASS.