Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Fix global dict late materialize optimize ignore delete conditions #30156

Merged
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
1 change: 1 addition & 0 deletions be/src/storage/rowset/dictcode_column_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class GlobalDictCodeColumnIterator final : public ColumnIterator {
RETURN_IF_ERROR(_col_iter->fetch_dict_codes_by_rowid(rowids, size, _local_dict_code_col.get()));
RETURN_IF_ERROR(decode_dict_codes(*_local_dict_code_col, values));
_swap_null_columns(_local_dict_code_col.get(), values);
values->set_delete_state(_local_dict_code_col->delete_state());
return Status::OK();
}

Expand Down
139 changes: 139 additions & 0 deletions test/sql/test_low_cardinality/R/test_delete_conditions
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
-- name: test_delete_condition
create table t0 (
c0 string,
c1 string,
c2 int,
c3 int
) DUPLICATE KEY(c0) DISTRIBUTED BY HASH(c0) BUCKETS 1 PROPERTIES('replication_num' = '1');
-- result:
-- !result
insert into t0 SELECT generate_series%100, generate_series%100, generate_series%100, generate_series%100 FROM TABLE(generate_series(1, 65535));
-- result:
-- !result
insert into t0 values (null, null, null, null);
-- result:
-- !result
[UC] analyze full table t0;
-- result:
-- !result
function: wait_global_dict_ready('c0', 't0')
-- result:

-- !result
delete from t0 where c0 = "s_1";
-- result:
-- !result
select count(*) from t0;
-- result:
65536
-- !result
select count(*) from t0 where c0 = "s_2";
-- result:
0
-- !result
select count(*) from t0 where c0 != "s_2";
-- result:
65535
-- !result
select count(*) from t0 where c0 is null;
-- result:
1
-- !result
select count(*) from t0 where c0 = "s_2" and c1 = "s_2";
-- result:
0
-- !result
select count(*) from t0 where c0 = "s_2" and c1 = "s_3";
-- result:
0
-- !result
select distinct c0, c1, c2, c3 from t0 where c0 = "s_2" and c1 = "s_2" order by 1,2,3,4 limit 5;
-- result:
-- !result
select distinct c0, c1, c2, c3 from t0 where c1 = "s_2" order by 1,2,3,4 limit 5;
-- result:
-- !result
delete from t0 where c0 is null;
-- result:
-- !result
select count(*) from t0;
-- result:
65535
-- !result
select count(*), count(c0) from t0 where c0 is not null;
-- result:
65535 65535
-- !result
select count(*), count(c0) from t0 where c0 is not null;
-- result:
65535 65535
-- !result
select count(*), count(c0) from t0 where c1 is not null;
-- result:
65535 65535
-- !result
select count(*), count(c0) from t0 where c2 is not null;
-- result:
65535 65535
-- !result
select count(*), count(c0), count(distinct c0) from t0 where c2 is not null;
-- result:
65535 65535 100
-- !result
delete from t0 where c0 = "s_2";
-- result:
-- !result
select count(*) from t0 where c0 = "s_2";
-- result:
0
-- !result
select count(*) from t0 where c0 != "s_2";
-- result:
65535
-- !result
select count(*) from t0 where c1 = "s_2";
-- result:
0
-- !result
select count(*) from t0 where c1 = "s_2" or c0 = "s_2";
-- result:
0
-- !result
delete from t0 where c2 = 1000;
-- result:
-- !result
select count(*), count(c0), count(distinct c0), max(c0) from t0;
-- result:
65535 65535 100 99
-- !result
select count(*) from t0 where c0 = "s_3";
-- result:
0
-- !result
select count(*) from t0 where c1 = "s_1000";
-- result:
0
-- !result
select count(*) from t0 where c2 = 1000;
-- result:
0
-- !result
delete from t0 where c0 != "";
-- result:
-- !result
select count(*) from t0;
-- result:
0
-- !result
select count(*) from t0 where c0 = "s_3";
-- result:
0
-- !result
select count(*) from t0 where c1 = "s_3";
-- result:
0
-- !result
select count(*) from t0 where c2 = 4;
-- result:
0
-- !result
55 changes: 55 additions & 0 deletions test/sql/test_low_cardinality/T/test_delete_conditions
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- name: test_delete_condition
create table t0 (
c0 string,
c1 string,
c2 int,
c3 int
) DUPLICATE KEY(c0) DISTRIBUTED BY HASH(c0) BUCKETS 1 PROPERTIES('replication_num' = '1');

-- analyze and wait dictioanry
-- insert
insert into t0 SELECT generate_series%100, generate_series%100, generate_series%100, generate_series%100 FROM TABLE(generate_series(1, 65535));
insert into t0 values (null, null, null, null);
[UC] analyze full table t0;
function: wait_global_dict_ready('c0', 't0')

-- delete by key
delete from t0 where c0 = "s_1";

select count(*) from t0;
select count(*) from t0 where c0 = "s_2";
select count(*) from t0 where c0 != "s_2";
select count(*) from t0 where c0 is null;
select count(*) from t0 where c0 = "s_2" and c1 = "s_2";
select count(*) from t0 where c0 = "s_2" and c1 = "s_3";
select distinct c0, c1, c2, c3 from t0 where c0 = "s_2" and c1 = "s_2" order by 1,2,3,4 limit 5;
select distinct c0, c1, c2, c3 from t0 where c1 = "s_2" order by 1,2,3,4 limit 5;

-- delete null
delete from t0 where c0 is null;
select count(*) from t0;
select count(*), count(c0) from t0 where c0 is not null;
select count(*), count(c0) from t0 where c0 is not null;
select count(*), count(c0) from t0 where c1 is not null;
select count(*), count(c0) from t0 where c2 is not null;
select count(*), count(c0), count(distinct c0) from t0 where c2 is not null;

--
delete from t0 where c0 = "s_2";
select count(*) from t0 where c0 = "s_2";
select count(*) from t0 where c0 != "s_2";
select count(*) from t0 where c1 = "s_2";
select count(*) from t0 where c1 = "s_2" or c0 = "s_2";
-- delete by value
delete from t0 where c2 = 1000;
select count(*), count(c0), count(distinct c0), max(c0) from t0;
select count(*) from t0 where c0 = "s_3";
select count(*) from t0 where c1 = "s_1000";
select count(*) from t0 where c2 = 1000;

-- delete all
delete from t0 where c0 != "";
select count(*) from t0;
select count(*) from t0 where c0 = "s_3";
select count(*) from t0 where c1 = "s_3";
select count(*) from t0 where c2 = 4;