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 5ea463f7fbe branch-4.2: [fix](query) Preserve session settings in
point queries and BE constant folding #70941 (#71240)
5ea463f7fbe is described below
commit 5ea463f7fbeb930c4b6b0ad238a7d688ee20a0c9
Author: Jerry Hu <[email protected]>
AuthorDate: Fri Dec 4 09:54:48 2026 +0800
branch-4.2: [fix](query) Preserve session settings in point queries and BE
constant folding #70941 (#71240)
### What problem does this PR solve?
Issue Number: None
Related PR: #70941
Backport #70941 to `branch-4.2`.
Problem Summary:
Point lookups and BE constant folding do not consistently receive the
session settings used by normal execution. Prepared point queries can
also reuse locale-dependent folded literals or opened expression
contexts after `lc_time_names` changes. In addition, `DAYNAME` and
`MONTHNAME` allocate output using English name lengths, which can be too
small for localized UTF-8 names.
### Changes
- Send `lc_time_names` on point-lookup requests, including lightweight
requests. Forward the session locale and `enable_hyperscan_fallback` to
BE constant folding.
- Capture the planning locale in the FE short-circuit context and
invalidate the cached plan when it changes, so folded literals are
regenerated.
- Initialize BE timezone and locale before opening expressions. Reuse a
cached context only when both settings match; otherwise rebuild it
without changing contexts retained by in-flight requests. Keep the
existing lightweight context-resend path.
- Size date-name output using the active locale's maximum UTF-8 byte
length instead of the English bound.
- Add the optional protobuf field `lc_time_names = 10` without changing
existing field numbers.
### Branch-specific adaptation
Preserve `branch-4.2`'s effective-session constructor,
descriptor/access-path validation, and scalar-slot/literal projection
restrictions. This backport does not enable complex or non-slot
projections in the short-circuit path.
The prepared-query regression uses scalar slots plus a BE-folded
date-name literal and checks that the plan is short-circuit. Array and
row-dependent date-name projections retain the normal-path fallback.
Adapt the unit tests to Java 8 and the legacy mock runtime state; use
text-protocol EXPLAIN while keeping the actual SELECT server-prepared.
### Testing
Local validation for the unchanged patch:
- `./build.sh --be --fe -j 32`: passed (BE Release build and FE
packaging).
- Focused FE tests (`ShortCircuitQueryContextTest`,
`SessionContextRequestTest`, `ExecuteCommandTest`): **23 passed**, no
failures, errors, or skips.
- `./run-be-ut.sh --run
--filter='VTimestampFunctionsTest.*:FoldConstantExecutorTest.*:LookupConnectionCacheTest.*:PointQueryReusableTest.*'
-j 32`: **97 passed** under ASAN.
- SQL regression suites: **3 passed**, no failed, fatal, or skipped
suites:
- `test_point_query_lc_time_names`
- `test_point_query_date_name_capacity`
- `test_be_fold_session_context`
- Expected output regenerated by the regression runner and checked by a
separate comparison run.
- clang-format 16, FE Checkstyle (zero violations), and `git diff
--check`: passed.
SQL validation used an isolated local FE/BE configuration with BE Java
support disabled. Remote CI and formal cloud/mixed-version validation
have not been run.
### Release note
Fix session-setting consistency in point queries and BE constant
folding, refresh prepared point queries after locale changes, and
prevent undersized buffers for localized date names.
### Check List (For Author)
- Test
- [x] Regression test
- [x] Unit Test
- Behavior changed:
- [x] Yes. Optimized execution honors the applicable session settings,
locale changes refresh cached contexts, and localized date-name output
uses sufficient capacity.
- Does this need documentation?
- [x] No.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
---
.../function_date_or_datetime_to_string.cpp | 20 ++-
be/src/runtime/runtime_state.h | 1 +
be/src/service/point_query_executor.cpp | 29 +++-
be/src/service/point_query_executor.h | 6 +-
be/test/exprs/function/function_time_test.cpp | 90 +++++++++++
be/test/runtime/fold_constant_executor_test.cpp | 43 ++++++
be/test/service/point_query_exector_test.cpp | 57 +++++--
be/test/testutil/function_utils.cpp | 2 +
.../expression/rules/FoldConstantRuleOnBE.java | 2 +
.../org/apache/doris/qe/PointQueryExecutor.java | 1 +
.../apache/doris/qe/ShortCircuitQueryContext.java | 8 +-
.../apache/doris/qe/SessionContextRequestTest.java | 165 +++++++++++++++++++++
.../doris/qe/ShortCircuitQueryContextTest.java | 22 ++-
gensrc/proto/internal_service.proto | 2 +
.../fold_constant/test_be_fold_session_context.out | 18 +++
.../test_point_query_date_name_capacity.out | 132 +++++++++++++++++
.../test_point_query_lc_time_names.out | 48 ++++++
.../test_be_fold_session_context.groovy | 59 ++++++++
.../test_point_query_date_name_capacity.groovy | 82 ++++++++++
.../test_point_query_lc_time_names.groovy | 83 +++++++++++
20 files changed, 841 insertions(+), 29 deletions(-)
diff --git a/be/src/exprs/function/function_date_or_datetime_to_string.cpp
b/be/src/exprs/function/function_date_or_datetime_to_string.cpp
index 3b259d504b5..db243b0978b 100644
--- a/be/src/exprs/function/function_date_or_datetime_to_string.cpp
+++ b/be/src/exprs/function/function_date_or_datetime_to_string.cpp
@@ -22,6 +22,7 @@
#include <unicode/locid.h>
#include <unicode/unistr.h>
+#include <algorithm>
#include <cstddef>
#include <memory>
#include <utility>
@@ -87,6 +88,8 @@ public:
std::string locale_name;
std::vector<std::string> day_name_storage {7};
std::vector<std::string> month_name_storage {13};
+ size_t max_day_name_bytes = 0;
+ size_t max_month_name_bytes = 0;
const char* day_names[7];
const char* month_names[13];
};
@@ -98,9 +101,6 @@ public:
auto state = std::make_shared<LocaleDayMonthNameState>();
state->locale_name = context->state()->lc_time_names();
-#ifdef BE_TEST
- state->locale_name = "en_US";
-#endif
UErrorCode status = U_ZERO_ERROR;
icu::Locale locale(state->locale_name.c_str());
icu::DateFormatSymbols symbols(locale, status);
@@ -119,6 +119,8 @@ public:
}
for (int i = 0; i < MONTH_NUM_IN_ICU; ++i) {
months[i].toUTF8String(state->month_name_storage[i + 1]);
+ state->max_month_name_bytes =
+ std::max(state->max_month_name_bytes,
state->month_name_storage[i + 1].size());
state->month_names[i + 1] = state->month_name_storage[i +
1].c_str();
}
@@ -127,9 +129,13 @@ public:
for (int i = 1; i < DAY_NUM_IN_ICU; ++i) {
if (i == 1) {
days[i].toUTF8String(state->day_name_storage[6]);
+ state->max_day_name_bytes =
+ std::max(state->max_day_name_bytes,
state->day_name_storage[6].size());
state->day_names[6] = state->day_name_storage[6].c_str();
} else {
days[i].toUTF8String(state->day_name_storage[i - 2]);
+ state->max_day_name_bytes =
+ std::max(state->max_day_name_bytes,
state->day_name_storage[i - 2].size());
state->day_names[i - 2] = state->day_name_storage[i -
2].c_str();
}
}
@@ -181,19 +187,25 @@ private:
ColumnString::Chars& res_data, ColumnString::Offsets&
res_offsets,
const NullMap* null_map = nullptr) {
const auto len = ts.size();
- res_data.resize(len * Transform::max_size);
res_offsets.resize(len);
size_t offset = 0;
auto* state = reinterpret_cast<LocaleDayMonthNameState*>(
context->get_function_state(FunctionContext::FRAGMENT_LOCAL));
+ size_t max_bytes = Transform::max_size;
const char* const* names_ptr = nullptr;
if constexpr (std::is_same_v<Transform,
DayNameImpl<Transform::OpArgType>>) {
names_ptr = state->day_names;
+ max_bytes = state->max_day_name_bytes;
} else if constexpr (std::is_same_v<Transform,
MonthNameImpl<Transform::OpArgType>>) {
names_ptr = state->month_names;
+ max_bytes = state->max_month_name_bytes;
}
+ // Localized names can exceed the English byte bound (e.g. ru_RU
Sunday is 22 bytes).
+ // Allocate the locale-specific UTF-8 bound before any transform
writes into the buffer.
+ res_data.resize(len * max_bytes);
+
for (size_t i = 0; i < len; ++i) {
if (null_map && (*null_map)[i]) {
res_offsets[i] = cast_set<UInt32>(offset);
diff --git a/be/src/runtime/runtime_state.h b/be/src/runtime/runtime_state.h
index 190b25137e0..1981a4f1aa6 100644
--- a/be/src/runtime/runtime_state.h
+++ b/be/src/runtime/runtime_state.h
@@ -218,6 +218,7 @@ public:
TimezoneUtils::find_cctz_time_zone(_timezone, _timezone_obj);
}
const std::string& lc_time_names() const { return _lc_time_names; }
+ void set_lc_time_names(const std::string& lc_time_names) { _lc_time_names
= lc_time_names; }
const std::string& user() const { return _user; }
const TUniqueId& query_id() const { return _query_id; }
const TUniqueId& fragment_instance_id() const { return
_fragment_instance_id; }
diff --git a/be/src/service/point_query_executor.cpp
b/be/src/service/point_query_executor.cpp
index c8550c45156..9b16523a82c 100644
--- a/be/src/service/point_query_executor.cpp
+++ b/be/src/service/point_query_executor.cpp
@@ -65,6 +65,7 @@
#include "util/simd/bits.h"
#include "util/thrift_util.h"
#include "util/time.h"
+#include "util/timezone_utils.h"
namespace doris {
@@ -133,10 +134,14 @@ static void extract_slot_ref(const VExprSPtr& expr,
TupleDescriptor* tuple_desc,
}
Status Reusable::init(const TDescriptorTable& t_desc_tbl, const
std::vector<TExpr>& output_exprs,
- const TQueryOptions& query_options, const TabletSchema&
schema,
+ const TQueryOptions& query_options, const std::string&
timezone,
+ const std::string& lc_time_names, const TabletSchema&
schema,
size_t block_size) {
_runtime_state = RuntimeState::create_unique();
_runtime_state->set_query_options(query_options);
+ // Expressions capture timezone and locale during open.
+ _runtime_state->set_timezone(timezone);
+ _runtime_state->set_lc_time_names(lc_time_names);
RETURN_IF_ERROR(DescriptorTbl::create(_runtime_state->obj_pool(),
t_desc_tbl, &_desc_tbl));
_runtime_state->set_desc_tbl(_desc_tbl);
// Point queries decode full row-store values and do not interpret access
paths.
@@ -312,6 +317,12 @@ void
PointQueryExecutor::_init_remote_scan_cache_write_limiter() {
}
}
+bool Reusable::matches_timezone_and_locale(const std::string& timezone,
+ const std::string& lc_time_names)
const {
+ return _runtime_state->timezone() == timezone &&
+ _runtime_state->lc_time_names() == lc_time_names;
+}
+
Status PointQueryExecutor::init(const PTabletKeyLookupRequest* request,
PTabletKeyLookupResponse* response) {
SCOPED_TIMER(&_profile_metrics.init_ns);
@@ -321,9 +332,17 @@ Status PointQueryExecutor::init(const
PTabletKeyLookupRequest* request,
static_cast<__int128_t>(request->uuid().uuid_high()) << 64 |
request->uuid().uuid_low();
SCOPED_ATTACH_TASK(ExecEnv::GetInstance()->point_query_executor_mem_tracker());
auto cache_handle = LookupConnectionCache::instance()->get(uuid);
+ const auto& timezone = request->has_time_zone() &&
!request->time_zone().empty()
+ ? request->time_zone()
+ : TimezoneUtils::default_time_zone;
+ const auto& lc_time_names = request->lc_time_names();
_binary_row_format = request->is_binary_row();
_tablet = DORIS_TRY(ExecEnv::get_tablet(request->tablet_id()));
- if (cache_handle != nullptr) {
+ // SET time_zone or lc_time_names can reuse the same prepared UUID, but
expressions
+ // capture these settings at open (e.g. monthname changes from zh_CN to
en_US).
+ // Rebuild on changes; existing requests retain their original contexts.
+ if (cache_handle != nullptr &&
+ cache_handle->matches_timezone_and_locale(timezone, lc_time_names)) {
_reusable = cache_handle;
_profile_metrics.hit_lookup_cache = true;
} else {
@@ -367,7 +386,7 @@ Status PointQueryExecutor::init(const
PTabletKeyLookupRequest* request,
&t_query_options));
}
RETURN_IF_ERROR(reusable_ptr->init(t_desc_tbl, t_output_exprs.exprs,
t_query_options,
- *_tablet->tablet_schema(), 1));
+ timezone, lc_time_names,
*_tablet->tablet_schema(), 1));
if (uuid != 0) {
LookupConnectionCache::instance()->add(uuid, reusable_ptr);
}
@@ -378,10 +397,6 @@ Status PointQueryExecutor::init(const
PTabletKeyLookupRequest* request,
_tablet->tablet_schema()->variant_escape_dots_in_keys(),
slot->type()));
}
_init_remote_scan_cache_write_limiter();
- // Set timezone from request for functions like from_unixtime()
- if (request->has_time_zone() && !request->time_zone().empty()) {
- _reusable->runtime_state()->set_timezone(request->time_zone());
- }
if (request->has_version() && request->version() >= 0) {
_version = request->version();
}
diff --git a/be/src/service/point_query_executor.h
b/be/src/service/point_query_executor.h
index 996c4cdcdfa..44851e39301 100644
--- a/be/src/service/point_query_executor.h
+++ b/be/src/service/point_query_executor.h
@@ -72,9 +72,13 @@ public:
}
Status init(const TDescriptorTable& t_desc_tbl, const std::vector<TExpr>&
output_exprs,
- const TQueryOptions& query_options, const TabletSchema& schema,
+ const TQueryOptions& query_options, const std::string&
timezone,
+ const std::string& lc_time_names, const TabletSchema& schema,
size_t block_size = 1);
+ bool matches_timezone_and_locale(const std::string& timezone,
+ const std::string& lc_time_names) const;
+
std::unique_ptr<Block> get_block();
const DataTypeSerDeSPtrs& get_data_type_serdes() const { return
_data_type_serdes; }
diff --git a/be/test/exprs/function/function_time_test.cpp
b/be/test/exprs/function/function_time_test.cpp
index fc3819bfa4d..7a5857f2793 100644
--- a/be/test/exprs/function/function_time_test.cpp
+++ b/be/test/exprs/function/function_time_test.cpp
@@ -17,13 +17,19 @@
#include <gtest/gtest.h>
+#include <array>
#include <limits>
#include <string>
+#include "core/column/column_const.h"
+#include "core/column/column_nullable.h"
+#include "core/column/column_string.h"
#include "core/data_type/data_type_date.h"
#include "core/data_type/data_type_date_or_datetime_v2.h"
#include "core/data_type/data_type_date_time.h"
#include "core/data_type/data_type_decimal.h"
+#include "core/data_type/data_type_factory.hpp"
+#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_time.h"
@@ -32,6 +38,8 @@
#include "core/value/vdatetime_value.h"
#include "exprs/function/function_date_or_datetime_computation.h"
#include "exprs/function/function_test_util.h"
+#include "exprs/function/simple_function_factory.h"
+#include "runtime/runtime_state.h"
#include "util/timezone_utils.h"
namespace doris {
@@ -1648,6 +1656,88 @@ TEST(VTimestampFunctionsTest, dayname_test) {
}
}
+TEST(VTimestampFunctionsTest, localized_date_name_capacity) {
+ const std::array<std::array<const char*, 3>, 3> locales {{{"ru_RU",
"воскресенье", "сентября"},
+ {"zh_CN", "星期日",
"九月"},
+ {"en_US",
"Sunday", "September"}}};
+ for (const auto primitive : {TYPE_DATEV2, TYPE_DATETIMEV2,
TYPE_TIMESTAMP_NS}) {
+ for (const bool nullable : {false, true}) {
+ const auto type =
DataTypeFactory::instance().create_data_type(primitive, nullable);
+ const auto return_type = nullable ?
make_nullable(std::make_shared<DataTypeString>())
+ :
std::make_shared<DataTypeString>();
+ for (const auto& locale : locales) {
+ for (const auto* function : {"dayname", "monthname"}) {
+ const std::string expected = locale[std::string(function)
== "dayname" ? 1 : 2];
+ for (const size_t rows : {0, 1, 1024}) {
+ for (const bool constant : {false, true}) {
+ SCOPED_TRACE(testing::Message()
+ << type->get_name() << " " <<
locale[0] << " " << function
+ << " rows=" << rows << " constant="
<< constant);
+ auto column = type->create_column();
+ for (size_t row = 0; row < (constant ? 1 : rows);
++row) {
+ if (nullable && !constant && row % 7 == 1) {
+ column->insert_default();
+ } else {
+ const std::string date = primitive ==
TYPE_DATEV2
+ ?
"2026-09-20"
+ :
"2026-09-20 12:34:56";
+ ASSERT_TRUE(insert_cell(column, type,
date));
+ }
+ }
+ if (constant) {
+ column =
ColumnConst::create(std::move(column), rows);
+ }
+ Block block {{std::move(column), type, "date"},
+ {nullptr, return_type, "result"}};
+ auto func =
SimpleFunctionFactory::instance().get_function(
+ function, {block.get_by_position(0)},
return_type);
+ ASSERT_NE(func, nullptr);
+ FunctionUtils utils(return_type, {type}, false);
+ auto* context = utils.get_fn_ctx();
+ context->state()->set_lc_time_names(locale[0]);
+ ASSERT_TRUE(
+ func->open(context,
+
FunctionContext::FunctionStateScope::FRAGMENT_LOCAL)
+ .ok());
+ ASSERT_TRUE(
+ func->open(context,
+
FunctionContext::FunctionStateScope::THREAD_LOCAL)
+ .ok());
+ ASSERT_TRUE(func->execute(context, block, {0}, 1,
rows).ok());
+ const auto result = block.get_by_position(1)
+
.column->convert_to_full_column_if_const();
+ ASSERT_EQ(result->size(), rows);
+ const auto& strings = assert_cast<const
ColumnString&>(
+ nullable ? assert_cast<const
ColumnNullable&>(*result)
+ .get_nested_column()
+ : *result);
+ size_t offset = 0;
+ for (size_t row = 0; row < rows; ++row) {
+ const bool is_null = nullable && !constant &&
row % 7 == 1;
+ EXPECT_EQ(result->is_null_at(row), is_null);
+ if (!is_null) {
+
EXPECT_EQ(strings.get_data_at(row).to_string(), expected);
+ offset += expected.size();
+ }
+ EXPECT_EQ(strings.get_offsets()[row], offset);
+ }
+ EXPECT_EQ(strings.get_chars().size(), offset);
+ ASSERT_TRUE(
+ func->close(context,
+
FunctionContext::FunctionStateScope::THREAD_LOCAL)
+ .ok());
+ ASSERT_TRUE(
+ func->close(context,
+
FunctionContext::FunctionStateScope::FRAGMENT_LOCAL)
+ .ok());
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
TEST(VTimestampFunctionsTest, datetrunc_test) {
std::string func_name = "date_trunc";
{
diff --git a/be/test/runtime/fold_constant_executor_test.cpp
b/be/test/runtime/fold_constant_executor_test.cpp
index 214044530a5..e22eac6edda 100644
--- a/be/test/runtime/fold_constant_executor_test.cpp
+++ b/be/test/runtime/fold_constant_executor_test.cpp
@@ -22,6 +22,7 @@
#include <gen_cpp/internal_service.pb.h>
#include <gtest/gtest.h>
+#include <array>
#include <map>
#include <string>
#include <utility>
@@ -83,5 +84,47 @@ TEST(FoldConstantExecutorTest, LegacyTimeStampNsResult) {
}
}
+TEST(FoldConstantExecutorTest, LocalizedDateNames) {
+ const std::array<std::array<const char*, 3>, 3> locales {{{"ru_RU",
"воскресенье", "сентября"},
+ {"zh_CN", "星期日",
"九月"},
+ {"en_US",
"Sunday", "September"}}};
+ for (const auto& locale : locales) {
+ TFoldConstantParams params;
+ params.query_globals.__set_now_string("2026-09-20 00:00:00");
+ params.query_globals.__set_time_zone("UTC");
+ params.query_globals.__set_lc_time_names(locale[0]);
+ // Decode strings directly so FE evaluation cannot hide a missing BE
locale.
+ params.__set_is_nereids(false);
+ for (const auto* name : {"dayname", "monthname"}) {
+ TFunctionName function_name;
+ function_name.__set_function_name(name);
+ TFunction function;
+ function.__set_name(function_name);
+ function.__set_binary_type(TFunctionBinaryType::BUILTIN);
+ function.__set_arg_types({create_type_desc(TYPE_TIMESTAMP_NS)});
+ function.__set_ret_type(create_type_desc(TYPE_STRING));
+ TExprNode call;
+ call.__set_node_type(TExprNodeType::FUNCTION_CALL);
+ call.__set_type(create_type_desc(TYPE_STRING));
+ call.__set_is_nullable(false);
+ call.__set_num_children(1);
+ call.__set_fn(function);
+ auto expression = timestamp_ns_literal_expr("2026-09-20
12:34:56.123456789");
+ expression.nodes.insert(expression.nodes.begin(), std::move(call));
+ params.expr_map["names"].emplace(name, std::move(expression));
+ }
+ PConstantExprResult response;
+ FoldConstantExecutor executor;
+ const auto status = executor.fold_constant_vexpr(params, &response);
+ ASSERT_TRUE(status.ok()) << status;
+ const auto& results = response.expr_result_map().at("names").map();
+ ASSERT_EQ(results.size(), 2);
+ EXPECT_TRUE(results.at("dayname").success());
+ EXPECT_TRUE(results.at("monthname").success());
+ EXPECT_EQ(results.at("dayname").content(), locale[1]);
+ EXPECT_EQ(results.at("monthname").content(), locale[2]);
+ }
+}
+
} // namespace
} // namespace doris
diff --git a/be/test/service/point_query_exector_test.cpp
b/be/test/service/point_query_exector_test.cpp
index ee9d4f7be99..14f5ebe8806 100644
--- a/be/test/service/point_query_exector_test.cpp
+++ b/be/test/service/point_query_exector_test.cpp
@@ -186,7 +186,8 @@ public:
return dtb.desc_tbl();
}
- static std::shared_ptr<Reusable> create_reusable() {
+ static std::shared_ptr<Reusable> create_reusable(const std::string&
timezone = "+08:00",
+ const std::string&
lc_time_names = "") {
auto obj_pool = std::make_unique<ObjectPool>();
auto runtime_state = RuntimeState::create_unique();
auto reusable = std::make_shared<Reusable>();
@@ -195,7 +196,8 @@ public:
TDescriptorTable t_desc_tbl = create_descriptor_tablet();
// Initialize Reusable
- Status st = reusable->init(t_desc_tbl, output_exprs, query_options,
*tablet_schema, 2);
+ Status st = reusable->init(t_desc_tbl, output_exprs, query_options,
timezone, lc_time_names,
+ *tablet_schema, 2);
if (!st.ok()) {
return nullptr;
}
@@ -246,9 +248,9 @@ TEST(PointQueryReusableTest,
AcceptDescriptorsWithoutAccessPaths) {
slot.__set_predicate_access_paths({});
}
Reusable reusable;
- auto status =
- reusable.init(descriptor, ReusableTestHelper::output_exprs,
- ReusableTestHelper::query_options,
*ReusableTestHelper::tablet_schema, 2);
+ auto status = reusable.init(descriptor, ReusableTestHelper::output_exprs,
+ ReusableTestHelper::query_options, "+08:00",
"",
+ *ReusableTestHelper::tablet_schema, 2);
ASSERT_TRUE(status.ok()) << status.to_string();
}
@@ -286,7 +288,7 @@ TEST(PointQueryReusableTest, RejectAllColumnAccessPaths) {
: TColumnAccessPaths
{});
Reusable reusable;
auto status = reusable.init(descriptor,
ReusableTestHelper::output_exprs,
- ReusableTestHelper::query_options,
+ ReusableTestHelper::query_options,
"+08:00", "",
*ReusableTestHelper::tablet_schema, 2);
ASSERT_FALSE(status.ok());
EXPECT_NE(status.to_string().find("does not support column access
paths"),
@@ -328,7 +330,7 @@ TEST(PointQueryReusableTest,
RejectFullStructRootAccessPaths) {
: TColumnAccessPaths {});
Reusable reusable;
auto status = reusable.init(descriptor,
ReusableTestHelper::output_exprs,
- ReusableTestHelper::query_options, schema,
2);
+ ReusableTestHelper::query_options,
"+08:00", "", schema, 2);
ASSERT_FALSE(status.ok());
EXPECT_NE(status.to_string().find("does not support column access
paths"),
std::string::npos);
@@ -363,7 +365,7 @@ TEST(PointQueryReusableTest,
MissingScalarWithoutPathsUsesPayloadOrFeDefault) {
Reusable reusable;
auto status = reusable.init(descriptor,
ReusableTestHelper::output_exprs,
- ReusableTestHelper::query_options,
+ ReusableTestHelper::query_options,
"+08:00", "",
*ReusableTestHelper::tablet_schema, 1);
ASSERT_TRUE(status.ok()) << status.to_string();
Block decoded(reusable.tuple_desc()->slots(), 1);
@@ -564,11 +566,44 @@ TEST_F(LookupConnectionCacheTest, PQTestInvalidKeys) {
cache.add(1, large_reusable);
}
-// Test key collision handling
+// Replacing a locale-specific context must not mutate in-flight requests.
+TEST_F(LookupConnectionCacheTest, PQTestLocaleContext) {
+ const __int128 uuid = 302;
+ auto chinese = ReusableTestHelper::create_reusable("UTC", "zh_CN");
+ ASSERT_NE(chinese, nullptr);
+ EXPECT_EQ(chinese->runtime_state()->lc_time_names(), "zh_CN");
+ EXPECT_TRUE(chinese->matches_timezone_and_locale("UTC", "zh_CN"));
+ EXPECT_FALSE(chinese->matches_timezone_and_locale("UTC", "en_US"));
+ EXPECT_FALSE(chinese->matches_timezone_and_locale("+08:00", "zh_CN"));
+ _lookup_cache->add(uuid, chinese);
+ auto retained = _lookup_cache->get(uuid);
+ ASSERT_EQ(retained, chinese);
+
+ auto english = ReusableTestHelper::create_reusable("UTC", "en_US");
+ ASSERT_NE(english, nullptr);
+ _lookup_cache->add(uuid, english);
+ auto current = _lookup_cache->get(uuid);
+ ASSERT_EQ(current, english);
+ EXPECT_TRUE(current->matches_timezone_and_locale("UTC", "en_US"));
+ EXPECT_FALSE(current->matches_timezone_and_locale("UTC", "zh_CN"));
+ EXPECT_EQ(retained->runtime_state()->lc_time_names(), "zh_CN");
+
+ PTabletKeyLookupRequest legacy_request;
+ EXPECT_FALSE(legacy_request.has_lc_time_names());
+ auto legacy = ReusableTestHelper::create_reusable("UTC",
legacy_request.lc_time_names());
+ ASSERT_NE(legacy, nullptr);
+ EXPECT_EQ(legacy->runtime_state()->lc_time_names(), "");
+ EXPECT_TRUE(legacy->matches_timezone_and_locale("UTC", ""));
+ EXPECT_FALSE(legacy->matches_timezone_and_locale("UTC", "en_US"));
+}
+
+// A prepared statement can replace its cached context after SET time_zone.
TEST_F(LookupConnectionCacheTest, PQTestDuplicateAdd) {
LookupConnectionCache cache(1024 * 1024);
- auto reusable1 = ReusableTestHelper::create_reusable();
- auto reusable2 = ReusableTestHelper::create_reusable();
+ auto reusable1 = ReusableTestHelper::create_reusable("UTC");
+ auto reusable2 = ReusableTestHelper::create_reusable("+06:00");
+ ASSERT_NE(reusable1, nullptr);
+ ASSERT_NE(reusable2, nullptr);
// Overwrite existing key
cache.add(123, reusable1);
diff --git a/be/test/testutil/function_utils.cpp
b/be/test/testutil/function_utils.cpp
index 079c506493c..f04a91380e6 100644
--- a/be/test/testutil/function_utils.cpp
+++ b/be/test/testutil/function_utils.cpp
@@ -36,6 +36,8 @@ FunctionUtils::FunctionUtils(const DataTypePtr& return_type,
globals.__set_nano_seconds(805000000);
_state = std::make_unique<MockRuntimeState>(globals);
+ // The legacy mock constructor does not initialize the locale from query
globals.
+ _state->set_lc_time_names("en_US");
_fn_ctx = FunctionContext::create_context(_state.get(), return_type,
arg_types);
_fn_ctx->set_enable_strict_mode(enable_strict_cast);
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java
index 4d6b33a6fcf..40dc8c458f6 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java
@@ -341,6 +341,7 @@ public class FoldConstantRuleOnBE implements
ExpressionPatternRuleFactory {
queryGlobals.setTimestampMs(System.currentTimeMillis());
queryGlobals.setTimeZone(
TimeUtils.getCanonicalTimeZone(context.getSessionVariable().getTimeZone()));
+
queryGlobals.setLcTimeNames(context.getSessionVariable().getLcTimeNames());
TQueryOptions tQueryOptions = new TQueryOptions();
tQueryOptions.setBeExecVersion(Config.be_exec_version);
@@ -348,6 +349,7 @@ public class FoldConstantRuleOnBE implements
ExpressionPatternRuleFactory {
tQueryOptions.setNewVersionUnixTimestamp(true);
tQueryOptions.setNewVersionPercentile(true);
tQueryOptions.setEnableStrictCast(SessionVariable.enableStrictCast());
+
tQueryOptions.setEnableHyperscanFallback(context.getSessionVariable().enableHyperscanFallback);
TFoldConstantParams tParams = new TFoldConstantParams(paramMap,
queryGlobals);
tParams.setVecExec(true);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/qe/PointQueryExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/PointQueryExecutor.java
index 84f9b2b18f7..c00473b3816 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/PointQueryExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/PointQueryExecutor.java
@@ -424,6 +424,7 @@ public class PointQueryExecutor implements CoordInterface {
// Set timezone for functions like from_unixtime
requestBuilder.setTimeZone(TimeUtils.getCanonicalTimeZone(
ConnectContext.get().getSessionVariable().getTimeZone()));
+
requestBuilder.setLcTimeNames(ConnectContext.get().getSessionVariable().getLcTimeNames());
if (snapshotVisibleVersions != null &&
!snapshotVisibleVersions.isEmpty()) {
requestBuilder.setVersion(snapshotVisibleVersions.get(0));
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/qe/ShortCircuitQueryContext.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/ShortCircuitQueryContext.java
index 933c8c7ec71..f001ec21991 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShortCircuitQueryContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShortCircuitQueryContext.java
@@ -67,6 +67,8 @@ public class ShortCircuitQueryContext {
private final long partitionTopologyVersion;
public final String tableName;
private final boolean enablePruneNestedColumns;
+ // The serialized output expressions may contain locale-dependent folded
literals.
+ private final String lcTimeNames;
public final OlapScanNode scanNode;
public final Queriable analzyedQuery;
@@ -97,6 +99,7 @@ public class ShortCircuitQueryContext {
this.planner = planner;
TDescriptorTable descriptors = planner.getDescTable().toThrift();
validateDescriptors(descriptors);
+ this.lcTimeNames = effectiveSession.getLcTimeNames();
this.serializedDescTable = ByteString.copyFrom(
new TSerializer().serialize(descriptors));
TQueryOptions options = planner.getQueryOptions() != null ?
planner.getQueryOptions() : new TQueryOptions();
@@ -131,7 +134,8 @@ public class ShortCircuitQueryContext {
}
@VisibleForTesting
- ShortCircuitQueryContext(OlapTable tbl, int schemaVersion, long
fileCacheQueryLimitBytes) {
+ ShortCircuitQueryContext(OlapTable tbl, int schemaVersion, long
fileCacheQueryLimitBytes,
+ String lcTimeNames) {
this.planner = null;
this.serializedDescTable = ByteString.EMPTY;
this.serializedOutputExpr = ByteString.EMPTY;
@@ -143,6 +147,7 @@ public class ShortCircuitQueryContext {
this.fileCacheQueryLimitBytes = fileCacheQueryLimitBytes;
this.partitionTopologyVersion = tbl.getPartitionTopologyVersion();
this.enablePruneNestedColumns = new
SessionVariable().enablePruneNestedColumns;
+ this.lcTimeNames = lcTimeNames;
this.scanNode = null;
this.analzyedQuery = null;
}
@@ -154,6 +159,7 @@ public class ShortCircuitQueryContext {
&& !this.tbl.isVariantValuesIndexExecutionDisabled()
&& this.tbl.getBaseSchemaVersion() == this.schemaVersion
&& this.fileCacheQueryLimitBytes ==
ctx.getSessionVariable().fileCacheQueryLimitBytes
+ && Objects.equals(this.lcTimeNames,
ctx.getSessionVariable().getLcTimeNames())
&& this.tbl.getPartitionTopologyVersion() ==
this.partitionTopologyVersion;
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/qe/SessionContextRequestTest.java
b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionContextRequestTest.java
new file mode 100644
index 00000000000..279616870e1
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionContextRequestTest.java
@@ -0,0 +1,165 @@
+// 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.
+
+package org.apache.doris.qe;
+
+import org.apache.doris.analysis.DescriptorTable;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.common.jmockit.Deencapsulation;
+import org.apache.doris.mysql.MysqlCommand;
+import org.apache.doris.nereids.rules.expression.rules.FoldConstantRuleOnBE;
+import org.apache.doris.planner.OlapScanNode;
+import org.apache.doris.planner.Planner;
+import org.apache.doris.proto.InternalService;
+import org.apache.doris.rpc.BackendServiceProxy;
+import org.apache.doris.system.Backend;
+import org.apache.doris.system.SystemInfoService;
+import org.apache.doris.thrift.TFoldConstantParams;
+import org.apache.doris.thrift.TNetworkAddress;
+import org.apache.doris.thrift.TQueryGlobals;
+import org.apache.doris.thrift.TUniqueId;
+
+import org.apache.thrift.TDeserializer;
+import org.apache.thrift.TSerializer;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
+
+class SessionContextRequestTest {
+ @AfterEach
+ void clearContext() {
+ ConnectContext.remove();
+ }
+
+ @Test
+ void testFoldRequestKeepsChineseLocale() throws Exception {
+ assertFoldLocale("zh_CN");
+ }
+
+ @Test
+ void testFoldRequestKeepsEnglishLocale() throws Exception {
+ assertFoldLocale("en_US");
+ }
+
+ private void assertFoldLocale(String locale) throws Exception {
+ ConnectContext context = newContext(locale);
+ TQueryGlobals normalQueryGlobals = new TQueryGlobals();
+ CoordinatorContext.refreshQueryGlobals(normalQueryGlobals, context);
+ Assertions.assertEquals(locale, normalQueryGlobals.getLcTimeNames());
+ TFoldConstantParams request = captureFoldRequest(context);
+ Assertions.assertTrue(request.getQueryGlobals().isSetLcTimeNames());
+ Assertions.assertEquals(locale,
request.getQueryGlobals().getLcTimeNames());
+ }
+
+ @Test
+ void testFoldRequestKeepsHyperscanFallback() throws Exception {
+ ConnectContext context = newContext("zh_CN");
+ for (boolean fallback : new boolean[] {false, true}) {
+ context.getSessionVariable().enableHyperscanFallback = fallback;
+ Assertions.assertEquals(fallback,
context.getSessionVariable().toThrift().isEnableHyperscanFallback());
+ TFoldConstantParams request = captureFoldRequest(context);
+
Assertions.assertTrue(request.getQueryOptions().isSetEnableHyperscanFallback());
+ Assertions.assertEquals(fallback,
request.getQueryOptions().isEnableHyperscanFallback());
+ }
+ }
+
+ @Test
+ void testPointLookupRequestChangesWithLocale() throws Exception {
+ ConnectContext context = newContext("zh_CN");
+ OlapTable table = Mockito.mock(OlapTable.class);
+ OlapScanNode scanNode = Mockito.mock(OlapScanNode.class);
+ Mockito.when(scanNode.getOlapTable()).thenReturn(table);
+
Mockito.when(scanNode.getTableNameInPlan()).thenReturn("session_context_case");
+
Mockito.when(scanNode.getProjectList()).thenReturn(Collections.emptyList());
+ Planner planner = Mockito.mock(Planner.class);
+ DescriptorTable descriptorTable = new DescriptorTable();
+ descriptorTable.createTupleDescriptor();
+ Mockito.when(planner.getDescTable()).thenReturn(descriptorTable);
+
Mockito.when(planner.getScanNodes()).thenReturn(Collections.singletonList(scanNode));
+
Mockito.when(planner.getQueryOptions()).thenReturn(context.getSessionVariable().toThrift());
+ ShortCircuitQueryContext shortCircuit =
+ new ShortCircuitQueryContext(planner, null,
context.getSessionVariable());
+ PointQueryExecutor executor = new PointQueryExecutor(shortCircuit,
1024);
+ for (MysqlCommand command : new MysqlCommand[]
{MysqlCommand.COM_QUERY, MysqlCommand.COM_STMT_EXECUTE}) {
+ context.command = command;
+ for (boolean full : new boolean[] {true, false, true}) {
+ for (String locale : new String[] {"zh_CN", "en_US", "zh_CN"})
{
+ context.getSessionVariable().setLcTimeNames(locale);
+ InternalService.PTabletKeyLookupRequest request =
Deencapsulation.invoke(
+ executor, "buildLookupRequest", full);
+ request =
InternalService.PTabletKeyLookupRequest.parseFrom(request.toByteArray());
+ Assertions.assertTrue(request.hasLcTimeNames());
+ Assertions.assertEquals(locale, request.getLcTimeNames());
+ Assertions.assertEquals(full, request.hasDescTbl());
+ Assertions.assertEquals(full, request.hasOutputExpr());
+ Assertions.assertEquals(full, request.hasQueryOptions());
+ Assertions.assertEquals(command ==
MysqlCommand.COM_STMT_EXECUTE, request.hasUuid());
+ if (request.hasUuid()) {
+
Assertions.assertEquals(shortCircuit.cacheID.getMostSignificantBits(),
+ request.getUuid().getUuidHigh());
+
Assertions.assertEquals(shortCircuit.cacheID.getLeastSignificantBits(),
+ request.getUuid().getUuidLow());
+ }
+ }
+ }
+ }
+ }
+
+ private ConnectContext newContext(String locale) {
+ ConnectContext context = new ConnectContext();
+ context.setThreadLocalInfo();
+ context.setQueryId(new TUniqueId(1, 2));
+ context.getSessionVariable().setLcTimeNames(locale);
+ return context;
+ }
+
+ private TFoldConstantParams captureFoldRequest(ConnectContext context)
throws Exception {
+ SystemInfoService systemInfo = Mockito.mock(SystemInfoService.class);
+ Backend backend = Mockito.mock(Backend.class);
+ BackendServiceProxy proxy = Mockito.mock(BackendServiceProxy.class);
+ Mockito.when(systemInfo.getAllBackendByCurrentCluster(true))
+ .thenReturn(new ArrayList<>(Collections.singletonList(1L)));
+ Mockito.when(systemInfo.getBackend(1L)).thenReturn(backend);
+ Mockito.when(backend.getHost()).thenReturn("127.0.0.1");
+ Mockito.when(backend.getBrpcPort()).thenReturn(8060);
+ AtomicReference<TFoldConstantParams> captured = new
AtomicReference<>();
+
Mockito.when(proxy.foldConstantExpr(Mockito.any(TNetworkAddress.class),
Mockito.any(TFoldConstantParams.class)))
+ .thenAnswer(invocation -> {
+ captured.set(invocation.getArgument(1));
+ return
CompletableFuture.completedFuture(InternalService.PConstantExprResult.getDefaultInstance());
+ });
+ try (MockedStatic<Env> env = Mockito.mockStatic(Env.class);
+ MockedStatic<BackendServiceProxy> proxies =
Mockito.mockStatic(BackendServiceProxy.class)) {
+ env.when(Env::getCurrentSystemInfo).thenReturn(systemInfo);
+ proxies.when(BackendServiceProxy::getInstance).thenReturn(proxy);
+ Deencapsulation.invoke(FoldConstantRuleOnBE.class, "evalOnBE",
+ Collections.emptyMap(), Collections.emptyMap(), context);
+ }
+ Assertions.assertNotNull(captured.get(), "real evalOnBE must reach the
RPC boundary");
+ TFoldConstantParams wireCopy = new TFoldConstantParams();
+ new TDeserializer().deserialize(wireCopy, new
TSerializer().serialize(captured.get()));
+ return wireCopy;
+ }
+}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/qe/ShortCircuitQueryContextTest.java
b/fe/fe-core/src/test/java/org/apache/doris/qe/ShortCircuitQueryContextTest.java
index a0605e81418..94318583ed7 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/qe/ShortCircuitQueryContextTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/qe/ShortCircuitQueryContextTest.java
@@ -70,16 +70,28 @@ public class ShortCircuitQueryContextTest {
@Test
public void testReusableRequiresSameFileCacheQueryLimitBytes() {
ShortCircuitQueryContext context =
- new ShortCircuitQueryContext(table("tbl", 10), 10, -1);
+ new ShortCircuitQueryContext(table("tbl", 10), 10, -1,
"en_US");
Assertions.assertTrue(context.isReusable(connectContext(-1)));
Assertions.assertFalse(context.isReusable(connectContext(0)));
}
+ @Test
+ public void testReusableRequiresSameLcTimeNames() {
+ ConnectContext ctx = connectContext(-1);
+ ctx.getSessionVariable().setLcTimeNames("zh_CN");
+ ShortCircuitQueryContext context =
+ new ShortCircuitQueryContext(table("tbl", 10), 10, -1,
"zh_CN");
+
+ Assertions.assertTrue(context.isReusable(ctx));
+ ctx.getSessionVariable().setLcTimeNames("en_US");
+ Assertions.assertFalse(context.isReusable(ctx));
+ }
+
@Test
public void testReusableStillChecksTableMetadata() {
ShortCircuitQueryContext context =
- new ShortCircuitQueryContext(table("tbl", 11), 10, 0);
+ new ShortCircuitQueryContext(table("tbl", 11), 10, 0, "en_US");
Assertions.assertFalse(context.isReusable(connectContext(0)));
}
@@ -95,7 +107,7 @@ public class ShortCircuitQueryContextTest {
table.setIndexMeta(baseIndexId, "tbl", baseSchema, 10, 0, (short) 1,
TStorageType.COLUMN, KeysType.DUP_KEYS);
table.setBaseIndexId(baseIndexId);
- ShortCircuitQueryContext context = new ShortCircuitQueryContext(table,
10, -1);
+ ShortCircuitQueryContext context = new ShortCircuitQueryContext(table,
10, -1, "en_US");
Assertions.assertTrue(context.isReusable(connectContext(-1)));
table.addPartition(new Partition(3L, "p1",
@@ -107,7 +119,7 @@ public class ShortCircuitQueryContextTest {
@Test
public void testDroppedTableCannotReuseCachedPlan() {
OlapTable table = table("tbl", 10);
- ShortCircuitQueryContext context = new ShortCircuitQueryContext(table,
10, -1);
+ ShortCircuitQueryContext context = new ShortCircuitQueryContext(table,
10, -1, "en_US");
Assertions.assertTrue(context.isReusable(connectContext(-1)));
table.isDropped = true;
Assertions.assertFalse(context.isReusable(connectContext(-1)));
@@ -116,7 +128,7 @@ public class ShortCircuitQueryContextTest {
@Test
public void testRenamedTableCannotReuseCachedPlan() {
OlapTable table = table("tbl", 10);
- ShortCircuitQueryContext context = new ShortCircuitQueryContext(table,
10, -1);
+ ShortCircuitQueryContext context = new ShortCircuitQueryContext(table,
10, -1, "en_US");
Assertions.assertTrue(context.isReusable(connectContext(-1)));
Mockito.doReturn("renamed").when(table).getName();
Assertions.assertFalse(context.isReusable(connectContext(-1)));
diff --git a/gensrc/proto/internal_service.proto
b/gensrc/proto/internal_service.proto
index ab666bda634..407c1098e8f 100644
--- a/gensrc/proto/internal_service.proto
+++ b/gensrc/proto/internal_service.proto
@@ -395,6 +395,8 @@ message PTabletKeyLookupRequest {
optional bytes query_options = 8;
// timezone string, e.g. "America/Mexico_City"
optional string time_zone = 9;
+ // Session locale for expression evaluation, including lightweight
requests.
+ optional string lc_time_names = 10;
}
message PTabletKeyLookupResponse {
diff --git
a/regression-test/data/nereids_p0/expression/fold_constant/test_be_fold_session_context.out
b/regression-test/data/nereids_p0/expression/fold_constant/test_be_fold_session_context.out
new file mode 100644
index 00000000000..9ca13c5193e
--- /dev/null
+++
b/regression-test/data/nereids_p0/expression/fold_constant/test_be_fold_session_context.out
@@ -0,0 +1,18 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !date_false_zh_CN --
+十一月 星期二
+
+-- !date_false_en_US --
+November Tuesday
+
+-- !date_true_zh_CN --
+十一月 星期二
+
+-- !date_true_en_US --
+November Tuesday
+
+-- !regex_false --
+1
+
+-- !regex_true --
+1
diff --git
a/regression-test/data/point_query_p0/test_point_query_date_name_capacity.out
b/regression-test/data/point_query_p0/test_point_query_date_name_capacity.out
new file mode 100644
index 00000000000..731df9af977
--- /dev/null
+++
b/regression-test/data/point_query_p0/test_point_query_date_name_capacity.out
@@ -0,0 +1,132 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !text_false_ru_RU_1 --
+1 1024 сентября воскресенье 22528 16384 22528 16384
22528 16384
+
+-- !text_false_ru_RU_2 --
+2 2 сентября воскресенье 22 16 22 16
22 16
+
+-- !text_false_ru_RU_3 --
+3 0 \N \N 0 0 0 0 0 0
+
+-- !text_false_ru_RU_4 --
+4 1 \N \N 0 0 0 0 0 0
+
+-- !text_false_ru_RU_5 --
+5 \N \N \N \N \N \N \N \N \N
+
+-- !text_false_zh_CN_1 --
+1 1024 九月 星期日 9216 6144 9216 6144 9216 6144
+
+-- !text_false_zh_CN_2 --
+2 2 九月 星期日 9 6 9 6 9 6
+
+-- !text_false_zh_CN_3 --
+3 0 \N \N 0 0 0 0 0 0
+
+-- !text_false_zh_CN_4 --
+4 1 \N \N 0 0 0 0 0 0
+
+-- !text_false_zh_CN_5 --
+5 \N \N \N \N \N \N \N \N \N
+
+-- !text_false_en_US_1 --
+1 1024 September Sunday 6144 9216 6144 9216 6144
9216
+
+-- !text_false_en_US_2 --
+2 2 September Sunday 6 9 6 9 6
9
+
+-- !text_false_en_US_3 --
+3 0 \N \N 0 0 0 0 0 0
+
+-- !text_false_en_US_4 --
+4 1 \N \N 0 0 0 0 0 0
+
+-- !text_false_en_US_5 --
+5 \N \N \N \N \N \N \N \N \N
+
+-- !text_true_ru_RU_1 --
+1 1024 сентября воскресенье 22528 16384 22528 16384
22528 16384
+
+-- !text_true_ru_RU_2 --
+2 2 сентября воскресенье 22 16 22 16
22 16
+
+-- !text_true_ru_RU_3 --
+3 0 \N \N 0 0 0 0 0 0
+
+-- !text_true_ru_RU_4 --
+4 1 \N \N 0 0 0 0 0 0
+
+-- !text_true_ru_RU_5 --
+5 \N \N \N \N \N \N \N \N \N
+
+-- !text_true_zh_CN_1 --
+1 1024 九月 星期日 9216 6144 9216 6144 9216 6144
+
+-- !text_true_zh_CN_2 --
+2 2 九月 星期日 9 6 9 6 9 6
+
+-- !text_true_zh_CN_3 --
+3 0 \N \N 0 0 0 0 0 0
+
+-- !text_true_zh_CN_4 --
+4 1 \N \N 0 0 0 0 0 0
+
+-- !text_true_zh_CN_5 --
+5 \N \N \N \N \N \N \N \N \N
+
+-- !text_true_en_US_1 --
+1 1024 September Sunday 6144 9216 6144 9216 6144
9216
+
+-- !text_true_en_US_2 --
+2 2 September Sunday 6 9 6 9 6
9
+
+-- !text_true_en_US_3 --
+3 0 \N \N 0 0 0 0 0 0
+
+-- !text_true_en_US_4 --
+4 1 \N \N 0 0 0 0 0 0
+
+-- !text_true_en_US_5 --
+5 \N \N \N \N \N \N \N \N \N
+
+-- !prepared_false_0 --
+1 1024 сентября воскресенье 22528 16384 22528 16384
22528 16384
+
+-- !prepared_false_1 --
+1 1024 сентября воскресенье 22528 16384 22528 16384
22528 16384
+
+-- !prepared_false_2 --
+1 1024 九月 星期日 9216 6144 9216 6144 9216 6144
+
+-- !prepared_false_3 --
+1 1024 九月 星期日 9216 6144 9216 6144 9216 6144
+
+-- !prepared_false_4 --
+1 1024 September Sunday 6144 9216 6144 9216 6144
9216
+
+-- !prepared_false_5 --
+1 1024 September Sunday 6144 9216 6144 9216 6144
9216
+
+-- !prepared_false_6 --
+1 1024 сентября воскресенье 22528 16384 22528 16384
22528 16384
+
+-- !prepared_true_0 --
+1 1024 сентября воскресенье 22528 16384 22528 16384
22528 16384
+
+-- !prepared_true_1 --
+1 1024 сентября воскресенье 22528 16384 22528 16384
22528 16384
+
+-- !prepared_true_2 --
+1 1024 九月 星期日 9216 6144 9216 6144 9216 6144
+
+-- !prepared_true_3 --
+1 1024 九月 星期日 9216 6144 9216 6144 9216 6144
+
+-- !prepared_true_4 --
+1 1024 September Sunday 6144 9216 6144 9216 6144
9216
+
+-- !prepared_true_5 --
+1 1024 September Sunday 6144 9216 6144 9216 6144
9216
+
+-- !prepared_true_6 --
+1 1024 сентября воскресенье 22528 16384 22528 16384
22528 16384
diff --git
a/regression-test/data/point_query_p0/test_point_query_lc_time_names.out
b/regression-test/data/point_query_p0/test_point_query_lc_time_names.out
new file mode 100644
index 00000000000..517b2df075e
--- /dev/null
+++ b/regression-test/data/point_query_p0/test_point_query_lc_time_names.out
@@ -0,0 +1,48 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !text_false_zh_CN --
+1 十一月 星期二
+
+-- !text_false_en_US --
+1 November Tuesday
+
+-- !text_true_zh_CN --
+1 十一月 星期二
+
+-- !text_true_en_US --
+1 November Tuesday
+
+-- !prepared_false_0 --
+1 2026-11-17 十一月
+
+-- !prepared_false_1 --
+1 2026-11-17 十一月
+
+-- !prepared_false_2 --
+1 2026-11-17 November
+
+-- !prepared_false_3 --
+1 2026-11-17 November
+
+-- !prepared_false_4 --
+1 2026-11-17 十一月
+
+-- !prepared_false_5 --
+1 2026-11-17 十一月
+
+-- !prepared_true_0 --
+1 2026-11-17 十一月
+
+-- !prepared_true_1 --
+1 2026-11-17 十一月
+
+-- !prepared_true_2 --
+1 2026-11-17 November
+
+-- !prepared_true_3 --
+1 2026-11-17 November
+
+-- !prepared_true_4 --
+1 2026-11-17 十一月
+
+-- !prepared_true_5 --
+1 2026-11-17 十一月
diff --git
a/regression-test/suites/nereids_p0/expression/fold_constant/test_be_fold_session_context.groovy
b/regression-test/suites/nereids_p0/expression/fold_constant/test_be_fold_session_context.groovy
new file mode 100644
index 00000000000..2122bc8b5e8
--- /dev/null
+++
b/regression-test/suites/nereids_p0/expression/fold_constant/test_be_fold_session_context.groovy
@@ -0,0 +1,59 @@
+// 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_be_fold_session_context") {
+ sql "SET enable_sql_cache = false"
+ def dateExpr = "str_to_date(concat('2026-11-', CAST(10 + crc32('a') % 10
AS STRING)), '%Y-%m-%d')"
+ def dateQuery = "SELECT monthname(${dateExpr}) AS m, dayname(${dateExpr})
AS d"
+ [false, true].each { fold ->
+ sql "SET enable_fold_constant_by_be = ${fold}"
+ ["zh_CN", "en_US"].each { locale ->
+ sql "SET lc_time_names = '${locale}'"
+ explain {
+ sql dateQuery
+ if (fold) {
+ notContains "crc32"
+ contains(locale == "zh_CN" ? "十一月" : "November")
+ } else {
+ contains "crc32"
+ }
+ }
+ quickRunTest("date_${fold}_${locale}", dateQuery, true)
+ }
+ }
+
+ sql "DROP TABLE IF EXISTS test_be_fold_session_context_tbl"
+ sql """CREATE TABLE test_be_fold_session_context_tbl (id INT, txt STRING)
+ DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES("replication_num" = "1")"""
+ sql "INSERT INTO test_be_fold_session_context_tbl VALUES (1, 'abc'), (2,
'def')"
+ def regexQuery = """SELECT id FROM test_be_fold_session_context_tbl
+ WHERE txt = 'abc' AND ('abc' REGEXP '(?U)a+') ORDER BY id"""
+ sql "SET enable_hyperscan_fallback = false"
+ [false, true].each { fold ->
+ sql "SET enable_fold_constant_by_be = ${fold}"
+ test {
+ sql regexQuery
+ exception "hs_compile regex pattern error"
+ }
+ }
+ sql "SET enable_hyperscan_fallback = true"
+ [false, true].each { fold ->
+ sql "SET enable_fold_constant_by_be = ${fold}"
+ quickRunTest("regex_${fold}", regexQuery, true)
+ }
+}
diff --git
a/regression-test/suites/point_query_p0/test_point_query_date_name_capacity.groovy
b/regression-test/suites/point_query_p0/test_point_query_date_name_capacity.groovy
new file mode 100644
index 00000000000..9a3dcbeb8b6
--- /dev/null
+++
b/regression-test/suites/point_query_p0/test_point_query_date_name_capacity.groovy
@@ -0,0 +1,82 @@
+// 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_point_query_date_name_capacity", "p0,nonConcurrent") {
+ sql "DROP TABLE IF EXISTS test_point_query_date_name_capacity"
+ sql """CREATE TABLE test_point_query_date_name_capacity (
+ id INT, dates ARRAY<DATE>, datetimes ARRAY<DATETIMEV2(6)>, timestamps
ARRAY<TIMESTAMP_NS>)
+ UNIQUE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES("replication_num" = "1", "enable_unique_key_merge_on_write"
= "true",
+ "store_row_column" = "true")"""
+ sql """INSERT INTO test_point_query_date_name_capacity VALUES
+ (1, array_repeat(CAST('2026-09-20' AS DATE), 1024),
+ array_repeat(CAST('2026-09-20 12:34:56.123456' AS DATETIMEV2(6)),
1024),
+ array_repeat(CAST('2026-09-20 12:34:56.123456789' AS
TIMESTAMP_NS), 1024)),
+ (2, array(CAST('2026-09-20' AS DATE), NULL),
+ array(CAST('2026-09-20 12:34:56' AS DATETIMEV2(6)), NULL),
+ array(CAST('2026-09-20 12:34:56' AS TIMESTAMP_NS), NULL)),
+ (3, [], [], []), (4, [NULL], [NULL], [NULL]), (5, NULL, NULL, NULL)"""
+ sql "SET enable_sql_cache = false"
+ def projection = """SELECT id, array_size(dates), monthname(dates[1]),
dayname(dates[1]),
+ length(array_join(array_map(x -> dayname(x), dates), '')),
+ length(array_join(array_map(x -> monthname(x), dates), '')),
+ length(array_join(array_map(x -> dayname(x), datetimes), '')),
+ length(array_join(array_map(x -> monthname(x), datetimes), '')),
+ length(array_join(array_map(x -> dayname(x), timestamps), '')),
+ length(array_join(array_map(x -> monthname(x), timestamps), ''))
+ FROM test_point_query_date_name_capacity"""
+ [false, true].each { shortCircuit ->
+ sql "SET enable_short_circuit_query = ${shortCircuit}"
+ ["ru_RU", "zh_CN", "en_US"].each { locale ->
+ sql "SET lc_time_names = '${locale}'"
+ if (shortCircuit) {
+ explain {
+ sql "${projection} WHERE id = 1"
+ // Keep the branch-4.2 safety fallback for nested/array
expressions.
+ notContains "SHORT-CIRCUIT"
+ }
+ }
+ (1..5).each { id ->
+ quickRunTest("text_${shortCircuit}_${locale}_${id}",
"${projection} WHERE id = ${id}", true)
+ }
+ }
+ }
+
+ def oldLightweight = sql("ADMIN SHOW FRONTEND CONFIG LIKE
'enable_lightweight_lookup_request'")[0][1]
+ def database = sql("SELECT DATABASE()")[0][0]
+ def prepareUrl = getServerPrepareJdbcUrl(context.config.jdbcUrl, database,
false)
+ try {
+ [false, true].each { lightweight ->
+ sql """ADMIN SET FRONTEND CONFIG
("enable_lightweight_lookup_request" = "${lightweight}")"""
+ connectToDoris(context.config.jdbcUser,
context.config.jdbcPassword, prepareUrl) {
+ sql "SET enable_sql_cache = false"
+ sql "SET enable_short_circuit_query = true"
+ try (def statement = prepareStatement("${projection} WHERE id
= ?")) {
+ assertEquals(statement.class,
com.mysql.cj.jdbc.ServerPreparedStatement)
+ statement.setInt(1, 1)
+ // Long UTF-8 names must remain safe on both cache hits
and locale changes.
+ ["ru_RU", "ru_RU", "zh_CN", "zh_CN", "en_US", "en_US",
"ru_RU"].eachWithIndex { locale, index ->
+ sql "SET lc_time_names = '${locale}'"
+ quickRunTest("prepared_${lightweight}_${index}",
statement, true)
+ }
+ }
+ }
+ }
+ } finally {
+ sql """ADMIN SET FRONTEND CONFIG ("enable_lightweight_lookup_request"
= "${oldLightweight}")"""
+ }
+}
diff --git
a/regression-test/suites/point_query_p0/test_point_query_lc_time_names.groovy
b/regression-test/suites/point_query_p0/test_point_query_lc_time_names.groovy
new file mode 100644
index 00000000000..28f78102691
--- /dev/null
+++
b/regression-test/suites/point_query_p0/test_point_query_lc_time_names.groovy
@@ -0,0 +1,83 @@
+// 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_point_query_lc_time_names", "p0,nonConcurrent") {
+ sql "DROP TABLE IF EXISTS test_point_query_lc_time_names_tbl"
+ sql """CREATE TABLE test_point_query_lc_time_names_tbl (id INT, d DATE)
+ UNIQUE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES("replication_num" = "1", "enable_unique_key_merge_on_write"
= "true",
+ "store_row_column" = "true")"""
+ sql """INSERT INTO test_point_query_lc_time_names_tbl VALUES
+ (1, '2026-11-17'), (2, '2026-03-02')"""
+ sql "SET enable_sql_cache = false"
+ def query = "SELECT id, monthname(d), dayname(d) FROM
test_point_query_lc_time_names_tbl WHERE id = 1"
+ [false, true].each { shortCircuit ->
+ sql "SET enable_short_circuit_query = ${shortCircuit}"
+ ["zh_CN", "en_US"].each { locale ->
+ sql "SET lc_time_names = '${locale}'"
+ if (shortCircuit) {
+ explain {
+ sql query
+ // branch-4.2 deliberately keeps non-slot projections on
the normal path.
+ notContains "SHORT-CIRCUIT"
+ }
+ }
+ quickRunTest("text_${shortCircuit}_${locale}", query, true)
+ }
+ }
+
+ // crc32 prevents FE-only folding before MONTHNAME is evaluated by BE
constant folding.
+ // After folding, only scalar slots/literals remain, as required by
branch-4.2 point queries.
+ def preparedProjection = """SELECT id, d,
+ monthname(str_to_date(concat('2026-11-', CAST(10 + crc32('a') % 10 AS
STRING)), '%Y-%m-%d')) AS folded_month
+ FROM test_point_query_lc_time_names_tbl"""
+ def oldLightweight = sql("ADMIN SHOW FRONTEND CONFIG LIKE
'enable_lightweight_lookup_request'")[0][1]
+ def database = sql("SELECT DATABASE()")[0][0]
+ def prepareUrl = getServerPrepareJdbcUrl(context.config.jdbcUrl, database,
false)
+ try {
+ [false, true].each { lightweight ->
+ sql """ADMIN SET FRONTEND CONFIG
("enable_lightweight_lookup_request" = "${lightweight}")"""
+ // EXPLAIN uses text protocol on branch-4.2; the SELECT below
remains server-prepared.
+ sql "SET enable_short_circuit_query = true"
+ sql "SET enable_fold_constant_by_be = true"
+ sql "SET lc_time_names = 'zh_CN'"
+ explain {
+ sql "${preparedProjection} WHERE id = 1"
+ contains "SHORT-CIRCUIT"
+ contains "十一月"
+ notContains "crc32"
+ }
+ connectToDoris(context.config.jdbcUser,
context.config.jdbcPassword, prepareUrl) {
+ sql "SET enable_sql_cache = false"
+ sql "SET enable_short_circuit_query = true"
+ sql "SET enable_fold_constant_by_be = true"
+ sql "SET lc_time_names = 'zh_CN'"
+ try (def statement = prepareStatement("${preparedProjection}
WHERE id = ?")) {
+ assertEquals(statement.class,
com.mysql.cj.jdbc.ServerPreparedStatement)
+ statement.setInt(1, 1)
+ // Reuse the JDBC statement across both cache hits and
locale changes.
+ ["zh_CN", "zh_CN", "en_US", "en_US", "zh_CN",
"zh_CN"].eachWithIndex { locale, index ->
+ sql "SET lc_time_names = '${locale}'"
+ quickRunTest("prepared_${lightweight}_${index}",
statement, true)
+ }
+ }
+ }
+ }
+ } finally {
+ sql """ADMIN SET FRONTEND CONFIG ("enable_lightweight_lookup_request"
= "${oldLightweight}")"""
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]