duckdb 0.7.2-dev402.0 → 0.7.2-dev586.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.
Files changed (105) hide show
  1. package/binding.gyp +9 -9
  2. package/package.json +1 -1
  3. package/src/duckdb/extension/parquet/include/parquet_timestamp.hpp +0 -1
  4. package/src/duckdb/extension/parquet/parquet-extension.cpp +1 -0
  5. package/src/duckdb/extension/parquet/parquet_timestamp.cpp +8 -6
  6. package/src/duckdb/src/catalog/catalog.cpp +13 -0
  7. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +2 -21
  8. package/src/duckdb/src/catalog/catalog_entry/type_catalog_entry.cpp +8 -2
  9. package/src/duckdb/src/catalog/catalog_set.cpp +1 -0
  10. package/src/duckdb/src/common/arrow/arrow_appender.cpp +48 -4
  11. package/src/duckdb/src/common/arrow/arrow_converter.cpp +1 -1
  12. package/src/duckdb/src/common/field_writer.cpp +1 -0
  13. package/src/duckdb/src/common/serializer/buffered_deserializer.cpp +4 -0
  14. package/src/duckdb/src/common/serializer/buffered_file_reader.cpp +15 -2
  15. package/src/duckdb/src/common/types.cpp +136 -53
  16. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +20 -40
  17. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +9 -1
  18. package/src/duckdb/src/execution/physical_plan/plan_distinct.cpp +5 -8
  19. package/src/duckdb/src/function/aggregate/distributive/bool.cpp +2 -0
  20. package/src/duckdb/src/function/aggregate/distributive/count.cpp +1 -0
  21. package/src/duckdb/src/function/aggregate/distributive/minmax.cpp +2 -0
  22. package/src/duckdb/src/function/aggregate/distributive/sum.cpp +8 -0
  23. package/src/duckdb/src/function/aggregate/holistic/quantile.cpp +15 -0
  24. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +42 -11
  25. package/src/duckdb/src/function/function_binder.cpp +1 -8
  26. package/src/duckdb/src/function/scalar/date/current.cpp +0 -2
  27. package/src/duckdb/src/function/table/arrow.cpp +3 -0
  28. package/src/duckdb/src/function/table/arrow_conversion.cpp +18 -0
  29. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  30. package/src/duckdb/src/function/table_function.cpp +11 -11
  31. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +3 -0
  32. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +1 -1
  33. package/src/duckdb/src/include/duckdb/common/field_writer.hpp +12 -4
  34. package/src/duckdb/src/include/duckdb/common/{http_stats.hpp → http_state.hpp} +18 -4
  35. package/src/duckdb/src/include/duckdb/common/serializer/buffered_deserializer.hpp +4 -2
  36. package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_reader.hpp +8 -2
  37. package/src/duckdb/src/include/duckdb/common/serializer.hpp +13 -0
  38. package/src/duckdb/src/include/duckdb/common/types.hpp +27 -1
  39. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_file_handle.hpp +1 -0
  40. package/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp +0 -3
  41. package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +6 -3
  42. package/src/duckdb/src/include/duckdb/function/function_binder.hpp +3 -6
  43. package/src/duckdb/src/include/duckdb/function/table/arrow.hpp +12 -1
  44. package/src/duckdb/src/include/duckdb/function/table_function.hpp +8 -0
  45. package/src/duckdb/src/include/duckdb/main/client_data.hpp +3 -3
  46. package/src/duckdb/src/include/duckdb/main/connection_manager.hpp +2 -0
  47. package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +1 -0
  48. package/src/duckdb/src/include/duckdb/optimizer/rule/list.hpp +1 -0
  49. package/src/duckdb/src/include/duckdb/optimizer/rule/ordered_aggregate_optimizer.hpp +24 -0
  50. package/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp +2 -2
  51. package/src/duckdb/src/include/duckdb/parser/expression/star_expression.hpp +2 -2
  52. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +3 -0
  53. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +6 -0
  54. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +2 -0
  55. package/src/duckdb/src/include/duckdb/planner/binder.hpp +4 -3
  56. package/src/duckdb/src/include/duckdb/planner/bound_result_modifier.hpp +3 -0
  57. package/src/duckdb/src/include/duckdb/planner/expression/bound_aggregate_expression.hpp +3 -0
  58. package/src/duckdb/src/include/duckdb/planner/expression_binder/order_binder.hpp +4 -1
  59. package/src/duckdb/src/include/duckdb/planner/operator/logical_distinct.hpp +3 -0
  60. package/src/duckdb/src/include/duckdb/storage/checkpoint_manager.hpp +1 -1
  61. package/src/duckdb/src/include/duckdb/storage/meta_block_reader.hpp +7 -0
  62. package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +1 -1
  63. package/src/duckdb/src/main/client_context.cpp +30 -32
  64. package/src/duckdb/src/main/client_data.cpp +7 -6
  65. package/src/duckdb/src/main/database.cpp +9 -0
  66. package/src/duckdb/src/main/query_profiler.cpp +17 -15
  67. package/src/duckdb/src/optimizer/optimizer.cpp +1 -0
  68. package/src/duckdb/src/optimizer/rule/ordered_aggregate_optimizer.cpp +30 -0
  69. package/src/duckdb/src/optimizer/rule/regex_optimizations.cpp +9 -2
  70. package/src/duckdb/src/parser/expression/star_expression.cpp +6 -6
  71. package/src/duckdb/src/parser/parsed_expression_iterator.cpp +7 -1
  72. package/src/duckdb/src/parser/transform/expression/transform_columnref.cpp +17 -2
  73. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +45 -40
  74. package/src/duckdb/src/parser/transform/helpers/transform_groupby.cpp +7 -0
  75. package/src/duckdb/src/parser/transform/helpers/transform_orderby.cpp +0 -7
  76. package/src/duckdb/src/parser/transform/statement/transform_rename.cpp +3 -4
  77. package/src/duckdb/src/planner/bind_context.cpp +2 -25
  78. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +6 -4
  79. package/src/duckdb/src/planner/binder/expression/bind_lambda.cpp +3 -2
  80. package/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp +176 -0
  81. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +57 -82
  82. package/src/duckdb/src/planner/binder/query_node/plan_query_node.cpp +11 -0
  83. package/src/duckdb/src/planner/binder/statement/bind_delete.cpp +1 -1
  84. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +2 -2
  85. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +1 -1
  86. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +11 -1
  87. package/src/duckdb/src/planner/binder.cpp +12 -23
  88. package/src/duckdb/src/planner/bound_result_modifier.cpp +26 -0
  89. package/src/duckdb/src/planner/expression/bound_aggregate_expression.cpp +9 -2
  90. package/src/duckdb/src/planner/expression_iterator.cpp +5 -0
  91. package/src/duckdb/src/planner/logical_operator.cpp +4 -2
  92. package/src/duckdb/src/planner/logical_operator_visitor.cpp +5 -0
  93. package/src/duckdb/src/planner/operator/logical_distinct.cpp +3 -0
  94. package/src/duckdb/src/planner/planner.cpp +2 -1
  95. package/src/duckdb/src/storage/checkpoint_manager.cpp +8 -3
  96. package/src/duckdb/src/storage/meta_block_reader.cpp +22 -0
  97. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  98. package/src/duckdb/src/storage/wal_replay.cpp +8 -5
  99. package/src/duckdb/src/storage/write_ahead_log.cpp +2 -2
  100. package/src/duckdb/src/transaction/commit_state.cpp +11 -7
  101. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +1 -1
  102. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +8145 -8317
  103. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +4 -4
  104. package/src/duckdb/ub_src_optimizer_rule.cpp +2 -0
  105. package/src/duckdb/ub_src_planner_binder_expression.cpp +2 -0
