Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions contrib/pax_storage/expected/delete_null_stats.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
-- Regression test for issue #2091:
-- After a DELETE on a PAX micro-partition whose column is entirely NULL,
-- "WHERE col IS NULL" must still return the remaining rows while the sparse
-- filter is enabled.
--
-- Root cause: DeleteWithVisibilityMap recomputed micro-partition stats using a
-- column projection of only the minmax / bloomfilter columns. When the table
-- declares none of those (or the all-NULL column is not among them), the
-- projected tuple left every tts_isnull flag false, so the refreshed stats
-- recorded "no nulls" (hasnull = false). The sparse filter then skipped the
-- whole block for an IS NULL qual and returned too few rows.
--
-- The fix projects every attribute when refreshing stats after DELETE, so the
-- per-column null counts (hasnull / allnull / nonnullrows) stay correct.
set pax.enable_sparse_filter = on;
-- Case 1: minimal reproducer from the issue. No minmax / bloomfilter columns,
-- c0 is entirely NULL. Pre-fix this returned 0 instead of 2.
create table pax_delete_null_2091 (c0 int, c1 boolean)
using pax
distributed by (c0);
insert into pax_delete_null_2091 (c1) values (true), (false), (false);
delete from pax_delete_null_2091 where c1;
select count(*) as isnull_rows from pax_delete_null_2091 where c0 is null;
isnull_rows
-------------
2
(1 row)

select count(*) as total_rows from pax_delete_null_2091;
total_rows
------------
2
(1 row)

drop table pax_delete_null_2091;
-- Case 2: larger all-NULL columns of different types, partial DELETE.
create table pax_delete_null_2091_big (id int, payload int, tag text)
using pax
distributed by (id);
insert into pax_delete_null_2091_big
select i, null, null from generate_series(1, 2000) i;
delete from pax_delete_null_2091_big where id between 1 and 500;
select count(*) as payload_isnull from pax_delete_null_2091_big where payload is null;
payload_isnull
----------------
1500
(1 row)

select count(*) as tag_isnull from pax_delete_null_2091_big where tag is null;
tag_isnull
------------
1500
(1 row)

select count(*) as payload_notnull from pax_delete_null_2091_big where payload is not null;
payload_notnull
-----------------
0
(1 row)

drop table pax_delete_null_2091_big;
-- Case 3: mixed NULL / non-NULL column. Checks both hasnull and nonnullrows
-- after DELETE (the column is neither all-NULL nor all-non-NULL).
create table pax_delete_null_2091_mixed (id int, v int)
using pax
distributed by (id);
insert into pax_delete_null_2091_mixed
select i, case when i % 2 = 0 then null else i end
from generate_series(1, 1000) i;
delete from pax_delete_null_2091_mixed where id between 1 and 200;
select count(*) as v_isnull from pax_delete_null_2091_mixed where v is null;
v_isnull
----------
400
(1 row)

select count(*) as v_notnull from pax_delete_null_2091_mixed where v is not null;
v_notnull
-----------
400
(1 row)

drop table pax_delete_null_2091_mixed;
-- Case 4: minmax_columns declared on a different column, so the projection is
-- non-empty but still omits the all-NULL column. Pre-fix this also returned 0.
create table pax_delete_null_2091_mm (id int, nullcol int, key int)
using pax
with (minmax_columns = 'key')
distributed by (id);
insert into pax_delete_null_2091_mm
select i, null, i from generate_series(1, 1000) i;
delete from pax_delete_null_2091_mm where id between 1 and 100;
select count(*) as nullcol_isnull from pax_delete_null_2091_mm where nullcol is null;
nullcol_isnull
----------------
900
(1 row)

select count(*) as total_rows from pax_delete_null_2091_mm;
total_rows
------------
900
(1 row)

drop table pax_delete_null_2091_mm;
reset pax.enable_sparse_filter;
1 change: 1 addition & 0 deletions contrib/pax_storage/pax_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test: filter_tree filter_tree_arithmetic
test: filter_tree_root_quals
test: statistics/statistics
test: delete_sum_stats
test: delete_null_stats
test: statistics/min_max_time_types statistics/min_max_text_types statistics/min_max_other_types statistics/min_max_net_types statistics/min_max_int_types statistics/min_max_geo_types statistics/min_max_float_types statistics/min_max_bit_byte_types


