This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 8dd6ce3adcd branch-4.2: [fix](be) Skip condition cache for complex
object literals (#71053)
8dd6ce3adcd is described below
commit 8dd6ce3adcd9c2afd44ee43b77fd69534973d8b0
Author: linrrarity <[email protected]>
AuthorDate: Wed Dec 2 10:54:51 2026 +0800
branch-4.2: [fix](be) Skip condition cache for complex object literals
(#71053)
pick: https://github.com/apache/doris/pull/68930
Check literal columns before sharing them with scanners using the 4.2
subcolumn visitor.
Co-authored-by: HappenLee <[email protected]>
---
be/src/exprs/varray_literal.cpp | 2 +-
be/src/exprs/vliteral.cpp | 42 ++++++
be/src/exprs/vliteral.h | 11 +-
be/src/exprs/vmap_literal.cpp | 2 +-
be/src/exprs/vstruct_literal.cpp | 2 +-
be/test/exprs/vliteral_digest_test.cpp | 159 +++++++++++++++++++++
be/test/format_v2/orc/orc_reader_test.cpp | 2 +-
be/test/testutil/mock/mock_literal_expr.h | 2 +-
.../test_condition_cache_complex_literal.groovy | 74 ++++++++++
9 files changed, 288 insertions(+), 8 deletions(-)
diff --git a/be/src/exprs/varray_literal.cpp b/be/src/exprs/varray_literal.cpp
index 500bf19de0e..5648a769cce 100644
--- a/be/src/exprs/varray_literal.cpp
+++ b/be/src/exprs/varray_literal.cpp
@@ -48,7 +48,7 @@ Status VArrayLiteral::prepare(RuntimeState* state, const
RowDescriptor& row_desc
child_literal->get_column_ptr()->get(0, item);
array.get<TYPE_ARRAY>().push_back(item);
}
- _column_ptr = _data_type->create_column_const(1, array);
+ init_column(array);
return Status::OK();
}
diff --git a/be/src/exprs/vliteral.cpp b/be/src/exprs/vliteral.cpp
index 6f2f178b711..2cdb8b4bbb4 100644
--- a/be/src/exprs/vliteral.cpp
+++ b/be/src/exprs/vliteral.cpp
@@ -28,6 +28,10 @@
#include "core/block/block.h"
#include "core/column/column.h"
+#include "core/column/column_complex.h"
+#include "core/column/column_const.h"
+#include "core/column/column_fixed_length_object.h"
+#include "core/column/column_varbinary.h"
#include "core/data_type/data_type_decimal.h"
#include "core/field.h"
#include "core/types.h"
@@ -36,6 +40,39 @@
namespace doris {
#include "common/compile_check_begin.h"
+namespace {
+
+bool supports_literal_digest(IColumn& column) {
+ // These concrete columns inherit IColumn's throwing xxHash implementation.
+ // Inspect the column rather than the SQL type: AGG_STATE can use either a
+ // hashable string column or an unsupported fixed-length object column.
+ if (is_column<ColumnBitmap>(column) || is_column<ColumnHLL>(column) ||
+ is_column<ColumnQuantileState>(column) ||
is_column<ColumnVarbinary>(column) ||
+ is_column<ColumnFixedLengthObject>(column)) {
+ return false;
+ }
+
+ bool supported = true;
+ column.for_each_subcolumn([&](IColumn::WrappedPtr& child) {
+ supported = supported && supports_literal_digest(*child);
+ });
+ return supported;
+}
+
+} // namespace
+
+void VLiteral::init_column(const Field& field) {
+ auto column = _data_type->create_column();
+ column->insert(field);
+ set_column(ColumnConst::create(std::move(column), 1));
+}
+
+void VLiteral::set_column(MutableColumnPtr column) {
+ // The 4.2 subcolumn visitor temporarily moves child pointers. Traverse
before sharing.
+ _supports_digest = supports_literal_digest(*column);
+ _column_ptr = std::move(column);
+}
+
class VExprContext;
Status VLiteral::prepare(RuntimeState* state, const RowDescriptor& desc,
VExprContext* context) {
@@ -101,6 +138,11 @@ bool VLiteral::equals(const VExpr& other) {
}
uint64_t VLiteral::get_digest(uint64_t seed) const {
+ // Wrappers and containers delegate hashing to their nested columns. A zero
+ // digest disables the condition cache without changing the column hash
contract.
+ if (!_supports_digest) {
+ return 0;
+ }
_column_ptr->update_xxHash_with_value(0, 1, seed, nullptr);
return seed;
}
diff --git a/be/src/exprs/vliteral.h b/be/src/exprs/vliteral.h
index 89988e2ba31..edba5e5766f 100644
--- a/be/src/exprs/vliteral.h
+++ b/be/src/exprs/vliteral.h
@@ -42,13 +42,13 @@ public:
if (should_init) {
Field field;
field = _data_type->get_field(node);
- _column_ptr = _data_type->create_column_const(1, field);
+ init_column(field);
}
}
VLiteral(const DataTypePtr& type, const Field& field) : VExpr(type, false)
{
_data_type = type;
- _column_ptr = _data_type->create_column_const(1, field);
+ init_column(field);
_node_type = TExprNodeType::LITERAL;
_expr_name = _data_type->get_name();
}
@@ -87,8 +87,13 @@ public:
protected:
VLiteral(const DataTypePtr& type) : VExpr(type, false) {}
- ColumnPtr _column_ptr;
+ void init_column(const Field& field);
+ void set_column(MutableColumnPtr column);
std::string _expr_name;
+
+private:
+ ColumnPtr _column_ptr;
+ bool _supports_digest = false;
};
} // namespace doris
diff --git a/be/src/exprs/vmap_literal.cpp b/be/src/exprs/vmap_literal.cpp
index 0425e433cf2..8f606bab508 100644
--- a/be/src/exprs/vmap_literal.cpp
+++ b/be/src/exprs/vmap_literal.cpp
@@ -59,7 +59,7 @@ Status VMapLiteral::prepare(RuntimeState* state, const
RowDescriptor& row_desc,
map.get<TYPE_MAP>().push_back(keys);
map.get<TYPE_MAP>().push_back(values);
- _column_ptr = _data_type->create_column_const(1, map);
+ init_column(map);
return Status::OK();
}
diff --git a/be/src/exprs/vstruct_literal.cpp b/be/src/exprs/vstruct_literal.cpp
index 05f9a09aeb7..7c3bbfef5c1 100644
--- a/be/src/exprs/vstruct_literal.cpp
+++ b/be/src/exprs/vstruct_literal.cpp
@@ -43,7 +43,7 @@ Status VStructLiteral::prepare(RuntimeState* state, const
RowDescriptor& row_des
child_literal->get_column_ptr()->get(0, item);
struct_field.get<TYPE_STRUCT>().push_back(item);
}
- _column_ptr = _data_type->create_column_const(1, struct_field);
+ init_column(struct_field);
return Status::OK();
}
diff --git a/be/test/exprs/vliteral_digest_test.cpp
b/be/test/exprs/vliteral_digest_test.cpp
new file mode 100644
index 00000000000..d520cbf23aa
--- /dev/null
+++ b/be/test/exprs/vliteral_digest_test.cpp
@@ -0,0 +1,159 @@
+// 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.
+
+#include <gtest/gtest.h>
+
+#include <utility>
+#include <vector>
+
+#include "agent/be_exec_version_manager.h"
+#include "core/data_type/data_type_agg_state.h"
+#include "core/data_type/data_type_array.h"
+#include "core/data_type/data_type_factory.hpp"
+#include "core/data_type/data_type_map.h"
+#include "core/data_type/data_type_nullable.h"
+#include "core/data_type/data_type_number.h"
+#include "core/data_type/data_type_string.h"
+#include "core/data_type/data_type_struct.h"
+#include "exprs/vliteral.h"
+#include "testutil/mock/mock_fn_call.h"
+
+namespace doris {
+
+TEST(VLiteralDigestTest, ComplexNullDisablesParentDigest) {
+ for (auto type : {TYPE_BITMAP, TYPE_HLL, TYPE_QUANTILE_STATE,
TYPE_VARBINARY}) {
+ SCOPED_TRACE(type_to_string(type));
+ auto data_type = DataTypeFactory::instance().create_data_type(type,
true);
+ auto literal = VLiteral::create_shared(data_type, Field());
+ EXPECT_EQ(literal->get_digest(42), 0);
+
+ // A later scalar child must not revive a digest disabled by the
complex literal.
+ auto parent = MockFnCall::create("if");
+ parent->add_child(literal);
+
parent->add_child(VLiteral::create_shared(std::make_shared<DataTypeInt32>(),
+
Field::create_field<TYPE_INT>(1)));
+ EXPECT_EQ(parent->get_digest(42), 0);
+ }
+}
+
+TEST(VLiteralDigestTest, NonNullComplexValuesDisableDigest) {
+ auto bitmap = VLiteral::create_shared(
+ DataTypeFactory::instance().create_data_type(TYPE_BITMAP, false),
+ Field::create_field<TYPE_BITMAP>(BitmapValue(1)));
+ auto hll =
+
VLiteral::create_shared(DataTypeFactory::instance().create_data_type(TYPE_HLL,
false),
+
Field::create_field<TYPE_HLL>(HyperLogLog()));
+ auto quantile = VLiteral::create_shared(
+ DataTypeFactory::instance().create_data_type(TYPE_QUANTILE_STATE,
false),
+ Field::create_field<TYPE_QUANTILE_STATE>(QuantileState()));
+ EXPECT_EQ(bitmap->get_digest(42), 0);
+ EXPECT_EQ(hll->get_digest(42), 0);
+ EXPECT_EQ(quantile->get_digest(42), 0);
+
+ auto binary = VLiteral::create_shared(
+ DataTypeFactory::instance().create_data_type(TYPE_VARBINARY,
false),
+ Field::create_field<TYPE_VARBINARY>(StringView("a", 1)));
+ EXPECT_EQ(binary->get_digest(42), 0);
+}
+
+TEST(VLiteralDigestTest, NestedUnsupportedColumnsDisableDigest) {
+ auto bitmap_type =
DataTypeFactory::instance().create_data_type(TYPE_BITMAP, true);
+ auto int_type = std::make_shared<DataTypeInt32>();
+ auto array_type = std::make_shared<DataTypeArray>(bitmap_type);
+ auto array = Field::create_field<TYPE_ARRAY>(
+ Array {Field::create_field<TYPE_BITMAP>(BitmapValue(1)), Field()});
+ auto nested_array_type = std::make_shared<DataTypeArray>(array_type);
+ auto nested_array = Field::create_field<TYPE_ARRAY>(Array {array});
+ auto map_type = std::make_shared<DataTypeMap>(int_type, array_type);
+ auto map = Field::create_field<TYPE_MAP>(
+ Map {Field::create_field<TYPE_ARRAY>(Array
{Field::create_field<TYPE_INT>(1)}),
+ Field::create_field<TYPE_ARRAY>(Array {array})});
+ auto struct_type = std::make_shared<DataTypeStruct>(DataTypes {int_type,
map_type});
+ auto structure =
+ Field::create_field<TYPE_STRUCT>(Struct
{Field::create_field<TYPE_INT>(1), map});
+
+ for (const auto& [type, value] :
+ std::vector<std::pair<DataTypePtr, Field>> {{array_type, array},
+ {nested_array_type,
nested_array},
+ {map_type, map},
+ {struct_type, structure},
+
{make_nullable(array_type), Field()}}) {
+ SCOPED_TRACE(type->get_name());
+ auto literal = VLiteral::create_shared(type, value);
+ EXPECT_EQ(literal->get_digest(42), 0);
+ }
+}
+
+TEST(VLiteralDigestTest, AggStateDigestUsesSerializedColumn) {
+ const auto version = BeExecVersionManager::get_newest_version();
+ auto sum_type = std::make_shared<DataTypeAggState>(
+ DataTypes {std::make_shared<DataTypeInt32>()}, false, "sum",
version);
+ auto sum_null = VLiteral::create_shared(make_nullable(sum_type), Field());
+ EXPECT_EQ(sum_null->get_digest(42), 0);
+
+ // HLL aggregate states serialize as ColumnString, unlike direct HLL
literals.
+ auto hll_type = DataTypeFactory::instance().create_data_type(TYPE_HLL,
false);
+ auto hll_state_type =
+ std::make_shared<DataTypeAggState>(DataTypes {hll_type}, false,
"hll_union", version);
+ auto hll_state_null =
VLiteral::create_shared(make_nullable(hll_state_type), Field());
+ EXPECT_NE(hll_state_null->get_digest(42), 0);
+ EXPECT_EQ(hll_state_null->get_digest(42), hll_state_null->get_digest(42));
+}
+
+TEST(VLiteralDigestTest, SupportedContainersKeepDistinctDigests) {
+ auto int_type = std::make_shared<DataTypeInt32>();
+ auto array_type = std::make_shared<DataTypeArray>(int_type);
+ auto one = Field::create_field<TYPE_INT>(1);
+ auto two = Field::create_field<TYPE_INT>(2);
+ auto first = VLiteral::create_shared(array_type,
Field::create_field<TYPE_ARRAY>(Array {one}));
+ auto second = VLiteral::create_shared(array_type,
Field::create_field<TYPE_ARRAY>(Array {two}));
+ EXPECT_NE(first->get_digest(42), 0);
+ EXPECT_NE(first->get_digest(42), second->get_digest(42));
+ EXPECT_EQ(first->get_digest(42), first->get_digest(42));
+
+ auto map_type = std::make_shared<DataTypeMap>(int_type, int_type);
+ auto map = Field::create_field<TYPE_MAP>(Map
{Field::create_field<TYPE_ARRAY>(Array {one}),
+
Field::create_field<TYPE_ARRAY>(Array {two})});
+ auto map_literal = VLiteral::create_shared(map_type, map);
+ EXPECT_NE(map_literal->get_digest(42), 0);
+ auto struct_type = std::make_shared<DataTypeStruct>(DataTypes {int_type,
map_type});
+ auto struct_literal = VLiteral::create_shared(
+ struct_type, Field::create_field<TYPE_STRUCT>(Struct {one, map}));
+ EXPECT_NE(struct_literal->get_digest(42), 0);
+}
+
+TEST(VLiteralDigestTest, ScalarValuesKeepDistinctStableDigests) {
+ auto int_type = std::make_shared<DataTypeInt32>();
+ auto one = VLiteral::create_shared(int_type,
Field::create_field<TYPE_INT>(1));
+ auto two = VLiteral::create_shared(int_type,
Field::create_field<TYPE_INT>(2));
+ EXPECT_NE(one->get_digest(42), 0);
+ EXPECT_EQ(one->get_digest(42), one->get_digest(42));
+ EXPECT_NE(one->get_digest(42), two->get_digest(42));
+ EXPECT_NE(one->get_digest(42), one->get_digest(43));
+
+ auto string_type = std::make_shared<DataTypeString>();
+ auto a = VLiteral::create_shared(string_type,
Field::create_field<TYPE_STRING>(String("a")));
+ auto b = VLiteral::create_shared(string_type,
Field::create_field<TYPE_STRING>(String("b")));
+ EXPECT_NE(a->get_digest(42), 0);
+ EXPECT_NE(a->get_digest(42), b->get_digest(42));
+
+ auto scalar_null = VLiteral::create_shared(
+ DataTypeFactory::instance().create_data_type(TYPE_INT, true),
Field());
+ EXPECT_NE(scalar_null->get_digest(42), 0);
+}
+
+} // namespace doris
diff --git a/be/test/format_v2/orc/orc_reader_test.cpp
b/be/test/format_v2/orc/orc_reader_test.cpp
index 515081ce73c..9668000c60b 100644
--- a/be/test/format_v2/orc/orc_reader_test.cpp
+++ b/be/test/format_v2/orc/orc_reader_test.cpp
@@ -194,7 +194,7 @@ public:
TableLiteral(const DataTypePtr& type, const Field& field) : VLiteral(type)
{
_node_type = node_type_for_field(field);
_data_type = type;
- _column_ptr = _data_type->create_column_const(1, field);
+ init_column(field);
_expr_name = _data_type->get_name();
}
diff --git a/be/test/testutil/mock/mock_literal_expr.h
b/be/test/testutil/mock/mock_literal_expr.h
index 566dc51bf94..91a90ba7d98 100644
--- a/be/test/testutil/mock/mock_literal_expr.h
+++ b/be/test/testutil/mock/mock_literal_expr.h
@@ -40,7 +40,7 @@ class MockLiteral final : public VLiteral {
public:
MockLiteral(ColumnWithTypeAndName data) {
_data_type = data.type;
- _column_ptr = data.column;
+ set_column(IColumn::mutate(data.column));
_expr_name = data.name;
if (!check_and_get_column<ColumnConst>(data.column.get())) {
_mock_const_expr_col =
diff --git
a/regression-test/suites/query_p0/condition_cache/test_condition_cache_complex_literal.groovy
b/regression-test/suites/query_p0/condition_cache/test_condition_cache_complex_literal.groovy
new file mode 100644
index 00000000000..269adb82cc0
--- /dev/null
+++
b/regression-test/suites/query_p0/condition_cache/test_condition_cache_complex_literal.groovy
@@ -0,0 +1,74 @@
+// 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_condition_cache_complex_literal") {
+ sql "set enable_sql_cache=false"
+ sql "drop table if exists condition_cache_complex_literal"
+ sql """
+ create table condition_cache_complex_literal (id int)
+ duplicate key(id)
+ distributed by hash(id) buckets 1
+ properties("replication_num"="1")
+ """
+ sql "insert into condition_cache_complex_literal values (1), (2)"
+
+ def queries = [
+ """
+ select id from condition_cache_complex_literal
+ where bitmap_count(if(id=1, to_bitmap(1), cast(null as bitmap))) > 0
+ order by id
+ """,
+ """
+ select id from condition_cache_complex_literal
+ where bitmap_count(case when id=1 then to_bitmap(1)
+ else cast(null as bitmap) end) > 0
+ order by id
+ """,
+ """
+ select id from condition_cache_complex_literal
+ where md5sum(X'61', to_binary(cast(id as string))) <> ''
+ order by id
+ """,
+ // FE folds this array into a literal, while the row-dependent index
+ // keeps it in the scan predicate. Even its NULL bitmap element lacks
xxHash.
+ """
+ select id from condition_cache_complex_literal
+ where bitmap_count(element_at(array(cast(null as bitmap)), id)) = 0
+ order by id
+ """,
+ """
+ select id from condition_cache_complex_literal
+ where element_at(array(1, 2), id) = id
+ order by id
+ """,
+ """
+ select id, bitmap_count(if(id=1, to_bitmap(1), cast(null as
bitmap)))
+ from condition_cache_complex_literal order by id
+ """
+ ]
+
+ // Compare each query with uncached execution to verify that cache
transitions
+ // and repeated enabled execution preserve the row results.
+ sql "set enable_condition_cache=false"
+ def uncachedResults = queries.collect { query -> sql(query) }
+ for (boolean enabled : [true, true, false, true]) {
+ sql "set enable_condition_cache=${enabled}"
+ queries.eachWithIndex { query, index ->
+ assertEquals(uncachedResults[index], sql(query))
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]