@@ -59,13 +59,10 @@ public:
59
59
  DUCKDB_API unique_ptr<BoundAggregateExpression>
60
60
  BindAggregateFunction(AggregateFunction bound_function, vector<unique_ptr<Expression>> children,
61
61
  unique_ptr<Expression> filter = nullptr,
62
- AggregateType aggr_type = AggregateType::NON_DISTINCT,
63
- unique_ptr<BoundOrderModifier> order_bys = nullptr);
62
+ AggregateType aggr_type = AggregateType::NON_DISTINCT);
64
63
 
65
- DUCKDB_API unique_ptr<FunctionData> BindSortedAggregate(AggregateFunction &bound_function,
66
- vector<unique_ptr<Expression>> &children,
67
- unique_ptr<FunctionData> bind_info,
68
- unique_ptr<BoundOrderModifier> order_bys);
64
+ DUCKDB_API static void BindSortedAggregate(ClientContext &context, BoundAggregateExpression &expr,
65
+ const vector<unique_ptr<Expression>> &groups);
69
66
 
70
67
  private:
71
68
  //! Cast a set of expressions to the arguments of this function
@@ -32,7 +32,18 @@ enum class ArrowDateTimeType : uint8_t {
32
32
  NANOSECONDS = 2,
33
33
  SECONDS = 3,
34
34
  DAYS = 4,
35
- MONTHS = 5
35
+ MONTHS = 5,
36
+ MONTH_DAY_NANO = 6
37
+ };
38
+
39
+ struct ArrowInterval {
40
+ int32_t months;
41
+ int32_t days;
42
+ int64_t nanoseconds;
43
+
44
+ inline bool operator==(const ArrowInterval &rhs) const {
45
+ return this->days == rhs.days && this->months == rhs.months && this->nanoseconds == rhs.nanoseconds;
46
+ }
36
47
  };
37
48
 
