From 6cdafc31040b8264c065fdd1d13425315e9cdf8c Mon Sep 17 00:00:00 2001 From: DuckLabs GitHub Bot Date: Wed, 25 Nov 2026 13:23:46 +0000 Subject: [PATCH] Update vendored DuckDB sources to 5e78b7f8338 --- .../aggregate/distributive/arg_min_max.cpp | 6 +- .../json/json_functions/json_transform.cpp | 2 + ...nerated_extension_loader_package_build.cpp | 8 +-- .../aggregate/distributive/minmax.cpp | 16 +++-- .../src/function/aggregate_function.cpp | 5 +- src/duckdb/src/function/function_binder.cpp | 3 +- .../scalar/system/aggregate_export.cpp | 2 + .../function/table/version/pragma_version.cpp | 6 +- .../duckdb/common/enums/collation_type.hpp | 3 +- .../duckdb/function/aggregate_function.hpp | 9 ++- src/duckdb/src/planner/collation_binding.cpp | 2 +- src/duckdb/src/planner/table_filter_state.cpp | 70 +++++++++++-------- .../yyjson/include/yyjson_memory.hpp | 21 +++++- 13 files changed, 101 insertions(+), 52 deletions(-) diff --git a/src/duckdb/extension/core_functions/aggregate/distributive/arg_min_max.cpp b/src/duckdb/extension/core_functions/aggregate/distributive/arg_min_max.cpp index 11bb741d0..3408a2f6b 100644 --- a/src/duckdb/extension/core_functions/aggregate/distributive/arg_min_max.cpp +++ b/src/duckdb/extension/core_functions/aggregate/distributive/arg_min_max.cpp @@ -210,7 +210,7 @@ struct ArgMinMaxBase { auto &context = input.GetClientContext(); auto &function = input.GetBoundFunction(); auto &arguments = input.GetArguments(); - ExpressionBinder::PushCollation(context, arguments[1], arguments[1]->GetReturnType()); + ExpressionBinder::PushCollation(context, arguments[1], arguments[1]->GetReturnType(), input.GetCollationType()); function.GetArguments()[0] = arguments[0]->GetReturnType(); function.GetArguments()[1] = arguments[1]->GetReturnType(); function.SetReturnType(arguments[0]->GetReturnType()); @@ -377,7 +377,7 @@ struct VectorArgMinMaxBase : ArgMinMaxBase { auto &context = input.GetClientContext(); auto &function = input.GetBoundFunction(); auto &arguments = input.GetArguments(); - ExpressionBinder::PushCollation(context, arguments[1], arguments[1]->GetReturnType()); + ExpressionBinder::PushCollation(context, arguments[1], arguments[1]->GetReturnType(), input.GetCollationType()); function.GetArguments()[0] = arguments[0]->GetReturnType(); function.GetArguments()[1] = arguments[1]->GetReturnType(); function.SetReturnType(arguments[0]->GetReturnType()); @@ -899,7 +899,7 @@ unique_ptr ArgMinMaxNBind(BindAggregateFunctionInput &input) { throw ParameterNotResolvedException(); } } - ExpressionBinder::PushCollation(context, arguments[1], arguments[1]->GetReturnType()); + ExpressionBinder::PushCollation(context, arguments[1], arguments[1]->GetReturnType(), input.GetCollationType()); const auto val_type = arguments[0]->GetReturnType().InternalType(); const auto arg_type = arguments[1]->GetReturnType().InternalType(); diff --git a/src/duckdb/extension/json/json_functions/json_transform.cpp b/src/duckdb/extension/json/json_functions/json_transform.cpp index b78d0dff1..3364f51b2 100644 --- a/src/duckdb/extension/json/json_functions/json_transform.cpp +++ b/src/duckdb/extension/json/json_functions/json_transform.cpp @@ -1310,6 +1310,8 @@ static bool JSONToAnyCast(Vector &source, Vector &result, idx_t count, CastParam options.delay_error = true; auto success = TransformFunctionInternal(source, count, result, alc, options); + // strings of the result point into the JSON allocator, which must outlive the cast's local state + JSONAllocator::AddBuffer(result, alc); if (!success) { HandleCastError::AssignError(options.error_message, parameters); } diff --git a/src/duckdb/generated_extension_loader_package_build.cpp b/src/duckdb/generated_extension_loader_package_build.cpp index cbecf7160..2ed0c2c61 100644 --- a/src/duckdb/generated_extension_loader_package_build.cpp +++ b/src/duckdb/generated_extension_loader_package_build.cpp @@ -45,7 +45,7 @@ int32_t duckdb_extension_core_functions_describe(duckdb_extension_descriptor *de descriptor->version = 1; descriptor->name = "core_functions"; descriptor->extension_version = EXT_VERSION_CORE_FUNCTIONS; - descriptor->api_version = "v2.1.0-alpha57486"; + descriptor->api_version = "v2.1.0-alpha57538"; descriptor->entry_cpp = (void (*)(void))core_functions_duckdb_cpp_init; return 0; } @@ -78,7 +78,7 @@ int32_t duckdb_extension_parquet_describe(duckdb_extension_descriptor *descripto descriptor->version = 1; descriptor->name = "parquet"; descriptor->extension_version = EXT_VERSION_PARQUET; - descriptor->api_version = "v2.1.0-alpha57486"; + descriptor->api_version = "v2.1.0-alpha57538"; descriptor->entry_cpp = (void (*)(void))parquet_duckdb_cpp_init; return 0; } @@ -111,7 +111,7 @@ int32_t duckdb_extension_icu_describe(duckdb_extension_descriptor *descriptor) { descriptor->version = 1; descriptor->name = "icu"; descriptor->extension_version = EXT_VERSION_ICU; - descriptor->api_version = "v2.1.0-alpha57486"; + descriptor->api_version = "v2.1.0-alpha57538"; descriptor->entry_cpp = (void (*)(void))icu_duckdb_cpp_init; return 0; } @@ -144,7 +144,7 @@ int32_t duckdb_extension_json_describe(duckdb_extension_descriptor *descriptor) descriptor->version = 1; descriptor->name = "json"; descriptor->extension_version = EXT_VERSION_JSON; - descriptor->api_version = "v2.1.0-alpha57486"; + descriptor->api_version = "v2.1.0-alpha57538"; descriptor->entry_cpp = (void (*)(void))json_duckdb_cpp_init; return 0; } diff --git a/src/duckdb/src/function/aggregate/distributive/minmax.cpp b/src/duckdb/src/function/aggregate/distributive/minmax.cpp index 9d93f3ca2..bbdcdd700 100644 --- a/src/duckdb/src/function/aggregate/distributive/minmax.cpp +++ b/src/duckdb/src/function/aggregate/distributive/minmax.cpp @@ -351,12 +351,13 @@ shared_ptr GetCollatedMinMaxFunction(ClientContext &con } //! Whether min/max over the type are computed through arg_min/arg_max over the collated value -static bool MinMaxUsesCollation(ClientContext &context, const LogicalType &input_type) { +static bool MinMaxUsesCollation(ClientContext &context, const LogicalType &input_type, CollationType collation_type) { // The generic non-VARCHAR collation path is not ready yet (see internal #8704). BIT, TIMETZ and VARIANT use // explicit binary-comparable keys so min/max follows the same logical order as comparisons and ORDER BY. const auto varchar_collation = input_type.id() == LogicalTypeId::VARCHAR && - (!StringType::GetCollation(input_type).empty() || !Settings::Get(context).empty()); + (!StringType::GetCollation(input_type).empty() || (collation_type != CollationType::EXPLICIT_COLLATIONS && + !Settings::Get(context).empty())); const auto nested_collation = StructType::IsStruct(input_type) || input_type.id() == LogicalTypeId::LIST || input_type.id() == LogicalTypeId::ARRAY; return input_type.id() == LogicalTypeId::BIT || input_type.id() == LogicalTypeId::TIME_TZ || @@ -370,9 +371,11 @@ unique_ptr BindMinMax(BindAggregateFunctionInput &input) { auto &arguments = input.GetArguments(); auto input_type = arguments[0]->GetReturnType(); - const auto collation = MinMaxUsesCollation(context, input_type); + const auto collation_type = input.GetCollationType(); + const auto collation = MinMaxUsesCollation(context, input_type, collation_type); auto collated_arg = collation ? arguments[0]->Copy() : nullptr; - if (collation && ExpressionBinder::PushCollation(context, collated_arg, collated_arg->GetReturnType())) { + if (collation && + ExpressionBinder::PushCollation(context, collated_arg, collated_arg->GetReturnType(), collation_type)) { // If aggr function is min/max and uses collations, replace bound_function with arg_min/arg_max // to make sure the result's correctness. vector types {arguments[0]->GetReturnType(), collated_arg->GetReturnType()}; @@ -572,9 +575,10 @@ unique_ptr MinMaxNBind(BindAggregateFunctionInput &input) { throw ParameterNotResolvedException(); } } - if (MinMaxUsesCollation(context, arguments[0]->GetReturnType())) { + const auto collation_type = input.GetCollationType(); + if (MinMaxUsesCollation(context, arguments[0]->GetReturnType(), collation_type)) { auto collated_arg = arguments[0]->Copy(); - if (ExpressionBinder::PushCollation(context, collated_arg, collated_arg->GetReturnType())) { + if (ExpressionBinder::PushCollation(context, collated_arg, collated_arg->GetReturnType(), collation_type)) { vector types {arguments[0]->GetReturnType(), collated_arg->GetReturnType(), arguments[1]->GetReturnType()}; auto collated_function = GetCollatedMinMaxFunction(context, function.GetName(), types); diff --git a/src/duckdb/src/function/aggregate_function.cpp b/src/duckdb/src/function/aggregate_function.cpp index 384f3dae7..c3a635f47 100644 --- a/src/duckdb/src/function/aggregate_function.cpp +++ b/src/duckdb/src/function/aggregate_function.cpp @@ -185,10 +185,11 @@ BindAggregateFunctionInput::BindAggregateFunctionInput(ClientContext &context_p, BoundAggregateFunction &bound_function_p, vector> &arguments_p, optional_ptr binder_p, - optional_ptr decimal_width_limit_p) + optional_ptr decimal_width_limit_p, + bool arguments_collated_p) : BindFunctionInput(context_p, bound_function_p, bound_function_p.GetDefinition()->GetSignature(), arguments_p, binder_p, decimal_width_limit_p), - bound_function(bound_function_p) { + bound_function(bound_function_p), arguments_collated(arguments_collated_p) { } } // namespace duckdb diff --git a/src/duckdb/src/function/function_binder.cpp b/src/duckdb/src/function/function_binder.cpp index 1214c720a..7ebdce0b4 100644 --- a/src/duckdb/src/function/function_binder.cpp +++ b/src/duckdb/src/function/function_binder.cpp @@ -1636,7 +1636,8 @@ FunctionBinder::ResolveAggregateFunction(const FunctionBinding &binding, vector< unique_ptr bind_info; if (bound_function.GetCallbacks().HasBindCallback()) { - BindAggregateFunctionInput input(context, bound_function, children, binder, decimal_width_limit); + BindAggregateFunctionInput input(context, bound_function, children, binder, decimal_width_limit, + arguments_collated); bind_info = bound_function.GetCallbacks().GetBindCallback()(input); // we may have lost some arguments in the bind diff --git a/src/duckdb/src/function/scalar/system/aggregate_export.cpp b/src/duckdb/src/function/scalar/system/aggregate_export.cpp index 087e3c61e..f56078049 100644 --- a/src/duckdb/src/function/scalar/system/aggregate_export.cpp +++ b/src/duckdb/src/function/scalar/system/aggregate_export.cpp @@ -286,6 +286,8 @@ unique_ptr BindExportedAggregate(FunctionBinder &functi } } + // The recorded signature already holds the collations the state was built with + function_binder.arguments_collated = true; vector>> keyword_args; auto [bound_aggr, bind_info] = function_binder.ResolveAggregateFunction(best_function.GetBinding(), args, keyword_args); diff --git a/src/duckdb/src/function/table/version/pragma_version.cpp b/src/duckdb/src/function/table/version/pragma_version.cpp index a4cb72041..d3e81a89d 100644 --- a/src/duckdb/src/function/table/version/pragma_version.cpp +++ b/src/duckdb/src/function/table/version/pragma_version.cpp @@ -1,5 +1,5 @@ #ifndef DUCKDB_PATCH_VERSION -#define DUCKDB_PATCH_VERSION "0-alpha57486" +#define DUCKDB_PATCH_VERSION "0-alpha57538" #endif #ifndef DUCKDB_MINOR_VERSION #define DUCKDB_MINOR_VERSION 1 @@ -8,10 +8,10 @@ #define DUCKDB_MAJOR_VERSION 2 #endif #ifndef DUCKDB_VERSION -#define DUCKDB_VERSION "v2.1.0-alpha57486" +#define DUCKDB_VERSION "v2.1.0-alpha57538" #endif #ifndef DUCKDB_SOURCE_ID -#define DUCKDB_SOURCE_ID "f0b39a6d67" +#define DUCKDB_SOURCE_ID "5e78b7f833" #endif #include "duckdb/function/table/system_functions.hpp" #include "duckdb/main/database.hpp" diff --git a/src/duckdb/src/include/duckdb/common/enums/collation_type.hpp b/src/duckdb/src/include/duckdb/common/enums/collation_type.hpp index bd1a6e95a..20e75fbd4 100644 --- a/src/duckdb/src/include/duckdb/common/enums/collation_type.hpp +++ b/src/duckdb/src/include/duckdb/common/enums/collation_type.hpp @@ -12,6 +12,7 @@ namespace duckdb { -enum class CollationType { ALL_COLLATIONS, COMBINABLE_COLLATIONS }; +//! EXPLICIT_COLLATIONS applies the collations of the type, but not the default collation +enum class CollationType { ALL_COLLATIONS, COMBINABLE_COLLATIONS, EXPLICIT_COLLATIONS }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/function/aggregate_function.hpp b/src/duckdb/src/include/duckdb/function/aggregate_function.hpp index e4800fb85..ec5c2a7d9 100644 --- a/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +++ b/src/duckdb/src/include/duckdb/function/aggregate_function.hpp @@ -9,6 +9,7 @@ #pragma once #include "duckdb/common/array.hpp" +#include "duckdb/common/enums/collation_type.hpp" #include "duckdb/common/enums/optimizer_type.hpp" #include "duckdb/common/vector_operations/aggregate_executor.hpp" #include "duckdb/function/aggregate_state.hpp" @@ -64,14 +65,20 @@ class BindAggregateFunctionInput : public BindFunctionInput { // Defined out-of-line: converting to the BindFunctionInput base requires the complete BoundAggregateFunction. BindAggregateFunctionInput(ClientContext &context_p, BoundAggregateFunction &bound_function_p, vector> &arguments_p, optional_ptr binder_p = nullptr, - optional_ptr decimal_width_limit_p = nullptr); + optional_ptr decimal_width_limit_p = nullptr, + bool arguments_collated_p = false); BoundAggregateFunction &GetBoundFunction() const { return bound_function; } + //! The collations to push into the arguments: arguments bound before do not get the default collation again + CollationType GetCollationType() const { + return arguments_collated ? CollationType::EXPLICIT_COLLATIONS : CollationType::ALL_COLLATIONS; + } private: BoundAggregateFunction &bound_function; + bool arguments_collated; }; class FunctionExpression; diff --git a/src/duckdb/src/planner/collation_binding.cpp b/src/duckdb/src/planner/collation_binding.cpp index ba8205c1a..08b5f8bff 100644 --- a/src/duckdb/src/planner/collation_binding.cpp +++ b/src/duckdb/src/planner/collation_binding.cpp @@ -74,7 +74,7 @@ static vector GetVarcharCollationFunctions(ClientContext // replace default collation with system collation auto str_collation = StringType::GetCollation(sql_type); string collation; - if (str_collation.empty()) { + if (str_collation.empty() && type != CollationType::EXPLICIT_COLLATIONS) { collation = Settings::Get(context); } else { collation = str_collation; diff --git a/src/duckdb/src/planner/table_filter_state.cpp b/src/duckdb/src/planner/table_filter_state.cpp index e3dcfe6dc..daf20fd9c 100644 --- a/src/duckdb/src/planner/table_filter_state.cpp +++ b/src/duckdb/src/planner/table_filter_state.cpp @@ -19,6 +19,7 @@ #include "duckdb/storage/table/column_segment.hpp" #include "duckdb/common/shared_ptr_ipp.hpp" #include "duckdb/optimizer/expression_heuristics.hpp" +#include "duckdb/execution/adaptive_filter.hpp" namespace duckdb { @@ -264,10 +265,28 @@ bool ExpressionFilterState::TryFilterDictionary(SelectionVector &sel, Vector &ve return true; } +template +static void FilterConjunction(AdaptiveFilter &adaptive_filter, vector> &children, idx_t &count, + FILTER filter, bool adapt = true) { + if (count == 0) { + return; + } + auto state = adapt ? adaptive_filter.BeginFilter() : AdaptiveFilterState(); + for (auto child_idx : adaptive_filter.GetPermutation()) { + filter(*children[child_idx]); + if (count == 0) { + break; + } + } + if (adapt) { + adaptive_filter.EndFilter(state); + } +} + class ConjunctionAndFilterExecutor final : public ExpressionFilterExecutor { public: - explicit ConjunctionAndFilterExecutor(vector> children_p) - : children(std::move(children_p)) { + ConjunctionAndFilterExecutor(const Expression &expression, vector> children_p) + : children(std::move(children_p)), adaptive_filter(expression) { } bool CanCache() const override { @@ -282,17 +301,15 @@ class ConjunctionAndFilterExecutor final : public ExpressionFilterExecutor { idx_t FilterSelection(SelectionVector &sel, Vector &vector, idx_t scan_count, idx_t &approved_tuple_count) override { - for (auto &child : children) { - child->FilterSelection(sel, vector, scan_count, approved_tuple_count); - if (approved_tuple_count == 0) { - break; - } - } + FilterConjunction(adaptive_filter, children, approved_tuple_count, [&](ExpressionFilterExecutor &child) { + child.FilterSelection(sel, vector, scan_count, approved_tuple_count); + }); return approved_tuple_count; } private: vector> children; + AdaptiveFilter adaptive_filter; }; class OptionalFilterExecutor final : public ExpressionFilterExecutor { @@ -599,7 +616,8 @@ class SelectivityOptionalFilterExecutor final : public ExpressionFilterExecutor class ConjunctionFilterCache final : public TableFilterCache { public: - explicit ConjunctionFilterCache(vector> children_p) : children(std::move(children_p)) { + ConjunctionFilterCache(vector> children_p, AdaptiveFilter &adaptive_filter_p) + : children(std::move(children_p)), adaptive_filter(adaptive_filter_p) { } protected: @@ -613,35 +631,29 @@ class ConjunctionFilterCache final : public TableFilterCache { } void FilterConstantInternal(idx_t value_index, idx_t &count) override { - for (auto &child : children) { - if (count == 0) { - break; - } - child->FilterConstant(value_index, count); - } + // A cached constant only requires a mask lookup per child. + FilterConjunction( + adaptive_filter.get(), children, count, + [&](TableFilterCache &child) { child.FilterConstant(value_index, count); }, false); } void FilterInternal(const SelectionVector &values, SelectionVector &sel, idx_t &count) override { - for (auto &child : children) { - if (count == 0) { - break; - } - child->Filter(values, sel, count); - } + FilterConjunction( + adaptive_filter.get(), children, count, [&](TableFilterCache &child) { child.Filter(values, sel, count); }, + !CanAcceptAllInternal()); } void FilterRunsInternal(const SelectionVector &values, array_ptr row_counts, SelectionVector &sel, idx_t &count) override { - for (auto &child : children) { - if (count == 0) { - break; - } - child->FilterRuns(values, row_counts, sel, count); - } + FilterConjunction( + adaptive_filter.get(), children, count, + [&](TableFilterCache &child) { child.FilterRuns(values, row_counts, sel, count); }, + !CanAcceptAllInternal()); } private: vector> children; + reference adaptive_filter; }; static idx_t CountRunRows(array_ptr row_counts, const SelectionVector &sel, idx_t count) { @@ -733,7 +745,7 @@ unique_ptr ConjunctionAndFilterExecutor::CreateCache(Vector &v for (auto &child : children) { caches.push_back(child->CreateCache(values, count)); } - return make_uniq(std::move(caches)); + return make_uniq(std::move(caches), adaptive_filter); } unique_ptr SelectivityOptionalFilterExecutor::CreateCache(Vector &values, idx_t count) { @@ -1185,7 +1197,7 @@ static unique_ptr TryCreateFastExecutor(const Expressi children.push_back(std::move(filter.executor)); } if (is_and) { - return make_uniq(std::move(children)); + return make_uniq(expression, std::move(children)); } return make_uniq(std::move(children)); } diff --git a/src/duckdb/third_party/yyjson/include/yyjson_memory.hpp b/src/duckdb/third_party/yyjson/include/yyjson_memory.hpp index 9d24624d4..c246e2a3e 100644 --- a/src/duckdb/third_party/yyjson/include/yyjson_memory.hpp +++ b/src/duckdb/third_party/yyjson/include/yyjson_memory.hpp @@ -10,6 +10,9 @@ #include "yyjson.hpp" #include "duckdb/common/optional.hpp" +#include "duckdb/common/vector/array_vector.hpp" +#include "duckdb/common/vector/list_vector.hpp" +#include "duckdb/common/vector/struct_vector.hpp" using namespace duckdb_yyjson; // NOLINT @@ -41,9 +44,25 @@ class JSONAllocator : public enable_shared_from_this { arena_allocator.Reset(); } + //! Retains the allocator in every string vector of a (possibly nested) vector void AddBuffer(Vector &vector) { - if (vector.GetType().InternalType() == PhysicalType::VARCHAR) { + switch (vector.GetType().InternalType()) { + case PhysicalType::VARCHAR: StringVector::AddAuxiliaryData(vector, make_uniq(shared_from_this())); + break; + case PhysicalType::STRUCT: + for (auto &child : StructVector::GetEntries(vector)) { + AddBuffer(child); + } + break; + case PhysicalType::LIST: + AddBuffer(ListVector::GetChildMutable(vector)); + break; + case PhysicalType::ARRAY: + AddBuffer(ArrayVector::GetChildMutable(vector)); + break; + default: + break; } }