duckdb 1.4.0 → 1.4.1

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 (144) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/extension/core_functions/scalar/generic/current_setting.cpp +1 -4
  3. package/src/duckdb/extension/icu/icu-strptime.cpp +2 -1
  4. package/src/duckdb/extension/json/include/json_common.hpp +2 -4
  5. package/src/duckdb/extension/json/json_functions.cpp +5 -1
  6. package/src/duckdb/extension/parquet/column_writer.cpp +31 -21
  7. package/src/duckdb/extension/parquet/geo_parquet.cpp +21 -6
  8. package/src/duckdb/extension/parquet/include/column_writer.hpp +2 -2
  9. package/src/duckdb/extension/parquet/include/geo_parquet.hpp +28 -1
  10. package/src/duckdb/extension/parquet/include/parquet_writer.hpp +7 -2
  11. package/src/duckdb/extension/parquet/include/reader/string_column_reader.hpp +13 -0
  12. package/src/duckdb/extension/parquet/include/writer/array_column_writer.hpp +4 -0
  13. package/src/duckdb/extension/parquet/parquet_extension.cpp +56 -1
  14. package/src/duckdb/extension/parquet/parquet_reader.cpp +4 -1
  15. package/src/duckdb/extension/parquet/parquet_statistics.cpp +5 -7
  16. package/src/duckdb/extension/parquet/parquet_writer.cpp +15 -8
  17. package/src/duckdb/extension/parquet/reader/string_column_reader.cpp +17 -4
  18. package/src/duckdb/extension/parquet/writer/array_column_writer.cpp +22 -28
  19. package/src/duckdb/extension/parquet/writer/primitive_column_writer.cpp +17 -5
  20. package/src/duckdb/extension/parquet/writer/struct_column_writer.cpp +3 -2
  21. package/src/duckdb/src/catalog/catalog_search_path.cpp +2 -2
  22. package/src/duckdb/src/catalog/catalog_set.cpp +1 -2
  23. package/src/duckdb/src/common/enum_util.cpp +20 -0
  24. package/src/duckdb/src/common/file_system.cpp +0 -30
  25. package/src/duckdb/src/common/sorting/sort.cpp +25 -6
  26. package/src/duckdb/src/common/sorting/sorted_run_merger.cpp +1 -0
  27. package/src/duckdb/src/common/string_util.cpp +24 -0
  28. package/src/duckdb/src/common/virtual_file_system.cpp +59 -10
  29. package/src/duckdb/src/execution/index/art/art_merger.cpp +0 -3
  30. package/src/duckdb/src/execution/index/art/prefix.cpp +4 -0
  31. package/src/duckdb/src/execution/operator/csv_scanner/scanner/string_value_scanner.cpp +1 -1
  32. package/src/duckdb/src/execution/operator/helper/physical_reset.cpp +2 -2
  33. package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +1 -1
  34. package/src/duckdb/src/execution/physical_plan/plan_asof_join.cpp +3 -3
  35. package/src/duckdb/src/function/table/system/duckdb_connection_count.cpp +45 -0
  36. package/src/duckdb/src/function/table/system/duckdb_settings.cpp +11 -1
  37. package/src/duckdb/src/function/table/system_functions.cpp +1 -0
  38. package/src/duckdb/src/function/table/version/pragma_version.cpp +3 -3
  39. package/src/duckdb/src/include/duckdb/common/enum_util.hpp +8 -0
  40. package/src/duckdb/src/include/duckdb/common/string_util.hpp +2 -0
  41. package/src/duckdb/src/include/duckdb/common/virtual_file_system.hpp +4 -1
  42. package/src/duckdb/src/include/duckdb/function/scalar/variant_functions.hpp +1 -1
  43. package/src/duckdb/src/include/duckdb/function/table/system_functions.hpp +4 -0
  44. package/src/duckdb/src/include/duckdb/logging/log_storage.hpp +6 -6
  45. package/src/duckdb/src/include/duckdb/logging/log_type.hpp +26 -3
  46. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +4 -0
  47. package/src/duckdb/src/include/duckdb/main/client_context.hpp +2 -0
  48. package/src/duckdb/src/include/duckdb/main/connection.hpp +0 -1
  49. package/src/duckdb/src/include/duckdb/main/connection_manager.hpp +0 -1
  50. package/src/duckdb/src/include/duckdb/main/database_file_path_manager.hpp +12 -1
  51. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +3 -0
  52. package/src/duckdb/src/include/duckdb/main/relation/create_table_relation.hpp +2 -0
  53. package/src/duckdb/src/include/duckdb/main/relation/create_view_relation.hpp +2 -0
  54. package/src/duckdb/src/include/duckdb/main/relation/delete_relation.hpp +2 -0
  55. package/src/duckdb/src/include/duckdb/main/relation/explain_relation.hpp +2 -0
  56. package/src/duckdb/src/include/duckdb/main/relation/insert_relation.hpp +2 -0
  57. package/src/duckdb/src/include/duckdb/main/relation/query_relation.hpp +1 -0
  58. package/src/duckdb/src/include/duckdb/main/relation/update_relation.hpp +2 -0
  59. package/src/duckdb/src/include/duckdb/main/relation/write_csv_relation.hpp +2 -0
  60. package/src/duckdb/src/include/duckdb/main/relation/write_parquet_relation.hpp +2 -0
  61. package/src/duckdb/src/include/duckdb/main/relation.hpp +2 -1
  62. package/src/duckdb/src/include/duckdb/main/secret/secret.hpp +3 -1
  63. package/src/duckdb/src/include/duckdb/optimizer/filter_pushdown.hpp +3 -2
  64. package/src/duckdb/src/include/duckdb/planner/binder.hpp +62 -3
  65. package/src/duckdb/src/include/duckdb/planner/expression_binder/lateral_binder.hpp +2 -2
  66. package/src/duckdb/src/include/duckdb/planner/operator/logical_cte.hpp +1 -1
  67. package/src/duckdb/src/include/duckdb/planner/operator/logical_dependent_join.hpp +3 -3
  68. package/src/duckdb/src/include/duckdb/planner/subquery/flatten_dependent_join.hpp +2 -2
  69. package/src/duckdb/src/include/duckdb/planner/subquery/has_correlated_expressions.hpp +2 -2
  70. package/src/duckdb/src/include/duckdb/planner/subquery/rewrite_cte_scan.hpp +2 -2
  71. package/src/duckdb/src/include/duckdb/planner/tableref/bound_joinref.hpp +1 -1
  72. package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_analyze.hpp +6 -1
  73. package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_analyze.hpp +5 -1
  74. package/src/duckdb/src/include/duckdb/storage/metadata/metadata_manager.hpp +9 -7
  75. package/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp +2 -0
  76. package/src/duckdb/src/include/duckdb/storage/table/array_column_data.hpp +4 -4
  77. package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +6 -6
  78. package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +4 -4
  79. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +4 -4
  80. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +5 -3
  81. package/src/duckdb/src/include/duckdb/storage/table/row_id_column_data.hpp +4 -4
  82. package/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp +4 -4
  83. package/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp +4 -4
  84. package/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +2 -2
  85. package/src/duckdb/src/include/duckdb/transaction/duck_transaction.hpp +2 -1
  86. package/src/duckdb/src/include/duckdb/transaction/update_info.hpp +4 -1
  87. package/src/duckdb/src/include/duckdb/transaction/wal_write_state.hpp +1 -1
  88. package/src/duckdb/src/logging/log_types.cpp +63 -0
  89. package/src/duckdb/src/main/attached_database.cpp +16 -3
  90. package/src/duckdb/src/main/client_context.cpp +27 -19
  91. package/src/duckdb/src/main/connection.cpp +2 -5
  92. package/src/duckdb/src/main/database_file_path_manager.cpp +23 -6
  93. package/src/duckdb/src/main/database_manager.cpp +18 -3
  94. package/src/duckdb/src/main/http/http_util.cpp +3 -1
  95. package/src/duckdb/src/main/relation/create_table_relation.cpp +8 -0
  96. package/src/duckdb/src/main/relation/create_view_relation.cpp +8 -0
  97. package/src/duckdb/src/main/relation/delete_relation.cpp +8 -0
  98. package/src/duckdb/src/main/relation/explain_relation.cpp +8 -0
  99. package/src/duckdb/src/main/relation/insert_relation.cpp +8 -0
  100. package/src/duckdb/src/main/relation/query_relation.cpp +4 -0
  101. package/src/duckdb/src/main/relation/update_relation.cpp +8 -0
  102. package/src/duckdb/src/main/relation/write_csv_relation.cpp +8 -0
  103. package/src/duckdb/src/main/relation/write_parquet_relation.cpp +8 -0
  104. package/src/duckdb/src/main/relation.cpp +2 -2
  105. package/src/duckdb/src/optimizer/filter_combiner.cpp +7 -0
  106. package/src/duckdb/src/optimizer/filter_pushdown.cpp +9 -3
  107. package/src/duckdb/src/optimizer/pushdown/pushdown_get.cpp +4 -1
  108. package/src/duckdb/src/optimizer/rule/comparison_simplification.cpp +3 -7
  109. package/src/duckdb/src/parser/statement/relation_statement.cpp +1 -4
  110. package/src/duckdb/src/parser/transform/statement/transform_create_function.cpp +2 -0
  111. package/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp +8 -6
  112. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +1 -5
  113. package/src/duckdb/src/planner/binder/statement/bind_merge_into.cpp +10 -2
  114. package/src/duckdb/src/planner/binder/statement/bind_pragma.cpp +20 -3
  115. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +8 -3
  116. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +9 -2
  117. package/src/duckdb/src/planner/binder.cpp +2 -2
  118. package/src/duckdb/src/planner/expression_binder/lateral_binder.cpp +9 -13
  119. package/src/duckdb/src/planner/expression_binder/table_function_binder.cpp +4 -0
  120. package/src/duckdb/src/planner/expression_binder.cpp +3 -1
  121. package/src/duckdb/src/planner/operator/logical_dependent_join.cpp +2 -2
  122. package/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp +12 -14
  123. package/src/duckdb/src/planner/subquery/has_correlated_expressions.cpp +1 -1
  124. package/src/duckdb/src/planner/subquery/rewrite_cte_scan.cpp +2 -2
  125. package/src/duckdb/src/storage/compression/bitpacking.cpp +1 -2
  126. package/src/duckdb/src/storage/data_table.cpp +2 -2
  127. package/src/duckdb/src/storage/local_storage.cpp +1 -1
  128. package/src/duckdb/src/storage/metadata/metadata_manager.cpp +67 -25
  129. package/src/duckdb/src/storage/statistics/string_stats.cpp +8 -0
  130. package/src/duckdb/src/storage/table/array_column_data.cpp +6 -5
  131. package/src/duckdb/src/storage/table/column_data.cpp +23 -9
  132. package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +15 -1
  133. package/src/duckdb/src/storage/table/list_column_data.cpp +5 -4
  134. package/src/duckdb/src/storage/table/row_group.cpp +8 -8
  135. package/src/duckdb/src/storage/table/row_group_collection.cpp +12 -8
  136. package/src/duckdb/src/storage/table/row_id_column_data.cpp +5 -4
  137. package/src/duckdb/src/storage/table/standard_column_data.cpp +9 -8
  138. package/src/duckdb/src/storage/table/struct_column_data.cpp +10 -9
  139. package/src/duckdb/src/storage/table/update_segment.cpp +12 -10
  140. package/src/duckdb/src/transaction/commit_state.cpp +18 -0
  141. package/src/duckdb/src/transaction/duck_transaction.cpp +2 -10
  142. package/src/duckdb/src/transaction/wal_write_state.cpp +5 -5
  143. package/src/duckdb/third_party/httplib/httplib.hpp +6 -1
  144. package/src/duckdb/ub_src_function_table_system.cpp +2 -0