38
49
  struct ArrowConvertData {
@@ -11,6 +11,8 @@
11
11
  #include "duckdb/common/enums/operator_result_type.hpp"
12
12
  #include "duckdb/execution/execution_context.hpp"
13
13
  #include "duckdb/function/function.hpp"
14
+ #include "duckdb/planner/bind_context.hpp"
15
+ #include "duckdb/planner/logical_operator.hpp"
14
16
  #include "duckdb/storage/statistics/node_statistics.hpp"
15
17
 
16
18
  #include <functional>
@@ -136,6 +138,7 @@ public:
136
138
 
137
139
  typedef unique_ptr<FunctionData> (*table_function_bind_t)(ClientContext &context, TableFunctionBindInput &input,
138
140
  vector<LogicalType> &return_types, vector<string> &names);
141
+ typedef unique_ptr<TableRef> (*table_function_bind_replace_t)(ClientContext &context, TableFunctionBindInput &input);
139
142
  typedef unique_ptr<GlobalTableFunctionState> (*table_function_init_global_t)(ClientContext &context,
140
143
  TableFunctionInitInput &input);
141
144
  typedef unique_ptr<LocalTableFunctionState> (*table_function_init_local_t)(ExecutionContext &context,
@@ -185,6 +188,11 @@ public:
185
188
  //! This function is used for determining the return type of a table producing function and returning bind data
186
189
  //! The returned FunctionData object should be constant and should not be changed during execution.
187
190
  table_function_bind_t bind;
191
+ //! (Optional) Bind replace function
192
+ //! This function is called before the regular bind function. It allows returning a TableRef will be used to
193
+ //! to generate a logical plan that replaces the LogicalGet of a regularly bound TableFunction. The BindReplace can
194
+ //! also return a nullptr to indicate a regular bind needs to be performed instead.
195
+ table_function_bind_replace_t bind_replace;
188
196
  //! (Optional) global init function
189
197
  //! Initialize the global operator state of the function.
190
198
  //! The global operator state is used to keep track of the progress in the table function and is shared between
@@ -20,7 +20,7 @@ class BufferedFileWriter;
20
20
  class ClientContext;
21
21
  class CatalogSearchPath;
22
22
  class FileOpener;
23
- class HTTPStats;
23
+ class HTTPState;
24
24
  class QueryProfiler;
25
25
  class QueryProfilerHistory;
26
26
  class PreparedStatementData;
@@ -52,8 +52,8 @@ struct ClientData {
52
52
  //! The file opener of the client context
53
53
  unique_ptr<FileOpener> file_opener;
54
54
 
55
- //! Statistics on HTTP traffic
56
- unique_ptr<HTTPStats> http_stats;
55
+ //! HTTP State in this query
56
+ unique_ptr<HTTPState> http_state;
57
57
 
58
58
  //! The file search path
59
59
  string file_search_path;
@@ -47,6 +47,8 @@ public:
47
47
  return result;
48
48
  }
49
49
 
50
+ ClientContext *GetConnection(DatabaseInstance *db);
51
+
50
52
  static ConnectionManager &Get(DatabaseInstance &db);
51
53
  static ConnectionManager &Get(ClientContext &context);
52
54
 
@@ -96,6 +96,7 @@ static constexpr ExtensionEntry EXTENSION_SETTINGS[] = {
96
96
  {"http_retry_backoff", "httpfs"},
97
97
  {"http_retry_wait_ms", "httpfs"},
98
98
  {"http_timeout", "httpfs"},
99
+ {"force_download", "httpfs"},
99
100
  {"s3_access_key_id", "httpfs"},
100
101
  {"s3_endpoint", "httpfs"},
101
102
  {"s3_region", "httpfs"},
@@ -10,3 +10,4 @@
10
10
  #include "duckdb/optimizer/rule/move_constants.hpp"
11
11
  #include "duckdb/optimizer/rule/enum_comparison.hpp"
12
12
  #include "duckdb/optimizer/rule/regex_optimizations.hpp"
13
+ #include "duckdb/optimizer/rule/ordered_aggregate_optimizer.hpp"
@@ -0,0 +1,24 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/optimizer/rule/ordered_aggregate_optimizer.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/optimizer/rule.hpp"
12
+ #include "duckdb/parser/expression_map.hpp"
13
+
14
+ namespace duckdb {
15
+
16
+ class OrderedAggregateOptimizer : public Rule {
17
+ public:
18
+ explicit OrderedAggregateOptimizer(ExpressionRewriter &rewriter);
19
+
20
+ unique_ptr<Expression> Apply(LogicalOperator &op, vector<Expression *> &bindings, bool &changes_made,
21
+ bool is_root) override;
22
+ };
23
+
24
+ } // namespace duckdb
@@ -59,9 +59,9 @@ public:
59
59
  void Verify() const override;
60
60
 
61
61
  public:
62
- template <class T, class BASE>
62
+ template <class T, class BASE, class ORDER_MODIFIER = OrderModifier>
63
63
  static string ToString(const T &entry, const string &schema, const string &function_name, bool is_operator = false,
64
- bool distinct = false, BASE *filter = nullptr, OrderModifier *order_bys = nullptr,
64
+ bool distinct = false, BASE *filter = nullptr, ORDER_MODIFIER *order_bys = nullptr,
65
65
  bool export_state = false, bool add_alias = false) {
66
66
  if (is_operator) {
67
67
  // built-in operator
@@ -24,8 +24,8 @@ public:
24
24
  case_insensitive_set_t exclude_list;
25
25
  //! List of columns to replace with another expression
26
26
  case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
27
- //! Regular expression to select columns (if any)
28
- string regex;
27
+ //! The expression to select the columns (regular expression or list)
28
+ unique_ptr<ParsedExpression> expr;
29
29
  //! Whether or not this is a COLUMNS expression
30
30
  bool columns = false;
31
31
 
@@ -59,6 +59,9 @@ public:
59
59
  void Serialize(Serializer &serializer) const;
60
60
  virtual void Serialize(FieldWriter &writer) const = 0;
61
61
  static unique_ptr<AlterInfo> Deserialize(Deserializer &source);
62
+ virtual string GetColumnName() const {
63
+ return "";
64
+ };
62
65
 
63
66
  AlterEntryData GetAlterEntryData() const;
64
67
  };
@@ -137,6 +137,9 @@ public:
137
137
  unique_ptr<AlterInfo> Copy() const override;
138
138
  void SerializeAlterTable(FieldWriter &writer) const override;
139
139
  static unique_ptr<AlterInfo> Deserialize(FieldReader &reader, AlterEntryData data);
140
+ string GetColumnName() const override {
141
+ return removed_column;
142
+ };
140
143
  };
141
144
 
142
145
  //===--------------------------------------------------------------------===//
@@ -158,6 +161,9 @@ public:
158
161
  unique_ptr<AlterInfo> Copy() const override;
159
162
  void SerializeAlterTable(FieldWriter &writer) const override;
160
163
  static unique_ptr<AlterInfo> Deserialize(FieldReader &reader, AlterEntryData data);
164
+ string GetColumnName() const override {
165
+ return column_name;
166
+ };
161
167
  };
162
168
 
163
169
  //===--------------------------------------------------------------------===//
@@ -335,6 +335,8 @@ private:
335
335
  void TransformWindowFrame(duckdb_libpgquery::PGWindowDef *window_spec, WindowExpression *expr);
336
336
 
337
337
  unique_ptr<SampleOptions> TransformSampleOptions(duckdb_libpgquery::PGNode *options);
338
+ //! Returns true if an expression is only a star (i.e. "*", without any other decorators)
339
+ bool ExpressionIsEmptyStar(ParsedExpression &expr);
338
340
 
339
341
  private:
340
342
  //! Current stack depth
@@ -253,8 +253,8 @@ private:
253
253
  BoundStatement Bind(DetachStatement &stmt);
254
254
 
255
255
  BoundStatement BindReturning(vector<unique_ptr<ParsedExpression>> returning_list, TableCatalogEntry *table,
256
- idx_t update_table_index, unique_ptr<LogicalOperator> child_operator,
257
- BoundStatement result);
256
+ const string &alias, idx_t update_table_index,
257
+ unique_ptr<LogicalOperator> child_operator, BoundStatement result);
258
258
 
259
259
  unique_ptr<QueryNode> BindTableMacro(FunctionExpression &function, TableMacroCatalogEntry *macro_func, idx_t depth);
260
260
 
@@ -339,8 +339,9 @@ private:
339
339
  void ExpandStarExpressions(vector<unique_ptr<ParsedExpression>> &select_list,
340
340
  vector<unique_ptr<ParsedExpression>> &new_select_list);
341
341
  void ExpandStarExpression(unique_ptr<ParsedExpression> expr, vector<unique_ptr<ParsedExpression>> &new_select_list);
342
- bool FindStarExpression(ParsedExpression &expr, StarExpression **star);
342
+ bool FindStarExpression(unique_ptr<ParsedExpression> &expr, StarExpression **star, bool is_root, bool in_columns);
343
343
  void ReplaceStarExpression(unique_ptr<ParsedExpression> &expr, unique_ptr<ParsedExpression> &replacement);
344
+ void BindWhereStarExpression(unique_ptr<ParsedExpression> &expr);
344
345
 
345
346
  //! If only a schema name is provided (e.g. "a.b") then figure out if "a" is a schema or a catalog name
346
347
  void BindSchemaOrCatalog(string &catalog_name, string &schema_name);
@@ -65,6 +65,9 @@ public:
65
65
 
66
66
  //! List of order nodes
67
67
  vector<BoundOrderByNode> orders;
68
+
69
+ unique_ptr<BoundOrderModifier> Copy() const;
70
+ static bool Equals(const BoundOrderModifier *left, const BoundOrderModifier *right);
68
71
  };
