Skip to content

Commit

Permalink
[BugFix] Fix global dict late materialize optimize ignore delete cond…
Browse files Browse the repository at this point in the history
…itions (#30156) (#30169)

Signed-off-by: stdpain <drfeng08@gmail.com>
(cherry picked from commit 9badac0)

Co-authored-by: stdpain <34912776+stdpain@users.noreply.github.com>
  • Loading branch information
mergify[bot] and stdpain authored Aug 31, 2023
1 parent 5619005 commit bfc9641
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 0 deletions.
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 @@ -109,6 +109,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;

0 comments on commit bfc9641

Please sign in to comment.