@@ -318,6 +318,8 @@ public:
318
318
  //! Transforms an complex JSON to a JSON string
319
319
  DUCKDB_API static string ToComplexJSONMap(const ComplexJSON &complex_json);
320
320
 
321
+ DUCKDB_API static string ValidateJSON(const char *data, const idx_t &len);
322
+
321
323
  DUCKDB_API static string GetFileName(const string &file_path);
322
324
  DUCKDB_API static string GetFileExtension(const string &file_name);
323
325
  DUCKDB_API static string GetFileStem(const string &file_name);
@@ -11,6 +11,7 @@
11
11
  #include "duckdb/common/file_system.hpp"
12
12
  #include "duckdb/common/map.hpp"
13
13
  #include "duckdb/common/unordered_set.hpp"
14
+ #include "duckdb/main/extension_helper.hpp"
14
15
 
15
16
  namespace duckdb {
16
17
 
@@ -82,8 +83,10 @@ protected:
82
83
  }
83
84
 
84
85
  private:
86
+ FileSystem &FindFileSystem(const string &path, optional_ptr<FileOpener> file_opener);
87
+ FileSystem &FindFileSystem(const string &path, optional_ptr<DatabaseInstance> database_instance);
85
88
  FileSystem &FindFileSystem(const string &path);