69
72
 
70
73
  class BoundDistinctModifier : public BoundResultModifier {
@@ -25,10 +25,13 @@ public:
25
25
  vector<unique_ptr<Expression>> children;
26
26
  //! The bound function data (if any)
27
27
  unique_ptr<FunctionData> bind_info;
28
+ //! The aggregate type (distinct or non-distinct)
28
29
  AggregateType aggr_type;
29
30
 
30
31
  //! Filter for this aggregate
31
32
  unique_ptr<Expression> filter;
33
+ //! The order by expression for this aggregate - if any
34
+ unique_ptr<BoundOrderModifier> order_bys;
32
35
 
33
36
  public:
34
37
  bool IsDistinct() const {
@@ -32,10 +32,13 @@ public:
32
32
  idx_t MaxCount() const {
33
33
  return max_count;
34
34
  }
35
-
36
35
  bool HasExtraList() const {
37
36
  return extra_list;
38
37
  }
38
+ const vector<Binder *> &GetBinders() const {
39
+ return binders;
40
+ }
41
+
39
42
  unique_ptr<Expression> CreateExtraReference(unique_ptr<ParsedExpression> expr);
40
43
 
41
44
  private:
@@ -9,6 +9,7 @@
9
9
  #pragma once
10
10
 
11
11
  #include "duckdb/planner/logical_operator.hpp"
12
+ #include "duckdb/planner/bound_result_modifier.hpp"
12
13
 
13
14
  namespace duckdb {
14
15
 
@@ -22,6 +23,8 @@ public:
22
23
  }
23
24
  //! The set of distinct targets (optional).
24
25
  vector<unique_ptr<Expression>> distinct_targets;
26
+ //! The order by modifier (optional, only for distinct on)
27
+ unique_ptr<BoundOrderModifier> order_by;
25
28
 
26
29
  public:
27
30
  string ParamsToString() const override;
@@ -44,7 +44,7 @@ protected:
44
44
  virtual void WriteMacro(ScalarMacroCatalogEntry &table);
45
45
  virtual void WriteTableMacro(TableMacroCatalogEntry &table);
46
46
  virtual void WriteIndex(IndexCatalogEntry &index_catalog);
47
- virtual void WriteType(TypeCatalogEntry &table);
47
+ virtual void WriteType(TypeCatalogEntry &type);
48
48
  };
49
49
 
50
50
  class CheckpointReader {
@@ -36,7 +36,14 @@ public:
36
36
  //! Read content of size read_size into the buffer
37
37
  void ReadData(data_ptr_t buffer, idx_t read_size) override;
38
38
 
39
+ ClientContext &GetContext() override;
40
+ Catalog *GetCatalog() override;
41
+ void SetCatalog(Catalog *catalog_p);
42
+ void SetContext(ClientContext *context_p);
43
+
39
44
  private:
40
45
  void ReadNewBlock(block_id_t id);
46
+ Catalog *catalog = nullptr;
47
+ ClientContext *context = nullptr;
41
48
  };
42
49
  } // namespace duckdb
