duckdb 0.7.2-dev1734.0 → 0.7.2-dev1867.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/duckdb/src/catalog/catalog.cpp +27 -27
- package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +6 -6
- package/src/duckdb/src/catalog/catalog_set.cpp +27 -25
- package/src/duckdb/src/catalog/default/default_functions.cpp +4 -4
- package/src/duckdb/src/catalog/default/default_types.cpp +4 -4
- package/src/duckdb/src/catalog/default/default_views.cpp +4 -4
- package/src/duckdb/src/catalog/dependency_list.cpp +7 -6
- package/src/duckdb/src/catalog/dependency_manager.cpp +44 -38
- package/src/duckdb/src/common/serializer/buffered_file_reader.cpp +11 -6
- package/src/duckdb/src/common/types/batched_data_collection.cpp +2 -1
- package/src/duckdb/src/common/types/column_data_allocator.cpp +1 -0
- package/src/duckdb/src/common/types/vector.cpp +2 -2
- package/src/duckdb/src/common/types.cpp +2 -2
- package/src/duckdb/src/common/vector_operations/vector_copy.cpp +14 -11
- package/src/duckdb/src/execution/operator/aggregate/distinct_aggregate_data.cpp +1 -1
- package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +51 -50
- package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +14 -13
- package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +20 -20
- package/src/duckdb/src/execution/operator/schema/physical_create_table.cpp +2 -2
- package/src/duckdb/src/execution/physical_plan/plan_create_index.cpp +1 -1
- package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +3 -3
- package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +1 -1
- package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +1 -1
- package/src/duckdb/src/execution/physical_plan/plan_update.cpp +1 -1
- package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +3 -3
- package/src/duckdb/src/function/cast/cast_function_set.cpp +2 -1
- package/src/duckdb/src/function/scalar/math/numeric.cpp +57 -0
- package/src/duckdb/src/function/scalar/math_functions.cpp +1 -0
- package/src/duckdb/src/function/scalar/sequence/nextval.cpp +29 -29
- package/src/duckdb/src/function/scalar/string/damerau_levenshtein.cpp +106 -0
- package/src/duckdb/src/function/scalar/string/hex.cpp +261 -78
- package/src/duckdb/src/function/scalar/string/regexp.cpp +145 -28
- package/src/duckdb/src/function/scalar/string_functions.cpp +1 -0
- package/src/duckdb/src/function/table/checkpoint.cpp +4 -4
- package/src/duckdb/src/function/table/system/duckdb_columns.cpp +24 -24
- package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +7 -6
- package/src/duckdb/src/function/table/system/duckdb_databases.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_dependencies.cpp +11 -11
- package/src/duckdb/src/function/table/system/pragma_database_size.cpp +1 -1
- package/src/duckdb/src/function/table/system/pragma_table_info.cpp +17 -18
- package/src/duckdb/src/function/table/table_scan.cpp +8 -11
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +9 -9
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry_map.hpp +38 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_transaction.hpp +4 -3
- package/src/duckdb/src/include/duckdb/catalog/default/default_functions.hpp +2 -2
- package/src/duckdb/src/include/duckdb/catalog/default/default_types.hpp +2 -2
- package/src/duckdb/src/include/duckdb/catalog/default/default_views.hpp +2 -2
- package/src/duckdb/src/include/duckdb/catalog/dependency.hpp +4 -5
- package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +4 -5
- package/src/duckdb/src/include/duckdb/catalog/dependency_manager.hpp +10 -9
- package/src/duckdb/src/include/duckdb/common/allocator.hpp +2 -1
- package/src/duckdb/src/include/duckdb/common/bit_utils.hpp +147 -0
- package/src/duckdb/src/include/duckdb/common/field_writer.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/helper.hpp +9 -0
- package/src/duckdb/src/include/duckdb/common/hugeint.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/optional_ptr.hpp +29 -6
- package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_reader.hpp +6 -5
- package/src/duckdb/src/include/duckdb/common/serializer.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/string_util.hpp +7 -0
- package/src/duckdb/src/include/duckdb/common/types/row_data_collection.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/types.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_insert.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_insert.hpp +5 -5
- package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_create_table.hpp +2 -2
- package/src/duckdb/src/include/duckdb/function/cast/default_casts.hpp +3 -2
- package/src/duckdb/src/include/duckdb/function/scalar/math_functions.hpp +4 -0
- package/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp +4 -0
- package/src/duckdb/src/include/duckdb/main/database_manager.hpp +4 -3
- package/src/duckdb/src/include/duckdb/main/query_result.hpp +3 -2
- package/src/duckdb/src/include/duckdb/optimizer/filter_combiner.hpp +7 -7
- package/src/duckdb/src/include/duckdb/optimizer/matcher/expression_matcher.hpp +11 -11
- package/src/duckdb/src/include/duckdb/optimizer/matcher/set_matcher.hpp +8 -8
- package/src/duckdb/src/include/duckdb/optimizer/rule/arithmetic_simplification.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/case_simplification.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/comparison_simplification.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/conjunction_simplification.hpp +2 -2
- package/src/duckdb/src/include/duckdb/optimizer/rule/constant_folding.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/date_part_simplification.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/distributivity.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/empty_needle_removal.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/enum_comparison.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/equal_or_null_simplification.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/in_clause_simplification.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/like_optimizations.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/move_constants.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/ordered_aggregate_optimizer.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule/regex_optimizations.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/rule.hpp +2 -2
- package/src/duckdb/src/include/duckdb/parser/base_expression.hpp +1 -1
- package/src/duckdb/src/include/duckdb/parser/expression_map.hpp +19 -6
- package/src/duckdb/src/include/duckdb/parser/expression_util.hpp +1 -1
- package/src/duckdb/src/include/duckdb/planner/expression.hpp +5 -2
- package/src/duckdb/src/include/duckdb/planner/expression_binder/base_select_binder.hpp +1 -1
- package/src/duckdb/src/include/duckdb/planner/expression_binder/order_binder.hpp +3 -3
- package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +15 -7
- package/src/duckdb/src/include/duckdb/storage/buffer/buffer_pool.hpp +3 -0
- package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +49 -126
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/chimp128.hpp +1 -0
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/chimp_utils.hpp +0 -97
- package/src/duckdb/src/include/duckdb/storage/compression/patas/algorithm/patas.hpp +1 -0
- package/src/duckdb/src/include/duckdb/storage/meta_block_reader.hpp +5 -5
- package/src/duckdb/src/include/duckdb/storage/standard_buffer_manager.hpp +159 -0
- package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +1 -0
- package/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp +6 -5
- package/src/duckdb/src/main/client_context.cpp +1 -1
- package/src/duckdb/src/main/database.cpp +2 -1
- package/src/duckdb/src/main/database_manager.cpp +4 -4
- package/src/duckdb/src/optimizer/common_aggregate_optimizer.cpp +2 -2
- package/src/duckdb/src/optimizer/cse_optimizer.cpp +4 -4
- package/src/duckdb/src/optimizer/deliminator.cpp +13 -11
- package/src/duckdb/src/optimizer/expression_rewriter.cpp +2 -2
- package/src/duckdb/src/optimizer/filter_combiner.cpp +67 -65
- package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +1 -0
- package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +26 -25
- package/src/duckdb/src/optimizer/matcher/expression_matcher.cpp +23 -21
- package/src/duckdb/src/optimizer/rule/arithmetic_simplification.cpp +3 -3
- package/src/duckdb/src/optimizer/rule/case_simplification.cpp +2 -2
- package/src/duckdb/src/optimizer/rule/comparison_simplification.cpp +6 -7
- package/src/duckdb/src/optimizer/rule/conjunction_simplification.cpp +9 -8
- package/src/duckdb/src/optimizer/rule/constant_folding.cpp +7 -7
- package/src/duckdb/src/optimizer/rule/date_part_simplification.cpp +3 -3
- package/src/duckdb/src/optimizer/rule/distributivity.cpp +5 -5
- package/src/duckdb/src/optimizer/rule/empty_needle_removal.cpp +6 -6
- package/src/duckdb/src/optimizer/rule/enum_comparison.cpp +4 -4
- package/src/duckdb/src/optimizer/rule/equal_or_null_simplification.cpp +23 -26
- package/src/duckdb/src/optimizer/rule/in_clause_simplification_rule.cpp +2 -3
- package/src/duckdb/src/optimizer/rule/like_optimizations.cpp +3 -3
- package/src/duckdb/src/optimizer/rule/move_constants.cpp +6 -6
- package/src/duckdb/src/optimizer/rule/ordered_aggregate_optimizer.cpp +2 -2
- package/src/duckdb/src/optimizer/rule/regex_optimizations.cpp +11 -10
- package/src/duckdb/src/parser/expression_util.cpp +6 -6
- package/src/duckdb/src/parser/transform/helpers/transform_groupby.cpp +3 -3
- package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +2 -2
- package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +3 -3
- package/src/duckdb/src/planner/binder/query_node/bind_setop_node.cpp +5 -5
- package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +2 -2
- package/src/duckdb/src/planner/expression_binder/base_select_binder.cpp +4 -4
- package/src/duckdb/src/planner/expression_binder/order_binder.cpp +3 -3
- package/src/duckdb/src/storage/buffer/block_handle.cpp +7 -6
- package/src/duckdb/src/storage/buffer/block_manager.cpp +3 -1
- package/src/duckdb/src/storage/buffer/buffer_handle.cpp +1 -0
- package/src/duckdb/src/storage/buffer/buffer_pool.cpp +6 -2
- package/src/duckdb/src/storage/buffer/buffer_pool_reservation.cpp +7 -4
- package/src/duckdb/src/storage/buffer_manager.cpp +35 -726
- package/src/duckdb/src/storage/checkpoint_manager.cpp +2 -2
- package/src/duckdb/src/storage/meta_block_reader.cpp +6 -5
- package/src/duckdb/src/storage/standard_buffer_manager.cpp +801 -0
- package/src/duckdb/src/storage/wal_replay.cpp +2 -2
- package/src/duckdb/src/transaction/meta_transaction.cpp +13 -13
- package/src/duckdb/src/transaction/transaction.cpp +1 -1
- package/src/duckdb/src/transaction/transaction_context.cpp +1 -1
- package/src/duckdb/ub_src_function_scalar_string.cpp +2 -0
- package/src/duckdb/ub_src_storage.cpp +2 -0
@@ -10,9 +10,9 @@ namespace duckdb {
|
|
10
10
|
//! The ConstantFoldingExpressionMatcher matches on any scalar expression (i.e. Expression::IsFoldable is true)
|
11
11
|
class ConstantFoldingExpressionMatcher : public FoldableConstantMatcher {
|
12
12
|
public:
|
13
|
-
bool Match(Expression
|
13
|
+
bool Match(Expression &expr, vector<reference<Expression>> &bindings) override {
|
14
14
|
// we also do not match on ConstantExpressions, because we cannot fold those any further
|
15
|
-
if (expr
|
15
|
+
if (expr.type == ExpressionType::VALUE_CONSTANT) {
|
16
16
|
return false;
|
17
17
|
}
|
18
18
|
return FoldableConstantMatcher::Match(expr, bindings);
|
@@ -24,18 +24,18 @@ ConstantFoldingRule::ConstantFoldingRule(ExpressionRewriter &rewriter) : Rule(re
|
|
24
24
|
root = std::move(op);
|
25
25
|
}
|
26
26
|
|
27
|
-
unique_ptr<Expression> ConstantFoldingRule::Apply(LogicalOperator &op, vector<Expression
|
27
|
+
unique_ptr<Expression> ConstantFoldingRule::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
28
28
|
bool &changes_made, bool is_root) {
|
29
|
-
auto root = bindings[0];
|
29
|
+
auto &root = bindings[0].get();
|
30
30
|
// the root is a scalar expression that we have to fold
|
31
|
-
D_ASSERT(root
|
31
|
+
D_ASSERT(root.IsFoldable() && root.type != ExpressionType::VALUE_CONSTANT);
|
32
32
|
|
33
33
|
// use an ExpressionExecutor to execute the expression
|
34
34
|
Value result_value;
|
35
|
-
if (!ExpressionExecutor::TryEvaluateScalar(GetContext(),
|
35
|
+
if (!ExpressionExecutor::TryEvaluateScalar(GetContext(), root, result_value)) {
|
36
36
|
return nullptr;
|
37
37
|
}
|
38
|
-
D_ASSERT(result_value.type().InternalType() == root
|
38
|
+
D_ASSERT(result_value.type().InternalType() == root.return_type.InternalType());
|
39
39
|
// now get the value from the result vector and insert it back into the plan as a constant expression
|
40
40
|
return make_uniq<BoundConstantExpression>(result_value);
|
41
41
|
}
|
@@ -20,10 +20,10 @@ DatePartSimplificationRule::DatePartSimplificationRule(ExpressionRewriter &rewri
|
|
20
20
|
root = std::move(func);
|
21
21
|
}
|
22
22
|
|
23
|
-
unique_ptr<Expression> DatePartSimplificationRule::Apply(LogicalOperator &op, vector<Expression
|
23
|
+
unique_ptr<Expression> DatePartSimplificationRule::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
24
24
|
bool &changes_made, bool is_root) {
|
25
|
-
auto &date_part = bindings[0]
|
26
|
-
auto &constant_expr = bindings[1]
|
25
|
+
auto &date_part = bindings[0].get().Cast<BoundFunctionExpression>();
|
26
|
+
auto &constant_expr = bindings[1].get().Cast<BoundConstantExpression>();
|
27
27
|
auto &constant = constant_expr.value;
|
28
28
|
|
29
29
|
if (constant.IsNull()) {
|
@@ -18,10 +18,10 @@ void DistributivityRule::AddExpressionSet(Expression &expr, expression_set_t &se
|
|
18
18
|
if (expr.type == ExpressionType::CONJUNCTION_AND) {
|
19
19
|
auto &and_expr = expr.Cast<BoundConjunctionExpression>();
|
20
20
|
for (auto &child : and_expr.children) {
|
21
|
-
set.insert(child
|
21
|
+
set.insert(*child);
|
22
22
|
}
|
23
23
|
} else {
|
24
|
-
set.insert(
|
24
|
+
set.insert(expr);
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
@@ -53,9 +53,9 @@ unique_ptr<Expression> DistributivityRule::ExtractExpression(BoundConjunctionExp
|
|
53
53
|
return result;
|
54
54
|
}
|
55
55
|
|
56
|
-
unique_ptr<Expression> DistributivityRule::Apply(LogicalOperator &op, vector<Expression
|
56
|
+
unique_ptr<Expression> DistributivityRule::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
57
57
|
bool &changes_made, bool is_root) {
|
58
|
-
auto &initial_or = bindings[0]
|
58
|
+
auto &initial_or = bindings[0].get().Cast<BoundConjunctionExpression>();
|
59
59
|
|
60
60
|
// we want to find expressions that occur in each of the children of the OR
|
61
61
|
// i.e. (X AND A) OR (X AND B) => X occurs in all branches
|
@@ -88,7 +88,7 @@ unique_ptr<Expression> DistributivityRule::Apply(LogicalOperator &op, vector<Exp
|
|
88
88
|
D_ASSERT(initial_or.children.size() > 0);
|
89
89
|
|
90
90
|
// extract the expression from the first child of the OR
|
91
|
-
auto result = ExtractExpression(initial_or, 0, (
|
91
|
+
auto result = ExtractExpression(initial_or, 0, expr.get());
|
92
92
|
// now for the subsequent expressions, simply remove the expression
|
93
93
|
for (idx_t i = 1; i < initial_or.children.size(); i++) {
|
94
94
|
ExtractExpression(initial_or, i, *result);
|
@@ -21,25 +21,25 @@ EmptyNeedleRemovalRule::EmptyNeedleRemovalRule(ExpressionRewriter &rewriter) : R
|
|
21
21
|
root = std::move(func);
|
22
22
|
}
|
23
23
|
|
24
|
-
unique_ptr<Expression> EmptyNeedleRemovalRule::Apply(LogicalOperator &op, vector<Expression
|
24
|
+
unique_ptr<Expression> EmptyNeedleRemovalRule::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
25
25
|
bool &changes_made, bool is_root) {
|
26
|
-
auto &root = bindings[0]
|
26
|
+
auto &root = bindings[0].get().Cast<BoundFunctionExpression>();
|
27
27
|
D_ASSERT(root.children.size() == 2);
|
28
|
-
auto prefix_expr = bindings[2];
|
28
|
+
auto &prefix_expr = bindings[2].get();
|
29
29
|
|
30
30
|
// the constant_expr is a scalar expression that we have to fold
|
31
|
-
if (!prefix_expr
|
31
|
+
if (!prefix_expr.IsFoldable()) {
|
32
32
|
return nullptr;
|
33
33
|
}
|
34
34
|
D_ASSERT(root.return_type.id() == LogicalTypeId::BOOLEAN);
|
35
35
|
|
36
|
-
auto prefix_value = ExpressionExecutor::EvaluateScalar(GetContext(),
|
36
|
+
auto prefix_value = ExpressionExecutor::EvaluateScalar(GetContext(), prefix_expr);
|
37
37
|
|
38
38
|
if (prefix_value.IsNull()) {
|
39
39
|
return make_uniq<BoundConstantExpression>(Value(LogicalType::BOOLEAN));
|
40
40
|
}
|
41
41
|
|
42
|
-
D_ASSERT(prefix_value.type() == prefix_expr
|
42
|
+
D_ASSERT(prefix_value.type() == prefix_expr.return_type);
|
43
43
|
auto &needle_string = StringValue::Get(prefix_value);
|
44
44
|
|
45
45
|
// PREFIX('xyz', '') is TRUE
|
@@ -44,12 +44,12 @@ bool AreMatchesPossible(LogicalType &left, LogicalType &right) {
|
|
44
44
|
}
|
45
45
|
return false;
|
46
46
|
}
|
47
|
-
unique_ptr<Expression> EnumComparisonRule::Apply(LogicalOperator &op, vector<Expression
|
47
|
+
unique_ptr<Expression> EnumComparisonRule::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
48
48
|
bool &changes_made, bool is_root) {
|
49
49
|
|
50
|
-
auto &root = bindings[0]
|
51
|
-
auto &left_child = bindings[1]
|
52
|
-
auto &right_child = bindings[3]
|
50
|
+
auto &root = bindings[0].get().Cast<BoundComparisonExpression>();
|
51
|
+
auto &left_child = bindings[1].get().Cast<BoundCastExpression>();
|
52
|
+
auto &right_child = bindings[3].get().Cast<BoundCastExpression>();
|
53
53
|
|
54
54
|
if (!AreMatchesPossible(left_child.child->return_type, right_child.child->return_type)) {
|
55
55
|
vector<unique_ptr<Expression>> children;
|
@@ -37,31 +37,30 @@ EqualOrNullSimplification::EqualOrNullSimplification(ExpressionRewriter &rewrite
|
|
37
37
|
}
|
38
38
|
|
39
39
|
// a=b OR (a IS NULL AND b IS NULL) to a IS NOT DISTINCT FROM b
|
40
|
-
static unique_ptr<Expression> TryRewriteEqualOrIsNull(
|
41
|
-
if (equal_expr
|
40
|
+
static unique_ptr<Expression> TryRewriteEqualOrIsNull(Expression &equal_expr, Expression &and_expr) {
|
41
|
+
if (equal_expr.type != ExpressionType::COMPARE_EQUAL || and_expr.type != ExpressionType::CONJUNCTION_AND) {
|
42
42
|
return nullptr;
|
43
43
|
}
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
auto &equal_cast = equal_expr.Cast<BoundComparisonExpression>();
|
46
|
+
auto &and_cast = and_expr.Cast<BoundConjunctionExpression>();
|
47
47
|
|
48
|
-
if (and_cast
|
48
|
+
if (and_cast.children.size() != 2) {
|
49
49
|
return nullptr;
|
50
50
|
}
|
51
51
|
|
52
52
|
// Make sure on the AND conjuction the relevant conditions appear
|
53
|
-
|
54
|
-
|
55
|
-
bool valid = true;
|
53
|
+
auto &a_exp = *equal_cast.left;
|
54
|
+
auto &b_exp = *equal_cast.right;
|
56
55
|
bool a_is_null_found = false;
|
57
56
|
bool b_is_null_found = false;
|
58
57
|
|
59
|
-
for (const auto &item : and_cast
|
60
|
-
|
58
|
+
for (const auto &item : and_cast.children) {
|
59
|
+
auto &next_exp = *item;
|
61
60
|
|
62
|
-
if (next_exp
|
63
|
-
|
64
|
-
|
61
|
+
if (next_exp.type == ExpressionType::OPERATOR_IS_NULL) {
|
62
|
+
auto &next_exp_cast = next_exp.Cast<BoundOperatorExpression>();
|
63
|
+
auto &child = *next_exp_cast.children[0];
|
65
64
|
|
66
65
|
// Test for equality on both 'a' and 'b' expressions
|
67
66
|
if (Expression::Equals(child, a_exp)) {
|
@@ -69,37 +68,35 @@ static unique_ptr<Expression> TryRewriteEqualOrIsNull(const Expression *equal_ex
|
|
69
68
|
} else if (Expression::Equals(child, b_exp)) {
|
70
69
|
b_is_null_found = true;
|
71
70
|
} else {
|
72
|
-
|
73
|
-
break;
|
71
|
+
return nullptr;
|
74
72
|
}
|
75
73
|
} else {
|
76
|
-
|
77
|
-
break;
|
74
|
+
return nullptr;
|
78
75
|
}
|
79
76
|
}
|
80
|
-
if (
|
77
|
+
if (a_is_null_found && b_is_null_found) {
|
81
78
|
return make_uniq<BoundComparisonExpression>(ExpressionType::COMPARE_NOT_DISTINCT_FROM,
|
82
|
-
std::move(equal_cast
|
79
|
+
std::move(equal_cast.left), std::move(equal_cast.right));
|
83
80
|
}
|
84
81
|
return nullptr;
|
85
82
|
}
|
86
83
|
|
87
|
-
unique_ptr<Expression> EqualOrNullSimplification::Apply(LogicalOperator &op, vector<Expression
|
84
|
+
unique_ptr<Expression> EqualOrNullSimplification::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
88
85
|
bool &changes_made, bool is_root) {
|
89
|
-
const Expression
|
86
|
+
const Expression &or_exp = bindings[0].get();
|
90
87
|
|
91
|
-
if (or_exp
|
88
|
+
if (or_exp.type != ExpressionType::CONJUNCTION_OR) {
|
92
89
|
return nullptr;
|
93
90
|
}
|
94
91
|
|
95
|
-
const auto or_exp_cast = (
|
92
|
+
const auto &or_exp_cast = or_exp.Cast<BoundConjunctionExpression>();
|
96
93
|
|
97
|
-
if (or_exp_cast
|
94
|
+
if (or_exp_cast.children.size() != 2) {
|
98
95
|
return nullptr;
|
99
96
|
}
|
100
97
|
|
101
|
-
|
102
|
-
|
98
|
+
auto &left_exp = *or_exp_cast.children[0];
|
99
|
+
auto &right_exp = *or_exp_cast.children[1];
|
103
100
|
// Test for: a=b OR (a IS NULL AND b IS NULL)
|
104
101
|
auto first_try = TryRewriteEqualOrIsNull(left_exp, right_exp);
|
105
102
|
if (first_try) {
|
@@ -12,10 +12,9 @@ InClauseSimplificationRule::InClauseSimplificationRule(ExpressionRewriter &rewri
|
|
12
12
|
root = std::move(op);
|
13
13
|
}
|
14
14
|
|
15
|
-
unique_ptr<Expression> InClauseSimplificationRule::Apply(LogicalOperator &op, vector<Expression
|
15
|
+
unique_ptr<Expression> InClauseSimplificationRule::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
16
16
|
bool &changes_made, bool is_root) {
|
17
|
-
|
18
|
-
auto &expr = bindings[0]->Cast<BoundOperatorExpression>();
|
17
|
+
auto &expr = bindings[0].get().Cast<BoundOperatorExpression>();
|
19
18
|
if (expr.children[0]->expression_class != ExpressionClass::BOUND_CAST) {
|
20
19
|
return nullptr;
|
21
20
|
}
|
@@ -99,10 +99,10 @@ static bool PatternIsContains(const string &pattern) {
|
|
99
99
|
return true;
|
100
100
|
}
|
101
101
|
|
102
|
-
unique_ptr<Expression> LikeOptimizationRule::Apply(LogicalOperator &op, vector<Expression
|
102
|
+
unique_ptr<Expression> LikeOptimizationRule::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
103
103
|
bool &changes_made, bool is_root) {
|
104
|
-
auto &root = bindings[0]
|
105
|
-
auto &constant_expr = bindings[2]
|
104
|
+
auto &root = bindings[0].get().Cast<BoundFunctionExpression>();
|
105
|
+
auto &constant_expr = bindings[2].get().Cast<BoundConstantExpression>();
|
106
106
|
D_ASSERT(root.children.size() == 2);
|
107
107
|
|
108
108
|
if (constant_expr.value.IsNull()) {
|
@@ -28,12 +28,12 @@ MoveConstantsRule::MoveConstantsRule(ExpressionRewriter &rewriter) : Rule(rewrit
|
|
28
28
|
root = std::move(op);
|
29
29
|
}
|
30
30
|
|
31
|
-
unique_ptr<Expression> MoveConstantsRule::Apply(LogicalOperator &op, vector<Expression
|
32
|
-
bool is_root) {
|
33
|
-
auto &comparison = bindings[0]
|
34
|
-
auto &outer_constant = bindings[1]
|
35
|
-
auto &arithmetic = bindings[2]
|
36
|
-
auto &inner_constant = bindings[3]
|
31
|
+
unique_ptr<Expression> MoveConstantsRule::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
32
|
+
bool &changes_made, bool is_root) {
|
33
|
+
auto &comparison = bindings[0].get().Cast<BoundComparisonExpression>();
|
34
|
+
auto &outer_constant = bindings[1].get().Cast<BoundConstantExpression>();
|
35
|
+
auto &arithmetic = bindings[2].get().Cast<BoundFunctionExpression>();
|
36
|
+
auto &inner_constant = bindings[3].get().Cast<BoundConstantExpression>();
|
37
37
|
if (!TypeIsIntegral(arithmetic.return_type.InternalType())) {
|
38
38
|
return nullptr;
|
39
39
|
}
|
@@ -11,9 +11,9 @@ OrderedAggregateOptimizer::OrderedAggregateOptimizer(ExpressionRewriter &rewrite
|
|
11
11
|
root->expr_class = ExpressionClass::BOUND_AGGREGATE;
|
12
12
|
}
|
13
13
|
|
14
|
-
unique_ptr<Expression> OrderedAggregateOptimizer::Apply(LogicalOperator &op, vector<Expression
|
14
|
+
unique_ptr<Expression> OrderedAggregateOptimizer::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
15
15
|
bool &changes_made, bool is_root) {
|
16
|
-
auto &aggr = bindings[0]
|
16
|
+
auto &aggr = bindings[0].get().Cast<BoundAggregateExpression>();
|
17
17
|
if (!aggr.order_bys) {
|
18
18
|
// no ORDER BYs defined
|
19
19
|
return nullptr;
|
@@ -18,10 +18,10 @@ RegexOptimizationRule::RegexOptimizationRule(ExpressionRewriter &rewriter) : Rul
|
|
18
18
|
root = std::move(func);
|
19
19
|
}
|
20
20
|
|
21
|
-
unique_ptr<Expression> RegexOptimizationRule::Apply(LogicalOperator &op, vector<Expression
|
21
|
+
unique_ptr<Expression> RegexOptimizationRule::Apply(LogicalOperator &op, vector<reference<Expression>> &bindings,
|
22
22
|
bool &changes_made, bool is_root) {
|
23
|
-
auto &root = bindings[0]
|
24
|
-
auto &constant_expr = bindings[2]
|
23
|
+
auto &root = bindings[0].get().Cast<BoundFunctionExpression>();
|
24
|
+
auto &constant_expr = bindings[2].get().Cast<BoundConstantExpression>();
|
25
25
|
D_ASSERT(root.children.size() == 2);
|
26
26
|
|
27
27
|
if (constant_expr.value.IsNull()) {
|
@@ -44,17 +44,18 @@ unique_ptr<Expression> RegexOptimizationRule::Apply(LogicalOperator &op, vector<
|
|
44
44
|
|
45
45
|
if (pattern.Regexp()->op() == duckdb_re2::kRegexpLiteralString ||
|
46
46
|
pattern.Regexp()->op() == duckdb_re2::kRegexpLiteral) {
|
47
|
-
auto contains = make_uniq<BoundFunctionExpression>(root.return_type, ContainsFun::GetFunction(),
|
48
|
-
std::move(root.children), nullptr);
|
49
47
|
|
50
48
|
string min;
|
51
49
|
string max;
|
52
|
-
pattern.PossibleMatchRange(&min, &max, patt_str.size());
|
53
|
-
if (min
|
54
|
-
|
55
|
-
} else {
|
56
|
-
contains->children[1] = make_uniq<BoundConstantExpression>(Value(std::move(patt_str)));
|
50
|
+
pattern.PossibleMatchRange(&min, &max, patt_str.size() + 1);
|
51
|
+
if (min != max) {
|
52
|
+
return nullptr;
|
57
53
|
}
|
54
|
+
auto parameter = make_uniq<BoundConstantExpression>(Value(std::move(min)));
|
55
|
+
auto contains = make_uniq<BoundFunctionExpression>(root.return_type, ContainsFun::GetFunction(),
|
56
|
+
std::move(root.children), nullptr);
|
57
|
+
contains->children[1] = std::move(parameter);
|
58
|
+
|
58
59
|
return std::move(contains);
|
59
60
|
}
|
60
61
|
return nullptr;
|
@@ -18,7 +18,7 @@ bool ExpressionUtil::ExpressionListEquals(const vector<unique_ptr<T>> &a, const
|
|
18
18
|
return true;
|
19
19
|
}
|
20
20
|
|
21
|
-
template <class T>
|
21
|
+
template <class T, class EXPRESSION_MAP>
|
22
22
|
bool ExpressionUtil::ExpressionSetEquals(const vector<unique_ptr<T>> &a, const vector<unique_ptr<T>> &b) {
|
23
23
|
if (a.size() != b.size()) {
|
24
24
|
return false;
|
@@ -26,14 +26,14 @@ bool ExpressionUtil::ExpressionSetEquals(const vector<unique_ptr<T>> &a, const v
|
|
26
26
|
// we create a map of expression -> count for the left side
|
27
27
|
// we keep the count because the same expression can occur multiple times (e.g. "1 AND 1" is legal)
|
28
28
|
// in this case we track the following value: map["Constant(1)"] = 2
|
29
|
-
|
29
|
+
EXPRESSION_MAP map;
|
30
30
|
for (idx_t i = 0; i < a.size(); i++) {
|
31
|
-
map[a[i]
|
31
|
+
map[*a[i]]++;
|
32
32
|
}
|
33
33
|
// now on the right side we reduce the counts again
|
34
34
|
// if the conjunctions are identical, all the counts will be 0 after the
|
35
35
|
for (auto &expr : b) {
|
36
|
-
auto entry = map.find(expr
|
36
|
+
auto entry = map.find(*expr);
|
37
37
|
// first we check if we can find the expression in the map at all
|
38
38
|
if (entry == map.end()) {
|
39
39
|
return false;
|
@@ -62,11 +62,11 @@ bool ExpressionUtil::ListEquals(const vector<unique_ptr<Expression>> &a, const v
|
|
62
62
|
|
63
63
|
bool ExpressionUtil::SetEquals(const vector<unique_ptr<ParsedExpression>> &a,
|
64
64
|
const vector<unique_ptr<ParsedExpression>> &b) {
|
65
|
-
return ExpressionSetEquals<ParsedExpression
|
65
|
+
return ExpressionSetEquals<ParsedExpression, parsed_expression_map_t<idx_t>>(a, b);
|
66
66
|
}
|
67
67
|
|
68
68
|
bool ExpressionUtil::SetEquals(const vector<unique_ptr<Expression>> &a, const vector<unique_ptr<Expression>> &b) {
|
69
|
-
return ExpressionSetEquals<Expression
|
69
|
+
return ExpressionSetEquals<Expression, expression_map_t<idx_t>>(a, b);
|
70
70
|
}
|
71
71
|
|
72
72
|
} // namespace duckdb
|
@@ -22,7 +22,7 @@ static void CheckGroupingSetCubes(idx_t current_count, idx_t cube_count) {
|
|
22
22
|
}
|
23
23
|
|
24
24
|
struct GroupingExpressionMap {
|
25
|
-
|
25
|
+
parsed_expression_map_t<idx_t> map;
|
26
26
|
};
|
27
27
|
|
28
28
|
static GroupingSet VectorToGroupingSet(vector<idx_t> &indexes) {
|
@@ -49,11 +49,11 @@ void Transformer::AddGroupByExpression(unique_ptr<ParsedExpression> expression,
|
|
49
49
|
return;
|
50
50
|
}
|
51
51
|
}
|
52
|
-
auto entry = map.map.find(expression
|
52
|
+
auto entry = map.map.find(*expression);
|
53
53
|
idx_t result_idx;
|
54
54
|
if (entry == map.map.end()) {
|
55
55
|
result_idx = result.group_expressions.size();
|
56
|
-
map.map[expression
|
56
|
+
map.map[*expression] = result_idx;
|
57
57
|
result.group_expressions.push_back(std::move(expression));
|
58
58
|
} else {
|
59
59
|
result_idx = entry->second;
|
@@ -233,11 +233,11 @@ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFu
|
|
233
233
|
|
234
234
|
// check for all the aggregates if this aggregate already exists
|
235
235
|
idx_t aggr_index;
|
236
|
-
auto entry = node.aggregate_map.find(aggregate
|
236
|
+
auto entry = node.aggregate_map.find(*aggregate);
|
237
237
|
if (entry == node.aggregate_map.end()) {
|
238
238
|
// new aggregate: insert into aggregate list
|
239
239
|
aggr_index = node.aggregates.size();
|
240
|
-
node.aggregate_map
|
240
|
+
node.aggregate_map[*aggregate] = aggr_index;
|
241
241
|
node.aggregates.push_back(std::move(aggregate));
|
242
242
|
} else {
|
243
243
|
// duplicate aggregate: simplify refer to this aggregate
|
@@ -329,7 +329,7 @@ unique_ptr<BoundQueryNode> Binder::BindSelectNode(SelectNode &statement, unique_
|
|
329
329
|
|
330
330
|
// create a mapping of (alias -> index) and a mapping of (Expression -> index) for the SELECT list
|
331
331
|
case_insensitive_map_t<idx_t> alias_map;
|
332
|
-
|
332
|
+
parsed_expression_map_t<idx_t> projection_map;
|
333
333
|
for (idx_t i = 0; i < statement.select_list.size(); i++) {
|
334
334
|
auto &expr = statement.select_list[i];
|
335
335
|
result->names.push_back(expr->GetName());
|
@@ -338,7 +338,7 @@ unique_ptr<BoundQueryNode> Binder::BindSelectNode(SelectNode &statement, unique_
|
|
338
338
|
alias_map[expr->alias] = i;
|
339
339
|
result->names[i] = expr->alias;
|
340
340
|
}
|
341
|
-
projection_map[expr
|
341
|
+
projection_map[*expr] = i;
|
342
342
|
result->original_expressions.push_back(expr->Copy());
|
343
343
|
}
|
344
344
|
result->column_count = statement.select_list.size();
|
@@ -391,7 +391,7 @@ unique_ptr<BoundQueryNode> Binder::BindSelectNode(SelectNode &statement, unique_
|
|
391
391
|
// hence we convert "a" -> "test.a" in the unbound expression
|
392
392
|
unbound_groups[i] = std::move(group_binder.unbound_expression);
|
393
393
|
ExpressionBinder::QualifyColumnNames(*this, unbound_groups[i]);
|
394
|
-
info.map[unbound_groups[i]
|
394
|
+
info.map[*unbound_groups[i]] = i;
|
395
395
|
}
|
396
396
|
}
|
397
397
|
result->groups.grouping_sets = std::move(statement.groups.grouping_sets);
|
@@ -13,7 +13,7 @@
|
|
13
13
|
namespace duckdb {
|
14
14
|
|
15
15
|
static void GatherAliases(BoundQueryNode &node, case_insensitive_map_t<idx_t> &aliases,
|
16
|
-
|
16
|
+
parsed_expression_map_t<idx_t> &expressions, const vector<idx_t> &reorder_idx) {
|
17
17
|
if (node.type == QueryNodeType::SET_OPERATION_NODE) {
|
18
18
|
// setop, recurse
|
19
19
|
auto &setop = node.Cast<BoundSetOperationNode>();
|
@@ -66,16 +66,16 @@ static void GatherAliases(BoundQueryNode &node, case_insensitive_map_t<idx_t> &a
|
|
66
66
|
aliases[name] = index;
|
67
67
|
}
|
68
68
|
// now check if the node is already in the set of expressions
|
69
|
-
auto expr_entry = expressions.find(expr
|
69
|
+
auto expr_entry = expressions.find(*expr);
|
70
70
|
if (expr_entry != expressions.end()) {
|
71
71
|
// the node is in there
|
72
72
|
// repeat the same as with the alias: if there is an ambiguity we insert "-1"
|
73
73
|
if (expr_entry->second != index) {
|
74
|
-
expressions[expr
|
74
|
+
expressions[*expr] = DConstants::INVALID_INDEX;
|
75
75
|
}
|
76
76
|
} else {
|
77
77
|
// not in there yet, just place it in there
|
78
|
-
expressions[expr
|
78
|
+
expressions[*expr] = index;
|
79
79
|
}
|
80
80
|
}
|
81
81
|
}
|
@@ -240,7 +240,7 @@ unique_ptr<BoundQueryNode> Binder::BindNode(SetOperationNode &statement) {
|
|
240
240
|
// we recursively visit the children of this node to extract aliases and expressions that can be referenced
|
241
241
|
// in the ORDER BY
|
242
242
|
case_insensitive_map_t<idx_t> alias_map;
|
243
|
-
|
243
|
+
parsed_expression_map_t<idx_t> expression_map;
|
244
244
|
|
245
245
|
if (result->setop_type == SetOperationType::UNION_BY_NAME) {
|
246
246
|
GatherAliases(*result->left, alias_map, expression_map, result->left_reorder_idx);
|
@@ -297,10 +297,10 @@ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateIn
|
|
297
297
|
auto type_dependency = LogicalType::GetCatalog(column.Type());
|
298
298
|
if (type_dependency) {
|
299
299
|
// Only if the USER comes from a create type
|
300
|
-
result->dependencies.AddDependency(type_dependency);
|
300
|
+
result->dependencies.AddDependency(*type_dependency);
|
301
301
|
}
|
302
302
|
}
|
303
|
-
result->dependencies.VerifyDependencies(schema->catalog, result->Base().table);
|
303
|
+
result->dependencies.VerifyDependencies(*schema->catalog, result->Base().table);
|
304
304
|
properties.allow_stream_result = false;
|
305
305
|
return result;
|
306
306
|
}
|
@@ -56,14 +56,14 @@ idx_t BaseSelectBinder::TryBindGroup(ParsedExpression &expr, idx_t depth) {
|
|
56
56
|
}
|
57
57
|
// no alias reference found
|
58
58
|
// check the list of group columns for a match
|
59
|
-
auto entry = info.map.find(
|
59
|
+
auto entry = info.map.find(expr);
|
60
60
|
if (entry != info.map.end()) {
|
61
61
|
return entry->second;
|
62
62
|
}
|
63
63
|
#ifdef DEBUG
|
64
64
|
for (auto entry : info.map) {
|
65
|
-
D_ASSERT(!entry.first
|
66
|
-
D_ASSERT(!expr.Equals(entry.first));
|
65
|
+
D_ASSERT(!entry.first.get().Equals(&expr));
|
66
|
+
D_ASSERT(!expr.Equals(&entry.first.get()));
|
67
67
|
}
|
68
68
|
#endif
|
69
69
|
return DConstants::INVALID_INDEX;
|
@@ -77,7 +77,7 @@ BindResult BaseSelectBinder::BindColumnRef(unique_ptr<ParsedExpression> *expr_pt
|
|
77
77
|
}
|
78
78
|
// binding failed
|
79
79
|
// check in the alias map
|
80
|
-
auto &colref = (ColumnRefExpression
|
80
|
+
auto &colref = (*expr_ptr)->Cast<ColumnRefExpression>();
|
81
81
|
if (!colref.IsQualified()) {
|
82
82
|
auto alias_entry = alias_map.find(colref.column_names[0]);
|
83
83
|
if (alias_entry != alias_map.end()) {
|
@@ -13,12 +13,12 @@
|
|
13
13
|
namespace duckdb {
|
14
14
|
|
15
15
|
OrderBinder::OrderBinder(vector<Binder *> binders, idx_t projection_index, case_insensitive_map_t<idx_t> &alias_map,
|
16
|
-
|
16
|
+
parsed_expression_map_t<idx_t> &projection_map, idx_t max_count)
|
17
17
|
: binders(std::move(binders)), projection_index(projection_index), max_count(max_count), extra_list(nullptr),
|
18
18
|
alias_map(alias_map), projection_map(projection_map) {
|
19
19
|
}
|
20
20
|
OrderBinder::OrderBinder(vector<Binder *> binders, idx_t projection_index, SelectNode &node,
|
21
|
-
case_insensitive_map_t<idx_t> &alias_map,
|
21
|
+
case_insensitive_map_t<idx_t> &alias_map, parsed_expression_map_t<idx_t> &projection_map)
|
22
22
|
: binders(std::move(binders)), projection_index(projection_index), alias_map(alias_map),
|
23
23
|
projection_map(projection_map) {
|
24
24
|
this->max_count = node.select_list.size();
|
@@ -111,7 +111,7 @@ unique_ptr<Expression> OrderBinder::Bind(unique_ptr<ParsedExpression> expr) {
|
|
111
111
|
ExpressionBinder::QualifyColumnNames(*binder, expr);
|
112
112
|
}
|
113
113
|
// first check if the ORDER BY clause already points to an entry in the projection list
|
114
|
-
auto entry = projection_map.find(expr
|
114
|
+
auto entry = projection_map.find(*expr);
|
115
115
|
if (entry != projection_map.end()) {
|
116
116
|
if (entry->second == DConstants::INVALID_INDEX) {
|
117
117
|
throw BinderException("Ambiguous reference to column");
|
@@ -3,13 +3,14 @@
|
|
3
3
|
#include "duckdb/storage/block_manager.hpp"
|
4
4
|
#include "duckdb/storage/buffer/buffer_handle.hpp"
|
5
5
|
#include "duckdb/storage/buffer_manager.hpp"
|
6
|
+
#include "duckdb/storage/buffer/buffer_pool.hpp"
|
6
7
|
#include "duckdb/common/file_buffer.hpp"
|
7
8
|
|
8
9
|
namespace duckdb {
|
9
10
|
|
10
11
|
BlockHandle::BlockHandle(BlockManager &block_manager, block_id_t block_id_p)
|
11
12
|
: block_manager(block_manager), readers(0), block_id(block_id_p), buffer(nullptr), eviction_timestamp(0),
|
12
|
-
can_destroy(false), unswizzled(nullptr) {
|
13
|
+
can_destroy(false), memory_charge(block_manager.buffer_manager.GetBufferPool()), unswizzled(nullptr) {
|
13
14
|
eviction_timestamp = 0;
|
14
15
|
state = BlockState::BLOCK_UNLOADED;
|
15
16
|
memory_usage = Storage::BLOCK_ALLOC_SIZE;
|
@@ -18,7 +19,7 @@ BlockHandle::BlockHandle(BlockManager &block_manager, block_id_t block_id_p)
|
|
18
19
|
BlockHandle::BlockHandle(BlockManager &block_manager, block_id_t block_id_p, unique_ptr<FileBuffer> buffer_p,
|
19
20
|
bool can_destroy_p, idx_t block_size, BufferPoolReservation &&reservation)
|
20
21
|
: block_manager(block_manager), readers(0), block_id(block_id_p), eviction_timestamp(0), can_destroy(can_destroy_p),
|
21
|
-
unswizzled(nullptr) {
|
22
|
+
memory_charge(block_manager.buffer_manager.GetBufferPool()), unswizzled(nullptr) {
|
22
23
|
buffer = std::move(buffer_p);
|
23
24
|
state = BlockState::BLOCK_LOADED;
|
24
25
|
memory_usage = block_size;
|
@@ -34,11 +35,11 @@ BlockHandle::~BlockHandle() { // NOLINT: allow internal exceptions
|
|
34
35
|
D_ASSERT(memory_charge.size > 0);
|
35
36
|
// the block is still loaded in memory: erase it
|
36
37
|
buffer.reset();
|
37
|
-
memory_charge.Resize(
|
38
|
+
memory_charge.Resize(0);
|
38
39
|
} else {
|
39
40
|
D_ASSERT(memory_charge.size == 0);
|
40
41
|
}
|
41
|
-
buffer_manager.
|
42
|
+
buffer_manager.GetBufferPool().PurgeQueue();
|
42
43
|
block_manager.UnregisterBlock(block_id, can_destroy);
|
43
44
|
}
|
44
45
|
|
@@ -97,7 +98,7 @@ unique_ptr<FileBuffer> BlockHandle::UnloadAndTakeBlock() {
|
|
97
98
|
// temporary block that cannot be destroyed: write to temporary file
|
98
99
|
block_manager.buffer_manager.WriteTemporaryBuffer(block_id, *buffer);
|
99
100
|
}
|
100
|
-
memory_charge.Resize(
|
101
|
+
memory_charge.Resize(0);
|
101
102
|
state = BlockState::BLOCK_UNLOADED;
|
102
103
|
return std::move(buffer);
|
103
104
|
}
|
@@ -116,7 +117,7 @@ bool BlockHandle::CanUnload() {
|
|
116
117
|
// there are active readers
|
117
118
|
return false;
|
118
119
|
}
|
119
|
-
if (block_id >= MAXIMUM_BLOCK && !can_destroy && block_manager.buffer_manager.
|
120
|
+
if (block_id >= MAXIMUM_BLOCK && !can_destroy && !block_manager.buffer_manager.HasTemporaryDirectory()) {
|
120
121
|
// in order to unload this block we need to write it to a temporary buffer
|
121
122
|
// however, no temporary directory is specified!
|
122
123
|
// hence we cannot unload the block
|
@@ -1,5 +1,7 @@
|
|
1
1
|
#include "duckdb/storage/block_manager.hpp"
|
2
2
|
#include "duckdb/storage/buffer_manager.hpp"
|
3
|
+
#include "duckdb/storage/buffer/block_handle.hpp"
|
4
|
+
#include "duckdb/storage/buffer/buffer_pool.hpp"
|
3
5
|
|
4
6
|
namespace duckdb {
|
5
7
|
|
@@ -62,7 +64,7 @@ shared_ptr<BlockHandle> BlockManager::ConvertToPersistent(block_id_t block_id, s
|
|
62
64
|
// persist the new block to disk
|
63
65
|
Write(*new_block->buffer, block_id);
|
64
66
|
|
65
|
-
buffer_manager.
|
67
|
+
buffer_manager.GetBufferPool().AddToEvictionQueue(new_block);
|
66
68
|
|
67
69
|
return new_block;
|
68
70
|
}
|