86
- FileSystem &FindFileSystemInternal(const string &path);
89
+ optional_ptr<FileSystem> FindFileSystemInternal(const string &path);
87
90
 
88
91
  private:
89
92
  vector<unique_ptr<FileSystem>> sub_systems;
@@ -29,7 +29,7 @@ struct VariantTypeofFun {
29
29
  static constexpr const char *Name = "variant_typeof";
30
30
  static constexpr const char *Parameters = "input_variant";
31
31
  static constexpr const char *Description = "Returns the internal type of the `input_variant`.";
32
- static constexpr const char *Example = "variant_typeof({'a': 42, 'b': [1,2,3])::VARIANT)";
32
+ static constexpr const char *Example = "variant_typeof({'a': 42, 'b': [1,2,3]})::VARIANT)";
33
33
  static constexpr const char *Categories = "variant";
34
34
 
35
35
  static ScalarFunction GetFunction();
@@ -47,6 +47,10 @@ struct DuckDBSchemasFun {
47
47
  static void RegisterFunction(BuiltinFunctions &set);
48
48
  };
49
49
 
50
+ struct DuckDBConnectionCountFun {
51
+ static void RegisterFunction(BuiltinFunctions &set);
52
+ };
53
+
50
54
  struct DuckDBApproxDatabaseCountFun {
51
55
  static void RegisterFunction(BuiltinFunctions &set);
52
56
  };
@@ -33,7 +33,7 @@ struct CSVReaderOptions;
33
33
 
34
34
  //! Logging storage can store entries normalized or denormalized. This enum describes what a single table/file/etc
35
35
  //! contains
36
- enum class LoggingTargetTable {
36
+ enum class LoggingTargetTable : uint8_t {
37
37
  ALL_LOGS, // Denormalized: log entries consisting of both the full log entry and the context
38
38
  LOG_ENTRIES, // Normalized: contains only the log entries and a context_id
39
39
  LOG_CONTEXTS, // Normalized: contains only the log contexts
@@ -165,7 +165,7 @@ private:
165
165
  //! Debug option for testing buffering behaviour
166
166
  bool only_flush_on_full_buffer = false;
167
167
  //! The buffers used for each table
168
- unordered_map<LoggingTargetTable, unique_ptr<DataChunk>> buffers;
168
+ map<LoggingTargetTable, unique_ptr<DataChunk>> buffers;
169
169
  //! This flag is set whenever a new context_is written to the entry buffer. It means that the next flush of
170
170
  //! LoggingTargetTable::LOG_ENTRIES also requires a flush of LoggingTargetTable::LOG_CONTEXTS
171
171
  bool flush_contexts_on_next_entry_flush = false;
@@ -218,9 +218,9 @@ private:
218
218
  void InitializeCastChunk(LoggingTargetTable table);
219
219
 
220
220
  //! The cast buffers used to cast from the original types to the VARCHAR types ready to write to CSV format
221
- unordered_map<LoggingTargetTable, unique_ptr<DataChunk>> cast_buffers;
221
+ map<LoggingTargetTable, unique_ptr<DataChunk>> cast_buffers;
222
222
  //! The writers to be registered by child classes
223
- unordered_map<LoggingTargetTable, unique_ptr<CSVWriter>> writers;
223
+ map<LoggingTargetTable, unique_ptr<CSVWriter>> writers;
224
224
 
225
225
  //! CSV Options to initialize the CSVWriters with. TODO: cleanup, this is now a little bit of a mixed bag of
226
226
  //! settings
@@ -302,7 +302,7 @@ private:
302
302
  };
303
303
 
304
304
  //! The table info per table
305
- unordered_map<LoggingTargetTable, TableWriter> tables;
305
+ map<LoggingTargetTable, TableWriter> tables;
306
306
 
307
307
  //! Base path to generate the file paths from
308
308
  string base_path;
@@ -349,7 +349,7 @@ private:
349
349
  //! Helper function to get the buffer
350
350
  ColumnDataCollection &GetBuffer(LoggingTargetTable table) const;
351
351
 
352
- unordered_map<LoggingTargetTable, unique_ptr<ColumnDataCollection>> log_storage_buffers;
352
+ map<LoggingTargetTable, unique_ptr<ColumnDataCollection>> log_storage_buffers;
353
353
  };
354
354
 
355
355
  } // namespace duckdb