@@ -137,7 +137,7 @@ public:
137
137
  //! Sets the table used for subsequent insert/delete/update commands
138
138
  void WriteSetTable(string &schema, string &table);
139
139
 
140
- void WriteAlter(AlterInfo &info);
140
+ void WriteAlter(data_ptr_t ptr, idx_t data_size);
141
141
 
142
142
  void WriteInsert(DataChunk &chunk);
143
143
  void WriteDelete(DataChunk &chunk);
@@ -1,52 +1,52 @@
1
1
  #include "duckdb/main/client_context.hpp"
2
2
 
3
- #include "duckdb/main/client_context_file_opener.hpp"
4
- #include "duckdb/main/query_profiler.hpp"
5
- #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
6
3
  #include "duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp"
4
+ #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
7
5
  #include "duckdb/catalog/catalog_search_path.hpp"
6
+ #include "duckdb/common/file_system.hpp"
7
+ #include "duckdb/common/http_state.hpp"
8
+ #include "duckdb/common/preserved_error.hpp"
9
+ #include "duckdb/common/progress_bar/progress_bar.hpp"
8
10
  #include "duckdb/common/serializer/buffered_deserializer.hpp"
11
+ #include "duckdb/common/serializer/buffered_file_writer.hpp"
9
12
  #include "duckdb/common/serializer/buffered_serializer.hpp"
13
+ #include "duckdb/common/types/column_data_collection.hpp"
14
+ #include "duckdb/execution/column_binding_resolver.hpp"
15
+ #include "duckdb/execution/operator/helper/physical_result_collector.hpp"
10
16
  #include "duckdb/execution/physical_plan_generator.hpp"
17
+ #include "duckdb/main/appender.hpp"
18
+ #include "duckdb/main/attached_database.hpp"
19
+ #include "duckdb/main/client_context_file_opener.hpp"
20
+ #include "duckdb/main/client_data.hpp"
11
21
  #include "duckdb/main/database.hpp"
22
+ #include "duckdb/main/database_manager.hpp"
23
+ #include "duckdb/main/error_manager.hpp"
12
24
  #include "duckdb/main/materialized_query_result.hpp"
13
- #include "duckdb/main/client_data.hpp"
25
+ #include "duckdb/main/query_profiler.hpp"
14
26
  #include "duckdb/main/query_result.hpp"
27
+ #include "duckdb/main/relation.hpp"
15
28
  #include "duckdb/main/stream_query_result.hpp"
16
29
  #include "duckdb/optimizer/optimizer.hpp"
17
- #include "duckdb/parser/parser.hpp"
30
+ #include "duckdb/parallel/task_scheduler.hpp"
18
31
  #include "duckdb/parser/expression/constant_expression.hpp"
19
32
  #include "duckdb/parser/expression/parameter_expression.hpp"
20
33
  #include "duckdb/parser/parsed_data/create_function_info.hpp"
