From 1915fcdc3c02d3ffdfa71b2f13898f6023a33284 Mon Sep 17 00:00:00 2001 From: Sun Chenyang Date: Tue, 22 Oct 2024 11:36:27 +0800 Subject: [PATCH] [test] (inverted index) add some regression cases (#42131) ## Proposed changes I cherry-picked the regression test cases for issues fixed in branch-2.0 and branch-2.1 to ensure the correctness of the master branch. #41200 #41297 #40425 #40630 --- .../inverted_index_p0/test_index_rqg_bug5.out | 4 ++ .../inverted_index_p0/test_index_rqg_bug6.out | 7 +++ .../inverted_index_p0/test_index_rqg_bug7.out | 4 ++ .../inverted_index_p0/test_need_read_data.out | 3 + .../test_index_rqg_bug5.groovy | 38 +++++++++++ .../test_index_rqg_bug6.groovy | 63 +++++++++++++++++++ .../test_index_rqg_bug7.groovy | 44 +++++++++++++ .../test_need_read_data.groovy | 22 +++++++ 8 files changed, 185 insertions(+) create mode 100644 regression-test/data/inverted_index_p0/test_index_rqg_bug5.out create mode 100644 regression-test/data/inverted_index_p0/test_index_rqg_bug6.out create mode 100644 regression-test/data/inverted_index_p0/test_index_rqg_bug7.out create mode 100644 regression-test/suites/inverted_index_p0/test_index_rqg_bug5.groovy create mode 100644 regression-test/suites/inverted_index_p0/test_index_rqg_bug6.groovy create mode 100644 regression-test/suites/inverted_index_p0/test_index_rqg_bug7.groovy diff --git a/regression-test/data/inverted_index_p0/test_index_rqg_bug5.out b/regression-test/data/inverted_index_p0/test_index_rqg_bug5.out new file mode 100644 index 00000000000000..095c7b2035676a --- /dev/null +++ b/regression-test/data/inverted_index_p0/test_index_rqg_bug5.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +1 + diff --git a/regression-test/data/inverted_index_p0/test_index_rqg_bug6.out b/regression-test/data/inverted_index_p0/test_index_rqg_bug6.out new file mode 100644 index 00000000000000..edf3444ebe2928 --- /dev/null +++ b/regression-test/data/inverted_index_p0/test_index_rqg_bug6.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +1 + +-- !sql_2 -- +3 + diff --git a/regression-test/data/inverted_index_p0/test_index_rqg_bug7.out b/regression-test/data/inverted_index_p0/test_index_rqg_bug7.out new file mode 100644 index 00000000000000..4ee136aef2b9c5 --- /dev/null +++ b/regression-test/data/inverted_index_p0/test_index_rqg_bug7.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +2 + diff --git a/regression-test/data/inverted_index_p0/test_need_read_data.out b/regression-test/data/inverted_index_p0/test_need_read_data.out index 782d5e5ab0b1b1..5999e7640ad5bc 100644 --- a/regression-test/data/inverted_index_p0/test_need_read_data.out +++ b/regression-test/data/inverted_index_p0/test_need_read_data.out @@ -31,3 +31,6 @@ -- !sql -- 1 +-- !sql_11 -- +1 + diff --git a/regression-test/suites/inverted_index_p0/test_index_rqg_bug5.groovy b/regression-test/suites/inverted_index_p0/test_index_rqg_bug5.groovy new file mode 100644 index 00000000000000..c0181b17715d3b --- /dev/null +++ b/regression-test/suites/inverted_index_p0/test_index_rqg_bug5.groovy @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_index_rqg_bug5", "test_index_rqg_bug"){ + def table = "test_index_rqg_bug5" + sql "drop table if exists ${table}" + + sql """ + create table ${table} ( + pk int, + col1 int not null, + col2 bigint not null, + INDEX col1_idx (`col1`) USING INVERTED, + INDEX col2_idx (`col2`) USING INVERTED + ) engine=olap + DUPLICATE KEY(pk, col1) + distributed by hash(pk) + properties("replication_num" = "1");; + """ + + sql """ insert into ${table} values (10, 20, 30); """ + + qt_sql """ select count() from ${table} where col2 + col1 > 20 or col1 > 20; """ +} diff --git a/regression-test/suites/inverted_index_p0/test_index_rqg_bug6.groovy b/regression-test/suites/inverted_index_p0/test_index_rqg_bug6.groovy new file mode 100644 index 00000000000000..ce8e138dfa3dd0 --- /dev/null +++ b/regression-test/suites/inverted_index_p0/test_index_rqg_bug6.groovy @@ -0,0 +1,63 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +suite("test_index_rqg_bug6", "test_index_rqg_bug"){ + def table = "test_index_rqg_bug6" + + sql "drop table if exists ${table}" + + sql """ + create table ${table} ( + pk int, + col_int_undef_signed_index_inverted int not null , + col_varchar_1024__undef_signed_not_null varchar(1024) not null, + INDEX col_int_undef_signed_index_inverted_idx (`col_int_undef_signed_index_inverted`) USING INVERTED, + INDEX col_varchar_1024__undef_signed_not_null_idx (`col_varchar_1024__undef_signed_not_null`) USING INVERTED + ) engine=olap + DUPLICATE KEY(pk) + distributed by hash(pk) buckets 1 + properties("replication_num" = "1"); + """ + + sql """ insert into ${table} values (10, 0, 'ok'), (11, 0, 'oo'), (12, 1, 'ok')""" + + + sql """ sync""" + sql """ set enable_inverted_index_query = true """ + sql """ set inverted_index_skip_threshold = 0 """ + qt_sql """ + SELECT + count() + FROM + test_index_rqg_bug6 + WHERE + IF(col_int_undef_signed_index_inverted = 0, 'true', 'false') = 'false' + AND ( + col_varchar_1024__undef_signed_not_null LIKE 'ok' + OR col_int_undef_signed_index_inverted = 0 + ); + """ + + qt_sql_2 """ + SELECT + count() + FROM + test_index_rqg_bug6 + WHERE + col_varchar_1024__undef_signed_not_null LIKE 'ok' + OR col_int_undef_signed_index_inverted = 0; + """ +} diff --git a/regression-test/suites/inverted_index_p0/test_index_rqg_bug7.groovy b/regression-test/suites/inverted_index_p0/test_index_rqg_bug7.groovy new file mode 100644 index 00000000000000..5f0e09e4d4ebd6 --- /dev/null +++ b/regression-test/suites/inverted_index_p0/test_index_rqg_bug7.groovy @@ -0,0 +1,44 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +suite("test_index_rqg_bug7", "test_index_rqg_bug"){ + def table = "test_index_rqg_bug7" + + sql "drop table if exists ${table}" + + sql """ + create table ${table} ( + pk int, + col_int_undef_signed int null , + col_int_undef_signed_not_null_index_inverted int not null , + INDEX col_int_undef_signed_not_null_index_inverted_idx (`col_int_undef_signed_not_null_index_inverted`) USING INVERTED + ) engine=olap + DUPLICATE KEY(pk) + distributed by hash(pk) buckets 10 + properties("replication_num" = "1"); + """ + + sql """ insert into ${table} values (1, 7, 7), (2, 7, -2), (3, 4, -2)""" + + + sql """ sync""" + sql """ set enable_inverted_index_query = true """ + sql """ set inverted_index_skip_threshold = 0 """ + sql """ set enable_no_need_read_data_opt = true """ + qt_sql """ + select count(*) from ${table} where col_int_undef_signed_not_null_index_inverted = -2 AND ((CASE WHEN col_int_undef_signed_not_null_index_inverted = -2 THEN 1 ELSE NULL END = 1) OR col_int_undef_signed != 7); + """ +} diff --git a/regression-test/suites/inverted_index_p0/test_need_read_data.groovy b/regression-test/suites/inverted_index_p0/test_need_read_data.groovy index 3bff37e261d649..9c80019e46ab95 100644 --- a/regression-test/suites/inverted_index_p0/test_need_read_data.groovy +++ b/regression-test/suites/inverted_index_p0/test_need_read_data.groovy @@ -138,4 +138,26 @@ suite("test_need_read_data", "p0"){ sql "INSERT INTO ${indexTblName3} VALUES (1, 1),(1, -2),(1, -1);" qt_sql "SELECT /*+SET_VAR(enable_common_expr_pushdown=false,inverted_index_skip_threshold=100) */ id FROM ${indexTblName3} WHERE value<0 and abs(value)>1;" qt_sql "SELECT /*+SET_VAR(enable_common_expr_pushdown=true,inverted_index_skip_threshold=100) */ id FROM ${indexTblName3} WHERE value<0 and abs(value)>1;" + + sql "DROP TABLE IF EXISTS tt" + sql """ + CREATE TABLE `tt` ( + `a` int NULL, + `b` varchar(20) NULL, + `c` int NULL, + INDEX idx_source (`b`) USING INVERTED, + ) ENGINE=OLAP + DUPLICATE KEY(`a`, `b`) + COMMENT 'OLAP' + DISTRIBUTED BY RANDOM BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql """ insert into tt values (20, 'aa', 30); """ + sql """ insert into tt values (20, null, 30); """ + + qt_sql_11 """ select /*+SET_VAR(enable_count_on_index_pushdown=true) */ count(b) from tt where c = 30; """ + sql """ DROP TABLE IF EXISTS tt """ + }