@@ -17,6 +17,9 @@ struct FileHandle;
17
17
  struct BaseRequest;
18
18
  struct HTTPResponse;
19
19
  class PhysicalOperator;
20
+ class AttachedDatabase;
21
+ class RowGroup;
22
+ struct DataTableInfo;
20
23
 
21
24
  //! Log types provide some structure to the formats that the different log messages can have
22
25
  //! For now, this holds a type that the VARCHAR value will be auto-cast into.
@@ -54,9 +57,7 @@ public:
54
57
 
55
58
  QueryLogType() : LogType(NAME, LEVEL) {};
56
59
 
57
- static string ConstructLogMessage(const string &str) {
58
- return str;
59
- }
60
+ static string ConstructLogMessage(const string &str);
60
61
  };
61
62
 
62
63
  class FileSystemLogType : public LogType {
@@ -105,4 +106,26 @@ public:
105
106
  const vector<pair<string, string>> &info);
106
107
  };
107
108
 
109
+ class CheckpointLogType : public LogType {
110
+ public:
111
+ static constexpr const char *NAME = "Checkpoint";
112
+ static constexpr LogLevel LEVEL = LogLevel::LOG_DEBUG;
113
+
114
+ //! Construct the log type
115
+ CheckpointLogType();
116
+
117
+ static LogicalType GetLogType();
118
+
119
+ //! Vacuum
120
+ static string ConstructLogMessage(const AttachedDatabase &db, DataTableInfo &table, idx_t segment_idx,
121
+ idx_t merge_count, idx_t target_count, idx_t merge_rows, idx_t row_start);
122
+ //! Checkpoint
123
+ static string ConstructLogMessage(const AttachedDatabase &db, DataTableInfo &table, idx_t segment_idx,
124
+ RowGroup &row_group);
125
+
126
+ private:
127
+ static string CreateLog(const AttachedDatabase &db, DataTableInfo &table, const char *op, vector<Value> map_keys,
128
+ vector<Value> map_values);
129
+ };
130
+
108
131
  } // namespace duckdb
@@ -40,6 +40,9 @@ struct StoredDatabasePath {
40
40
 
41
41
  DatabaseFilePathManager &manager;
42
42
  string path;
43
+
44
+ public:
45
+ void OnDetach();
43
46
  };
44
47
 
45
48
  //! AttachOptions holds information about a database we plan to attach. These options are generalized, i.e.,
@@ -103,6 +106,7 @@ public:
103
106
  void SetInitialDatabase();
104
107
  void SetReadOnlyDatabase();
105
108
  void OnDetach(ClientContext &context);
109
+ string StoredPath() const;
106
110
 
107
111
  static bool NameIsReserved(const string &name);
108
112
  static string ExtractDatabaseName(const string &dbpath, FileSystem &fs);
@@ -304,6 +304,8 @@ private:
304
304
  CreatePreparedStatementInternal(ClientContextLock &lock, const string &query, unique_ptr<SQLStatement> statement,
305
305
  optional_ptr<case_insensitive_map_t<BoundParameterData>> values);
306
306
 
307
+ SettingLookupResult TryGetCurrentSettingInternal(const string &key, Value &result) const;
308
+
307
309
  private:
308
310
  //! Lock on using the ClientContext in parallel
309
311
  mutex context_lock;
@@ -50,7 +50,6 @@ public:
50
50
  DUCKDB_API ~Connection();
51
51
 
52
52
  shared_ptr<ClientContext> context;
53
- warning_callback_t warning_cb;
54
53
 
55
54
  public:
56
55
  //! Returns query profiling information for the current query
@@ -40,7 +40,6 @@ private:
40
40
  mutex connections_lock;
41
41
  reference_map_t<ClientContext, weak_ptr<ClientContext>> connections;
42
42
  atomic<idx_t> connection_count;
43
-
44
43
  atomic<connection_t> current_connection_id;
45
44
  };
46
45
 
@@ -19,13 +19,24 @@ struct AttachOptions;
19
19
 