34
+ #include "duckdb/parser/parsed_expression_iterator.hpp"
35
+ #include "duckdb/parser/parser.hpp"
36
+ #include "duckdb/parser/query_node/select_node.hpp"
21
37
  #include "duckdb/parser/statement/drop_statement.hpp"
38
+ #include "duckdb/parser/statement/execute_statement.hpp"
22
39
  #include "duckdb/parser/statement/explain_statement.hpp"
40
+ #include "duckdb/parser/statement/prepare_statement.hpp"
41
+ #include "duckdb/parser/statement/relation_statement.hpp"
23
42
  #include "duckdb/parser/statement/select_statement.hpp"
24
43
  #include "duckdb/planner/operator/logical_execute.hpp"
25
44
  #include "duckdb/planner/planner.hpp"
26
- #include "duckdb/transaction/transaction_manager.hpp"
27
- #include "duckdb/transaction/transaction.hpp"
28
- #include "duckdb/storage/data_table.hpp"
29
- #include "duckdb/main/appender.hpp"
30
- #include "duckdb/main/relation.hpp"
31
- #include "duckdb/parser/statement/relation_statement.hpp"
32
- #include "duckdb/parallel/task_scheduler.hpp"
33
- #include "duckdb/common/serializer/buffered_file_writer.hpp"
34
45
  #include "duckdb/planner/pragma_handler.hpp"
35
- #include "duckdb/common/file_system.hpp"
36
- #include "duckdb/execution/column_binding_resolver.hpp"
37
- #include "duckdb/execution/operator/helper/physical_result_collector.hpp"
38
- #include "duckdb/parser/query_node/select_node.hpp"
39
- #include "duckdb/parser/parsed_expression_iterator.hpp"
40
- #include "duckdb/parser/statement/prepare_statement.hpp"
41
- #include "duckdb/parser/statement/execute_statement.hpp"
42
- #include "duckdb/common/types/column_data_collection.hpp"
43
- #include "duckdb/common/preserved_error.hpp"
44
- #include "duckdb/common/progress_bar/progress_bar.hpp"
45
- #include "duckdb/main/error_manager.hpp"
46
- #include "duckdb/main/database_manager.hpp"
46
+ #include "duckdb/storage/data_table.hpp"
47
47
  #include "duckdb/transaction/meta_transaction.hpp"
48
- #include "duckdb/common/http_stats.hpp"
49
- #include "duckdb/main/attached_database.hpp"
48
+ #include "duckdb/transaction/transaction.hpp"
49
+ #include "duckdb/transaction/transaction_manager.hpp"
50
50
 