Expand Down
83 changes: 83 additions & 0 deletions contrib/pax_storage/sql/delete_null_stats.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
-- Regression test for issue #2091:
-- After a DELETE on a PAX micro-partition whose column is entirely NULL,
-- "WHERE col IS NULL" must still return the remaining rows while the sparse
-- filter is enabled.
--
-- Root cause: DeleteWithVisibilityMap recomputed micro-partition stats using a
-- column projection of only the minmax / bloomfilter columns. When the table
-- declares none of those (or the all-NULL column is not among them), the
-- projected tuple left every tts_isnull flag false, so the refreshed stats
-- recorded "no nulls" (hasnull = false). The sparse filter then skipped the
-- whole block for an IS NULL qual and returned too few rows.
--
-- The fix projects every attribute when refreshing stats after DELETE, so the
-- per-column null counts (hasnull / allnull / nonnullrows) stay correct.

set pax.enable_sparse_filter = on;

-- Case 1: minimal reproducer from the issue. No minmax / bloomfilter columns,
-- c0 is entirely NULL. Pre-fix this returned 0 instead of 2.
create table pax_delete_null_2091 (c0 int, c1 boolean)
using pax
distributed by (c0);

insert into pax_delete_null_2091 (c1) values (true), (false), (false);
delete from pax_delete_null_2091 where c1;

select count(*) as isnull_rows from pax_delete_null_2091 where c0 is null;

select count(*) as total_rows from pax_delete_null_2091;

drop table pax_delete_null_2091;

-- Case 2: larger all-NULL columns of different types, partial DELETE.
create table pax_delete_null_2091_big (id int, payload int, tag text)
using pax
distributed by (id);

insert into pax_delete_null_2091_big
select i, null, null from generate_series(1, 2000) i;
delete from pax_delete_null_2091_big where id between 1 and 500;

select count(*) as payload_isnull from pax_delete_null_2091_big where payload is null;

select count(*) as tag_isnull from pax_delete_null_2091_big where tag is null;
select count(*) as payload_notnull from pax_delete_null_2091_big where payload is not null;

drop table pax_delete_null_2091_big;

-- Case 3: mixed NULL / non-NULL column. Checks both hasnull and nonnullrows
-- after DELETE (the column is neither all-NULL nor all-non-NULL).
create table pax_delete_null_2091_mixed (id int, v int)
using pax
distributed by (id);

insert into pax_delete_null_2091_mixed
select i, case when i % 2 = 0 then null else i end
from generate_series(1, 1000) i;
delete from pax_delete_null_2091_mixed where id between 1 and 200;

select count(*) as v_isnull from pax_delete_null_2091_mixed where v is null;

select count(*) as v_notnull from pax_delete_null_2091_mixed where v is not null;

drop table pax_delete_null_2091_mixed;

-- Case 4: minmax_columns declared on a different column, so the projection is
-- non-empty but still omits the all-NULL column. Pre-fix this also returned 0.
create table pax_delete_null_2091_mm (id int, nullcol int, key int)
using pax
with (minmax_columns = 'key')
distributed by (id);

insert into pax_delete_null_2091_mm
select i, null, i from generate_series(1, 1000) i;
delete from pax_delete_null_2091_mm where id between 1 and 100;

select count(*) as nullcol_isnull from pax_delete_null_2091_mm where nullcol is null;

select count(*) as total_rows from pax_delete_null_2091_mm;

drop table pax_delete_null_2091_mm;

reset pax.enable_sparse_filter;
14 changes: 9 additions & 5 deletions contrib/pax_storage/src/cpp/storage/pax.cc
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,15 @@ void TableDeleter::DeleteWithVisibilityMap(
min_max_col_idxs = cbdb::GetMinMaxColumnIndexes(rel_);
bf_col_idxs = cbdb::GetBloomFilterColumnIndexes(rel_);

// Projection must cover minmax ∪ bloomfilter columns; otherwise
// AddRow reads uninitialized slot values for bf columns (issue #1749).
std::set_union(min_max_col_idxs.begin(), min_max_col_idxs.end(),
bf_col_idxs.begin(), bf_col_idxs.end(),
std::back_inserter(stats_proj_col_idxs));
// AddRow maintains null counts (hasnull / allnull / nonnullrows) for every
// column, so the recompute reader must load every column. A projection
// limited to minmax / bloomfilter columns leaves the rest unloaded: their
// tts_isnull stays false, the refreshed stats claim hasnull=false for an
// all-NULL column, and the sparse filter drops the block for IS NULL after
// a DELETE (issue #2091). Reading all attributes also subsumes issue #1749.
for (int i = 0; i < rel_->rd_att->natts; i++) {
stats_proj_col_idxs.push_back(i);
}
stats_updater_projection->SetColumnProjection(stats_proj_col_idxs,
rel_->rd_att->natts);
do {
Expand Down
Loading