20
20
  enum class InsertDatabasePathResult { SUCCESS, ALREADY_EXISTS };
21
21
 
22
+ struct DatabasePathInfo {
23
+ explicit DatabasePathInfo(string name_p) : name(std::move(name_p)), is_attached(true) {
24
+ }
25
+
26
+ string name;
27
+ bool is_attached;
28
+ };
29
+
22
30
  //! The DatabaseFilePathManager is used to ensure we only ever open a single database file once
23
31
  class DatabaseFilePathManager {
24
32
  public:
25
33
  idx_t ApproxDatabaseCount() const;
26
34
  InsertDatabasePathResult InsertDatabasePath(const string &path, const string &name, OnCreateConflict on_conflict,
27
35
  AttachOptions &options);
36
+ //! Erase a database path - indicating we are done with using it
28
37
  void EraseDatabasePath(const string &path);
38
+ //! Called when a database is detached, but before it is fully finished being used
39
+ void DetachDatabase(const string &path);
29
40
 
30
41
  private:
31
42
  //! The lock to add entries to the database path map
@@ -33,7 +44,7 @@ private:
33
44
  //! A set containing all attached database path
34
45
  //! This allows to attach many databases efficiently, and to avoid attaching the
35
46
  //! same file path twice
36
- case_insensitive_map_t<string> db_paths_to_name;
47
+ case_insensitive_map_t<DatabasePathInfo> db_paths;
37
48
  };
38
49
 
39
50
  } // namespace duckdb
@@ -48,6 +48,7 @@ public:
48
48
  void FinalizeStartup();
49
49
  //! Get an attached database by its name
50
50
  optional_ptr<AttachedDatabase> GetDatabase(ClientContext &context, const string &name);
51
+ shared_ptr<AttachedDatabase> GetDatabase(const string &name);
51
52
  //! Attach a new database
52
53
  shared_ptr<AttachedDatabase> AttachDatabase(ClientContext &context, AttachInfo &info, AttachOptions &options);
53
54
 
@@ -103,6 +104,8 @@ public:
103
104
  //! Gets a list of all attached database paths
104
105
  vector<string> GetAttachedDatabasePaths();
105
106
 
107
+ shared_ptr<AttachedDatabase> GetDatabaseInternal(const lock_guard<mutex> &, const string &name);
108
+
106
109
  private:
107
110
  //! The system database is a special database that holds system entries (e.g. functions)
108
111
  shared_ptr<AttachedDatabase> system;
@@ -26,6 +26,8 @@ public:
26
26
 
27
27
  public:
28
28
  BoundStatement Bind(Binder &binder) override;
29
+ unique_ptr<QueryNode> GetQueryNode() override;
30
+ string GetQuery() override;
29
31
  const vector<ColumnDefinition> &Columns() override;
30
32
  string ToString(idx_t depth) override;