51
51
  namespace duckdb {
52
52
 
@@ -156,8 +156,8 @@ void ClientContext::BeginQueryInternal(ClientContextLock &lock, const string &qu
156
156
  PreservedError ClientContext::EndQueryInternal(ClientContextLock &lock, bool success, bool invalidate_transaction) {
157
157
  client_data->profiler->EndQuery();
158
158
 
159
- if (client_data->http_stats) {
160
- client_data->http_stats->Reset();
159
+ if (client_data->http_state) {
160
+ client_data->http_state->Reset();
161
161
  }
162
162
 
163
163
  // Notify any registered state of query end
@@ -717,9 +717,7 @@ unique_ptr<PendingQueryResult> ClientContext::PendingStatementOrPreparedStatemen
717
717
  auto &profiler = QueryProfiler::Get(*this);
718
718
  profiler.StartQuery(query, IsExplainAnalyze(statement ? statement.get() : prepared->unbound_statement.get()));
719
719
 
720
- if (IsExplainAnalyze(statement ? statement.get() : prepared->unbound_statement.get())) {
721
- client_data->http_stats = make_unique<HTTPStats>();
722
- }
720
+ client_data->http_state = make_unique<HTTPState>();
723
721
 
724
722
  bool invalidate_query = true;
725
723
  try {
@@ -1,15 +1,16 @@
1
1
  #include "duckdb/main/client_data.hpp"
2
- #include "duckdb/main/client_context.hpp"
3
- #include "duckdb/main/client_context_file_opener.hpp"
4
- #include "duckdb/main/query_profiler.hpp"
5
- #include "duckdb/common/http_stats.hpp"
6
- #include "duckdb/common/random_engine.hpp"
7
- #include "duckdb/catalog/catalog_search_path.hpp"
2
+
8
3
  #include "duckdb/catalog/catalog.hpp"
4
+ #include "duckdb/catalog/catalog_search_path.hpp"
5
+ #include "duckdb/common/http_state.hpp"
6
+ #include "duckdb/common/random_engine.hpp"
9
7
  #include "duckdb/common/serializer/buffered_file_writer.hpp"
10
8
  #include "duckdb/main/attached_database.hpp"
9
+ #include "duckdb/main/client_context.hpp"
10
+ #include "duckdb/main/client_context_file_opener.hpp"
11
11
  #include "duckdb/main/database.hpp"
12
12
  #include "duckdb/main/database_manager.hpp"
13
+ #include "duckdb/main/query_profiler.hpp"
13
14
 
14
15
  namespace duckdb {
15
16
 
@@ -115,6 +115,15 @@ ConnectionManager &ConnectionManager::Get(DatabaseInstance &db) {
115
115
  return db.GetConnectionManager();
116
116
  }
117
117
 
118
+ ClientContext *ConnectionManager::GetConnection(DatabaseInstance *db) {
119
+ for (auto &conn : connections) {
120
+ if (conn.first->db.get() == db) {
121
+ return conn.first;
122
+ }
123
+ }
124
+ return nullptr;
125
+ }
126
+
118
127
  ConnectionManager &ConnectionManager::Get(ClientContext &context) {
119
128
  return ConnectionManager::Get(DatabaseInstance::GetDatabase(context));
120
129
  }
@@ -1,21 +1,23 @@
1
1
  #include "duckdb/main/query_profiler.hpp"
2
- #include "duckdb/common/to_string.hpp"
2
+
3
3
  #include "duckdb/common/fstream.hpp"
4
+ #include "duckdb/common/http_state.hpp"
5
+ #include "duckdb/common/limits.hpp"
4
6
  #include "duckdb/common/printer.hpp"
5
7
  #include "duckdb/common/string_util.hpp"
6
- #include "duckdb/execution/physical_operator.hpp"
7
- #include "duckdb/execution/operator/join/physical_delim_join.hpp"
8
- #include "duckdb/execution/operator/helper/physical_execute.hpp"
9
- #include "duckdb/common/http_stats.hpp"
8
+ #include "duckdb/common/to_string.hpp"
10
9
  #include "duckdb/common/tree_renderer.hpp"
11
- #include "duckdb/common/limits.hpp"
12
10
  #include "duckdb/execution/expression_executor.hpp"
13
- #include "duckdb/planner/expression/bound_function_expression.hpp"
11
+ #include "duckdb/execution/operator/helper/physical_execute.hpp"
12
+ #include "duckdb/execution/operator/join/physical_delim_join.hpp"
13
+ #include "duckdb/execution/physical_operator.hpp"
14
14
  #include "duckdb/main/client_config.hpp"
15
15
  #include "duckdb/main/client_context.hpp"
16
16
  #include "duckdb/main/client_data.hpp"
17
- #include <utility>
17
+ #include "duckdb/planner/expression/bound_function_expression.hpp"
18
+
18
19
  #include <algorithm>
20
+ #include <utility>
19
21
 
20
22
  namespace duckdb {
21
23
 
@@ -377,15 +379,15 @@ void QueryProfiler::QueryTreeToStream(std::ostream &ss) const {
377
379
  return;
378
380
  }
379
381
 
380
- if (context.client_data->http_stats && !context.client_data->http_stats->IsEmpty()) {
382
+ if (context.client_data->http_state && !context.client_data->http_state->IsEmpty()) {
381
383
  string read =
382
- "in: " + StringUtil::BytesToHumanReadableString(context.client_data->http_stats->total_bytes_received);
384
+ "in: " + StringUtil::BytesToHumanReadableString(context.client_data->http_state->total_bytes_received);
383
385
  string written =
384
- "out: " + StringUtil::BytesToHumanReadableString(context.client_data->http_stats->total_bytes_sent);
385
- string head = "#HEAD: " + to_string(context.client_data->http_stats->head_count);
386
- string get = "#GET: " + to_string(context.client_data->http_stats->get_count);
387
- string put = "#PUT: " + to_string(context.client_data->http_stats->put_count);
388
- string post = "#POST: " + to_string(context.client_data->http_stats->post_count);
386
+ "out: " + StringUtil::BytesToHumanReadableString(context.client_data->http_state->total_bytes_sent);
387
+ string head = "#HEAD: " + to_string(context.client_data->http_state->head_count);
388
+ string get = "#GET: " + to_string(context.client_data->http_state->get_count);
389
+ string put = "#PUT: " + to_string(context.client_data->http_state->put_count);
390
+ string post = "#POST: " + to_string(context.client_data->http_state->post_count);
389
391
 
390
392
  constexpr idx_t TOTAL_BOX_WIDTH = 39;
391
393
  ss << "┌─────────────────────────────────────┐\n";
@@ -39,6 +39,7 @@ Optimizer::Optimizer(Binder &binder, ClientContext &context) : context(context),
39
39
  rewriter.rules.push_back(make_unique<EqualOrNullSimplification>(rewriter));
40
40
  rewriter.rules.push_back(make_unique<MoveConstantsRule>(rewriter));
41
41
  rewriter.rules.push_back(make_unique<LikeOptimizationRule>(rewriter));
42
+ rewriter.rules.push_back(make_unique<OrderedAggregateOptimizer>(rewriter));
42
43
  rewriter.rules.push_back(make_unique<RegexOptimizationRule>(rewriter));
43
44
  rewriter.rules.push_back(make_unique<EmptyNeedleRemovalRule>(rewriter));
44
45
  rewriter.rules.push_back(make_unique<EnumComparisonRule>(rewriter));
@@ -0,0 +1,30 @@
1
+ #include "duckdb/optimizer/rule/ordered_aggregate_optimizer.hpp"
2
+
3
+ #include "duckdb/optimizer/matcher/expression_matcher.hpp"
4
+ #include "duckdb/planner/expression/bound_aggregate_expression.hpp"
5
+
6
+ namespace duckdb {
7
+
8
+ OrderedAggregateOptimizer::OrderedAggregateOptimizer(ExpressionRewriter &rewriter) : Rule(rewriter) {
9
+ // we match on an OR expression within a LogicalFilter node
10
+ root = make_unique<ExpressionMatcher>();
11
+ root->expr_class = ExpressionClass::BOUND_AGGREGATE;
12
+ }
13
+
14
+ unique_ptr<Expression> OrderedAggregateOptimizer::Apply(LogicalOperator &op, vector<Expression *> &bindings,
15
+ bool &changes_made, bool is_root) {
16
+ auto aggr = (BoundAggregateExpression *)bindings[0];
17
+ if (!aggr->order_bys) {
18
+ // no ORDER BYs defined
19
+ return nullptr;
20
+ }
21
+ if (aggr->function.order_dependent == AggregateOrderDependent::NOT_ORDER_DEPENDENT) {
22
+ // not an order dependent aggregate but we have an ORDER BY clause - remove it
23
+ aggr->order_bys.reset();
24
+ changes_made = true;
25
+ return nullptr;
26
+ }
27
+ return nullptr;
28
+ }
29
+
30
+ } // namespace duckdb
@@ -35,7 +35,7 @@ unique_ptr<Expression> RegexOptimizationRule::Apply(LogicalOperator &op, vector<
35
35
 
36
36
  auto constant_value = ExpressionExecutor::EvaluateScalar(GetContext(), *constant_expr);
37
37
  D_ASSERT(constant_value.type() == constant_expr->return_type);
38
- auto &patt_str = StringValue::Get(constant_value);
38
+ auto patt_str = StringValue::Get(constant_value);
39
39
 
40
40
  duckdb_re2::RE2 pattern(patt_str);
41
41
  if (!pattern.ok()) {
@@ -47,7 +47,14 @@ unique_ptr<Expression> RegexOptimizationRule::Apply(LogicalOperator &op, vector<
47
47
  auto contains = make_unique<BoundFunctionExpression>(root->return_type, ContainsFun::GetFunction(),
48
48
  std::move(root->children), nullptr);
49
49
 
50
- contains->children[1] = make_unique<BoundConstantExpression>(Value(patt_str));
50
+ string min;
51
+ string max;
52
+ pattern.PossibleMatchRange(&min, &max, patt_str.size());
53
+ if (min == max) {
54
+ contains->children[1] = make_unique<BoundConstantExpression>(Value(std::move(min)));
55
+ } else {
56
+ contains->children[1] = make_unique<BoundConstantExpression>(Value(std::move(patt_str)));
57
+ }
51
58
  return std::move(contains);
52
59
  }
53
60
  return nullptr;
@@ -10,9 +10,9 @@ StarExpression::StarExpression(string relation_name_p)
10
10
  }
11
11
 
12
12
  string StarExpression::ToString() const {
13
- if (!regex.empty()) {
13
+ if (expr) {
14
14
  D_ASSERT(columns);
15
- return "COLUMNS('" + regex + "')";
15
+ return "COLUMNS(" + expr->ToString() + ")";
16
16
  }
17
17
  string result;
18
18
  if (columns) {
@@ -70,7 +70,7 @@ bool StarExpression::Equal(const StarExpression *a, const StarExpression *b) {
70
70
  return false;
71
71
  }
72
72
  }
73
- if (a->regex != b->regex) {
73
+ if (!BaseExpression::Equals(a->expr.get(), b->expr.get())) {
74
74
  return false;
75
75
  }
76
76
  return true;
@@ -93,7 +93,7 @@ void StarExpression::Serialize(FieldWriter &writer) const {
93
93
  entry.second->Serialize(serializer);
94
94
  }
95
95
  writer.WriteField<bool>(columns);
96
- writer.WriteString(regex);
96
+ writer.WriteOptional(expr);
97
97
  }
98
98
 
99
99
  unique_ptr<ParsedExpression> StarExpression::Deserialize(ExpressionType type, FieldReader &reader) {
@@ -112,7 +112,7 @@ unique_ptr<ParsedExpression> StarExpression::Deserialize(ExpressionType type, Fi
112
112
  result->replace_list.insert(make_pair(name, std::move(expr)));
113
113
  }
114
114
  result->columns = reader.ReadField<bool>(false);
115
- result->regex = reader.ReadField<string>(string());
115
+ result->expr = reader.ReadOptional<ParsedExpression>(nullptr);
116
116
  return std::move(result);
117
117
  }
118
118
 
@@ -123,7 +123,7 @@ unique_ptr<ParsedExpression> StarExpression::Copy() const {
123
123
  copy->replace_list[entry.first] = entry.second->Copy();
124
124
  }
125
125
  copy->columns = columns;
126
- copy->regex = regex;
126
+ copy->expr = expr ? expr->Copy() : nullptr;
127
127
  copy->CopyProperties(*this);
128
128
  return std::move(copy);
129
129
  }