From 4b78186e6c4ae8b8f45d708bbfc78aaec288bf7e Mon Sep 17 00:00:00 2001 From: Sun Chenyang Date: Wed, 11 Feb 2026 14:29:06 +0800 Subject: [PATCH] [enhance](variant) add condition cache for variant type (#60532) `select count() from table where profile['id'] > 100` When `profile` is a variant type, the column name for this column is `profile.id`, which can be used to distinguish different sub-columns within the variant. This also serves as the key for the condition cache. --- be/src/vec/exprs/vslot_ref.cpp | 3 -- regression-test/data/variant_p0/multi_var.out | 36 +++++++++++++++++++ .../suites/variant_p0/multi_var.groovy | 24 ++++++++++++- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/be/src/vec/exprs/vslot_ref.cpp b/be/src/vec/exprs/vslot_ref.cpp index 173f889b0c8117..91969165422963 100644 --- a/be/src/vec/exprs/vslot_ref.cpp +++ b/be/src/vec/exprs/vslot_ref.cpp @@ -138,9 +138,6 @@ bool VSlotRef::equals(const VExpr& other) { } uint64_t VSlotRef::get_digest(uint64_t seed) const { - if (_data_type->get_primitive_type() == TYPE_VARIANT) { - return 0; - } seed = HashUtil::hash64(&_column_uniq_id, sizeof(int), seed); return HashUtil::hash64(_column_name->c_str(), _column_name->size(), seed); } diff --git a/regression-test/data/variant_p0/multi_var.out b/regression-test/data/variant_p0/multi_var.out index 18e31a4a5a5761..70033d66399ffd 100644 --- a/regression-test/data/variant_p0/multi_var.out +++ b/regression-test/data/variant_p0/multi_var.out @@ -35,3 +35,39 @@ \N \N \N 123 \N \N \N \N \N 123 elden ring \N +-- !sql_condition_cache1 -- +600 + +-- !sql_condition_cache2 -- +600 + +-- !sql_condition_cache3 -- +700 + +-- !sql_condition_cache4 -- +700 + +-- !sql_condition_cache5 -- +600 + +-- !sql_condition_cache6 -- +600 + +-- !sql_condition_cache7 -- +700 + +-- !sql_condition_cache8 -- +700 + +-- !sql_condition_cache9 -- +0 + +-- !sql_condition_cache10 -- +0 + +-- !sql_condition_cache11 -- +700 + +-- !sql_condition_cache12 -- +700 + diff --git a/regression-test/suites/variant_p0/multi_var.groovy b/regression-test/suites/variant_p0/multi_var.groovy index 91d5810a670001..ef56aa68daed38 100644 --- a/regression-test/suites/variant_p0/multi_var.groovy +++ b/regression-test/suites/variant_p0/multi_var.groovy @@ -25,7 +25,7 @@ suite("regression_test_variant_multi_var", "variant_type"){ ) DUPLICATE KEY(`k`) DISTRIBUTED BY HASH(k) BUCKETS 4 - properties("replication_num" = "1"); + properties("replication_num" = "1", "disable_auto_compaction" = "true"); """ sql """INSERT INTO ${table_name} SELECT *, '{"k1":1, "k2": "hello world", "k3" : [1234], "k4" : 1.10000, "k5" : [[123]]}' FROM numbers("number" = "101")""" sql """INSERT INTO ${table_name} SELECT *, '{"k7":123, "k8": "elden ring", "k9" : 1.1112, "k10" : [1.12], "k11" : ["moon"]}' FROM numbers("number" = "203") where number > 100""" @@ -45,4 +45,26 @@ suite("regression_test_variant_multi_var", "variant_type"){ for (int i = 0; i < 20; i++) { sql """insert into ${table_name} values (1, '{"a" : 1}', '{"a" : 1}', '{"a" : 1}', '{"a" : 1}', '{"a" : 1}')""" } + + trigger_and_wait_compaction(table_name, "full") + + sql "set enable_condition_cache = true" + sql "set enable_sql_cache = false" + qt_sql_condition_cache1 """select count() from ${table_name} where cast(v3['k1'] as bigint) = 1 and cast(v2['k2'] as string) = 'hello world' """ + qt_sql_condition_cache2 """select count() from ${table_name} where cast(v3['k1'] as bigint) = 1 and cast(v2['k2'] as string) = 'hello world' """ + + qt_sql_condition_cache3 """select count() from ${table_name} where cast(v3['k1'] as bigint) = 1 or cast(v2['k2'] as string) = 'hello world' """ + qt_sql_condition_cache4 """select count() from ${table_name} where cast(v3['k1'] as bigint) = 1 or cast(v2['k2'] as string) = 'hello world' """ + + qt_sql_condition_cache5 """select count() from ${table_name} where cast(v3['k1'] as bigint) = 1 and cast(v3['k2'] as string) = 'hello world' """ + qt_sql_condition_cache6 """select count() from ${table_name} where cast(v3['k1'] as bigint) = 1 and cast(v3['k2'] as string) = 'hello world' """ + + qt_sql_condition_cache7 """select count() from ${table_name} where cast(v2['k1'] as bigint) = 1 or cast(v2['k2'] as string) = 'hello world' """ + qt_sql_condition_cache8 """select count() from ${table_name} where cast(v2['k1'] as bigint) = 1 or cast(v2['k2'] as string) = 'hello world' """ + + qt_sql_condition_cache9 """select count() from ${table_name} where cast(v2['k2'] as string) = 'hello world' and array_contains(cast(v3['k11'] as array), 'moon') """ + qt_sql_condition_cache10 """select count() from ${table_name} where cast(v2['k2'] as string) = 'hello world' and array_contains(cast(v3['k11'] as array), 'moon') """ + + qt_sql_condition_cache11 """select count() from ${table_name} where cast(v2['k1'] as bigint) = 1 or cast(v2['k1'] as double) < 2.0 """ + qt_sql_condition_cache12 """select count() from ${table_name} where cast(v2['k1'] as bigint) = 1 or cast(v2['k1'] as double) < 2.0 """ } \ No newline at end of file