31
33
  bool IsReadOnly() override {
@@ -26,6 +26,8 @@ public:
26
26
 
27
27
  public:
28
28
  BoundStatement Bind(Binder &binder) override;
29
+ unique_ptr<QueryNode> GetQueryNode() override;
30
+ string GetQuery() override;
29
31
  const vector<ColumnDefinition> &Columns() override;
30
32
  string ToString(idx_t depth) override;
31
33
  bool IsReadOnly() override {
@@ -26,6 +26,8 @@ public:
26
26
 
27
27
  public:
28
28
  BoundStatement Bind(Binder &binder) override;
29
+ unique_ptr<QueryNode> GetQueryNode() override;
30
+ string GetQuery() override;
29
31
  const vector<ColumnDefinition> &Columns() override;
30
32
  string ToString(idx_t depth) override;
31
33
  bool IsReadOnly() override {
@@ -24,6 +24,8 @@ public:
24
24
 
25
25
  public:
26
26
  BoundStatement Bind(Binder &binder) override;
27
+ unique_ptr<QueryNode> GetQueryNode() override;
28
+ string GetQuery() override;
27
29
  const vector<ColumnDefinition> &Columns() override;
28
30
  string ToString(idx_t depth) override;
29
31
  bool IsReadOnly() override {
@@ -23,6 +23,8 @@ public:
23
23
 
24
24
  public:
25
25
  BoundStatement Bind(Binder &binder) override;
26
+ unique_ptr<QueryNode> GetQueryNode() override;
27
+ string GetQuery() override;
26
28
  const vector<ColumnDefinition> &Columns() override;
27
29
  string ToString(idx_t depth) override;
28
30
  bool IsReadOnly() override {
@@ -28,6 +28,7 @@ public:
28
28
  public:
29
29
  static unique_ptr<SelectStatement> ParseStatement(ClientContext &context, const string &query, const string &error);
30
30
  unique_ptr<QueryNode> GetQueryNode() override;
31
+ string GetQuery() override;
31
32
  unique_ptr<TableRef> GetTableRef() override;
32
33
  BoundStatement Bind(Binder &binder) override;
33
34
 
@@ -29,6 +29,8 @@ public:
29
29
 
30
30
  public:
31
31
  BoundStatement Bind(Binder &binder) override;
32
+ unique_ptr<QueryNode> GetQueryNode() override;
33
+ string GetQuery() override;
32
34
  const vector<ColumnDefinition> &Columns() override;
33
35
  string ToString(idx_t depth) override;
34
36
  bool IsReadOnly() override {
@@ -23,6 +23,8 @@ public:
23
23
 
24
24
  public:
25
25
  BoundStatement Bind(Binder &binder) override;
26
+ unique_ptr<QueryNode> GetQueryNode() override;
27
+ string GetQuery() override;
26
28
  const vector<ColumnDefinition> &Columns() override;
27
29
  string ToString(idx_t depth) override;
28
30
  bool IsReadOnly() override {
@@ -24,6 +24,8 @@ public:
24
24
 
25
25
  public:
26
26
  BoundStatement Bind(Binder &binder) override;
27
+ unique_ptr<QueryNode> GetQueryNode() override;
28
+ string GetQuery() override;
27
29
  const vector<ColumnDefinition> &Columns() override;
28
30
  string ToString(idx_t depth) override;
29
31
  bool IsReadOnly() override {
@@ -78,7 +78,8 @@ public:
78
78
 
79
79
  public:
80
80
  DUCKDB_API virtual const vector<ColumnDefinition> &Columns() = 0;
81
- DUCKDB_API virtual unique_ptr<QueryNode> GetQueryNode();
81
+ DUCKDB_API virtual unique_ptr<QueryNode> GetQueryNode() = 0;
82
+ DUCKDB_API virtual string GetQuery();
82
83
  DUCKDB_API virtual BoundStatement Bind(Binder &binder);
83
84
  DUCKDB_API virtual string GetAlias();
84
85
 
@@ -296,7 +296,9 @@ public:
296
296
  Value result;
297
297
  auto lookup_result = TryGetSecretKeyOrSetting(secret_key, setting_name, result);
298
298
  if (lookup_result) {
299
- value_out = result.GetValue<TYPE>();
299
+ if (!result.IsNull()) {
300
+ value_out = result.GetValue<TYPE>();
301
+ }
300
302
  }
301
303
  return lookup_result;
302
304
  }
@@ -102,8 +102,9 @@ private:
102
102
  void ExtractFilterBindings(const Expression &expr, vector<ColumnBinding> &bindings);
103
103
  //! Generate filters from the current set of filters stored in the FilterCombiner
104
104
  void GenerateFilters();
105
- //! if there are filters in this FilterPushdown node, push them into the combiner
106
- void PushFilters();
105
+ //! if there are filters in this FilterPushdown node, push them into the combiner. Returns
106
+ //! FilterResult::UNSATISFIABLE if the subtree should be stripped, or FilterResult::SUCCESS otherwise
107
+ FilterResult PushFilters();
107
108
  };
108
109
 
109
110
  } // namespace duckdb
@@ -100,6 +100,65 @@ struct CorrelatedColumnInfo {
100
100
  }
101
101
  };
102
102
 
103
+ struct CorrelatedColumns {
104
+ private:
105
+ using container_type = vector<CorrelatedColumnInfo>;
106
+
107
+ public:
108
+ CorrelatedColumns() : delim_index(1ULL << 63) {
109
+ }
110
+
111
+ void AddColumn(container_type::value_type info) {
112
+ // Add to beginning
113
+ correlated_columns.insert(correlated_columns.begin(), std::move(info));
114
+ delim_index++;
115
+ }
116
+
117
+ void SetDelimIndexToZero() {
118
+ delim_index = 0;
119
+ }
120
+
121
+ idx_t GetDelimIndex() const {
122
+ return delim_index;
123
+ }
124
+
125
+ const container_type::value_type &operator[](const idx_t &index) const {
126
+ return correlated_columns.at(index);
127
+ }
128
+
129
+ idx_t size() const { // NOLINT: match stl case
130
+ return correlated_columns.size();
131
+ }
132
+
133
+ bool empty() const { // NOLINT: match stl case
134
+ return correlated_columns.empty();
135
+ }
136
+
137
+ void clear() { // NOLINT: match stl case
138
+ correlated_columns.clear();
139
+ }
140
+
141
+ container_type::iterator begin() { // NOLINT: match stl case
142
+ return correlated_columns.begin();
143
+ }
144
+
145
+ container_type::iterator end() { // NOLINT: match stl case
146
+ return correlated_columns.end();
147
+ }
148
+
149
+ container_type::const_iterator begin() const { // NOLINT: match stl case
150
+ return correlated_columns.begin();
151
+ }
152
+
153
+ container_type::const_iterator end() const { // NOLINT: match stl case
154
+ return correlated_columns.end();
155
+ }
156
+
157
+ private:
158
+ container_type correlated_columns;
159
+ idx_t delim_index;
160
+ };
161
+
103
162
  //! Bind the parsed query tree to the actual columns present in the catalog.
104
163
  /*!
105
164
  The binder is responsible for binding tables and columns to actual physical
@@ -124,7 +183,7 @@ public:
124
183
  BindContext bind_context;
125
184
  //! The set of correlated columns bound by this binder (FIXME: this should probably be an unordered_set and not a
126
185
  //! vector)
127
- vector<CorrelatedColumnInfo> correlated_columns;
186
+ CorrelatedColumns correlated_columns;
128
187
  //! The set of parameter expressions bound by this binder
129
188
  optional_ptr<BoundParameterMap> parameters;
130
189
  //! The alias for the currently processing subquery, if it exists
@@ -200,7 +259,7 @@ public:
200
259
 
201
260
  vector<reference<ExpressionBinder>> &GetActiveBinders();
202
261
 
203
- void MergeCorrelatedColumns(vector<CorrelatedColumnInfo> &other);
262
+ void MergeCorrelatedColumns(CorrelatedColumns &other);
204
263
  //! Add a correlated column to this binder (if it does not exist)
205
264
  void AddCorrelatedColumn(const CorrelatedColumnInfo &info);
206
265
 
@@ -428,7 +487,7 @@ private:
428
487
  void PlanSubqueries(unique_ptr<Expression> &expr, unique_ptr<LogicalOperator> &root);
429
488
  unique_ptr<Expression> PlanSubquery(BoundSubqueryExpression &expr, unique_ptr<LogicalOperator> &root);
430
489
  unique_ptr<LogicalOperator> PlanLateralJoin(unique_ptr<LogicalOperator> left, unique_ptr<LogicalOperator> right,
431
- vector<CorrelatedColumnInfo> &correlated_columns,
490
+ CorrelatedColumns &correlated_columns,
432
491
  JoinType join_type = JoinType::INNER,
433
492
  unique_ptr<Expression> condition = nullptr);
434
493
 
@@ -24,7 +24,7 @@ public:
24
24
  return !correlated_columns.empty();
25
25
  }
26
26
 
27
- static void ReduceExpressionDepth(LogicalOperator &op, const vector<CorrelatedColumnInfo> &info);
27
+ static void ReduceExpressionDepth(LogicalOperator &op, const CorrelatedColumns &info);
28
28
 
29
29
  protected:
30
30
  BindResult BindExpression(unique_ptr<ParsedExpression> &expr_ptr, idx_t depth,
@@ -37,7 +37,7 @@ private:
37
37
  void ExtractCorrelatedColumns(Expression &expr);
38
38
 
39
39
  private:
40
- vector<CorrelatedColumnInfo> correlated_columns;
40
+ CorrelatedColumns correlated_columns;
41
41
  };
42
42
 
43
43
  } // namespace duckdb
@@ -35,6 +35,6 @@ public:
35
35
  string ctename;
36
36
  idx_t table_index;
37
37
  idx_t column_count;
38
- vector<CorrelatedColumnInfo> correlated_columns;
38
+ CorrelatedColumns correlated_columns;
39
39
  };
40
40
  } // namespace duckdb
@@ -27,7 +27,7 @@ public:
27
27
 
28
28
  public:
29
29
  explicit LogicalDependentJoin(unique_ptr<LogicalOperator> left, unique_ptr<LogicalOperator> right,
30
- vector<CorrelatedColumnInfo> correlated_columns, JoinType type,
30
+ CorrelatedColumns correlated_columns, JoinType type,
31
31
  unique_ptr<Expression> condition);
32
32
 
33
33
  explicit LogicalDependentJoin(JoinType type);
@@ -35,7 +35,7 @@ public:
35
35
  //! The conditions of the join
36
36
  unique_ptr<Expression> join_condition;
37
37
  //! The list of columns that have correlations with the right
38
- vector<CorrelatedColumnInfo> correlated_columns;
38
+ CorrelatedColumns correlated_columns;
39
39
 
40
40
  SubqueryType subquery_type = SubqueryType::INVALID;
41
41
  bool perform_delim = true;
@@ -51,7 +51,7 @@ public:
51
51
 
52
52
  public:
53
53
  static unique_ptr<LogicalOperator> Create(unique_ptr<LogicalOperator> left, unique_ptr<LogicalOperator> right,
54
- vector<CorrelatedColumnInfo> correlated_columns, JoinType type,
54
+ CorrelatedColumns correlated_columns, JoinType type,
55
55
  unique_ptr<Expression> condition);
56
56
  };
57
57
  } // namespace duckdb
@@ -18,7 +18,7 @@ namespace duckdb {
18
18
  //! The FlattenDependentJoins class is responsible for pushing the dependent join down into the plan to create a
19
19
  //! flattened subquery
20
20
  struct FlattenDependentJoins {
21
- FlattenDependentJoins(Binder &binder, const vector<CorrelatedColumnInfo> &correlated, bool perform_delim = true,
21
+ FlattenDependentJoins(Binder &binder, const CorrelatedColumns &correlated, bool perform_delim = true,
22
22
  bool any_join = false, optional_ptr<FlattenDependentJoins> parent = nullptr);
23
23
 
24
24
  static unique_ptr<LogicalOperator> DecorrelateIndependent(Binder &binder, unique_ptr<LogicalOperator> plan);
@@ -47,7 +47,7 @@ public:
47
47
  reference_map_t<LogicalOperator, bool> has_correlated_expressions;
48
48
  column_binding_map_t<idx_t> correlated_map;
49
49
  column_binding_map_t<idx_t> replacement_map;
50
- const vector<CorrelatedColumnInfo> &correlated_columns;
50
+ const CorrelatedColumns &correlated_columns;
51
51
  vector<LogicalType> delim_types;
52
52
 
53
53
  bool perform_delim;
@@ -16,7 +16,7 @@ namespace duckdb {
16
16
  //! Helper class to recursively detect correlated expressions inside a single LogicalOperator
17
17
  class HasCorrelatedExpressions : public LogicalOperatorVisitor {
18
18
  public:
19
- explicit HasCorrelatedExpressions(const vector<CorrelatedColumnInfo> &correlated, bool lateral = false,
19
+ explicit HasCorrelatedExpressions(const CorrelatedColumns &correlated, bool lateral = false,
20
20
  idx_t lateral_depth = 0);
21
21
 
22
22
  void VisitOperator(LogicalOperator &op) override;
@@ -28,7 +28,7 @@ protected:
28
28
  unique_ptr<Expression> VisitReplace(BoundColumnRefExpression &expr, unique_ptr<Expression> *expr_ptr) override;
29
29
  unique_ptr<Expression> VisitReplace(BoundSubqueryExpression &expr, unique_ptr<Expression> *expr_ptr) override;
30
30
 
31
- const vector<CorrelatedColumnInfo> &correlated_columns;
31
+ const CorrelatedColumns &correlated_columns;
32
32
  // Tracks number of nested laterals
33
33
  idx_t lateral_depth;
34
34
  };
@@ -17,13 +17,13 @@ namespace duckdb {
17
17
  //! Helper class to rewrite correlated cte scans within a single LogicalOperator
18
18
  class RewriteCTEScan : public LogicalOperatorVisitor {
19
19
  public:
20
- RewriteCTEScan(idx_t table_index, const vector<CorrelatedColumnInfo> &correlated_columns);
20
+ RewriteCTEScan(idx_t table_index, const CorrelatedColumns &correlated_columns);
21
21
 
22
22
  void VisitOperator(LogicalOperator &op) override;
23
23
 
24
24
  private:
25
25
  idx_t table_index;
26
- const vector<CorrelatedColumnInfo> &correlated_columns;
26
+ const CorrelatedColumns &correlated_columns;
27
27
  };
28
28
 
29
29
  } // namespace duckdb
@@ -47,7 +47,7 @@ public:
47
47
  //! Whether or not this is a lateral join
48
48
  bool lateral;
49
49
  //! The correlated columns of the right-side with the left-side
50
- vector<CorrelatedColumnInfo> correlated_columns;
50
+ CorrelatedColumns correlated_columns;
51
51
  //! The mark index, for mark joins generated by the relational API
52
52
  idx_t mark_index {};
53
53
  };
@@ -82,7 +82,12 @@ unique_ptr<AnalyzeState> AlpInitAnalyze(ColumnData &col_data, PhysicalType type)
82
82
  */
83
83
  template <class T>
84
84
  bool AlpAnalyze(AnalyzeState &state, Vector &input, idx_t count) {
85
- auto &analyze_state = (AlpAnalyzeState<T> &)state;
85
+ if (state.info.GetBlockSize() + state.info.GetBlockHeaderSize() < DEFAULT_BLOCK_ALLOC_SIZE) {
86
+ return false;
87
+ }
88
+
89
+ auto &analyze_state = state.Cast<AlpAnalyzeState<T>>();
90
+
86
91
  bool must_skip_current_vector = alp::AlpUtils::MustSkipSamplingFromCurrentVector(
87
92
  analyze_state.vectors_count, analyze_state.vectors_sampled_count, count);
88
93
  analyze_state.vectors_count += 1;
@@ -47,8 +47,12 @@ unique_ptr<AnalyzeState> AlpRDInitAnalyze(ColumnData &col_data, PhysicalType typ
47
47
  */
48
48
  template <class T>
49
49
  bool AlpRDAnalyze(AnalyzeState &state, Vector &input, idx_t count) {
50
+ if (state.info.GetBlockSize() + state.info.GetBlockHeaderSize() < DEFAULT_BLOCK_ALLOC_SIZE) {
51
+ return false;
52
+ }
53
+
50
54
  using EXACT_TYPE = typename FloatingToExact<T>::TYPE;
51
- auto &analyze_state = (AlpRDAnalyzeState<T> &)state;
55
+ auto &analyze_state = state.Cast<AlpRDAnalyzeState<T>>();
52
56
 
53
57
  bool must_skip_current_vector = alp::AlpUtils::MustSkipSamplingFromCurrentVector(
54
58
  analyze_state.vectors_count, analyze_state.vectors_sampled_count, count);
@@ -92,17 +92,19 @@ public:
92
92
  protected:
93
93
  BlockManager &block_manager;
94
94
  BufferManager &buffer_manager;
95
+ mutable mutex block_lock;
95
96
  unordered_map<block_id_t, MetadataBlock> blocks;
96
97
  unordered_map<block_id_t, idx_t> modified_blocks;
97
98
 
98
99
  protected:
99
- block_id_t AllocateNewBlock();
100
- block_id_t PeekNextBlockId();
101
- block_id_t GetNextBlockId();
102
-
103
- void AddBlock(MetadataBlock new_block, bool if_exists = false);
104
- void AddAndRegisterBlock(MetadataBlock block);
105
- void ConvertToTransient(MetadataBlock &block);
100
+ block_id_t AllocateNewBlock(unique_lock<mutex> &block_lock);
101
+ block_id_t PeekNextBlockId() const;
102
+ block_id_t GetNextBlockId() const;
103
+
104
+ void AddBlock(unique_lock<mutex> &block_lock, MetadataBlock new_block, bool if_exists = false);
105
+ void AddAndRegisterBlock(unique_lock<mutex> &block_lock, MetadataBlock block);
106
+ void ConvertToTransient(unique_lock<mutex> &block_lock, MetadataBlock &block);
107
+ MetadataPointer FromDiskPointerInternal(unique_lock<mutex> &block_lock, MetaBlockPointer pointer);
106
108
  };
107
109
 
108
110
  } // namespace duckdb