duckdb 0.7.1-dev90.0 → 0.7.2-dev0.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 (131) hide show
  1. package/README.md +1 -1
  2. package/binding.gyp +7 -7
  3. package/package.json +3 -3
  4. package/src/duckdb/extension/json/buffered_json_reader.cpp +50 -9
  5. package/src/duckdb/extension/json/include/buffered_json_reader.hpp +7 -2
  6. package/src/duckdb/extension/json/include/json_scan.hpp +45 -10
  7. package/src/duckdb/extension/json/json_functions/copy_json.cpp +35 -22
  8. package/src/duckdb/extension/json/json_functions/json_create.cpp +8 -8
  9. package/src/duckdb/extension/json/json_functions/json_structure.cpp +8 -3
  10. package/src/duckdb/extension/json/json_functions/json_transform.cpp +54 -10
  11. package/src/duckdb/extension/json/json_functions/read_json.cpp +104 -49
  12. package/src/duckdb/extension/json/json_functions/read_json_objects.cpp +5 -3
  13. package/src/duckdb/extension/json/json_functions.cpp +7 -0
  14. package/src/duckdb/extension/json/json_scan.cpp +144 -38
  15. package/src/duckdb/extension/parquet/column_reader.cpp +7 -0
  16. package/src/duckdb/extension/parquet/include/column_reader.hpp +1 -0
  17. package/src/duckdb/extension/parquet/parquet-extension.cpp +2 -10
  18. package/src/duckdb/src/catalog/catalog.cpp +62 -13
  19. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +8 -7
  20. package/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +1 -1
  21. package/src/duckdb/src/catalog/catalog_set.cpp +1 -1
  22. package/src/duckdb/src/catalog/default/default_functions.cpp +1 -0
  23. package/src/duckdb/src/catalog/default/default_views.cpp +1 -1
  24. package/src/duckdb/src/common/bind_helpers.cpp +55 -0
  25. package/src/duckdb/src/common/file_system.cpp +23 -9
  26. package/src/duckdb/src/common/hive_partitioning.cpp +1 -0
  27. package/src/duckdb/src/common/local_file_system.cpp +4 -4
  28. package/src/duckdb/src/common/string_util.cpp +8 -4
  29. package/src/duckdb/src/common/types/partitioned_column_data.cpp +1 -0
  30. package/src/duckdb/src/common/types.cpp +37 -11
  31. package/src/duckdb/src/execution/column_binding_resolver.cpp +5 -2
  32. package/src/duckdb/src/execution/index/art/art.cpp +117 -67
  33. package/src/duckdb/src/execution/index/art/art_key.cpp +24 -12
  34. package/src/duckdb/src/execution/index/art/leaf.cpp +7 -8
  35. package/src/duckdb/src/execution/index/art/node.cpp +13 -27
  36. package/src/duckdb/src/execution/index/art/node16.cpp +5 -8
  37. package/src/duckdb/src/execution/index/art/node256.cpp +3 -5
  38. package/src/duckdb/src/execution/index/art/node4.cpp +4 -7
  39. package/src/duckdb/src/execution/index/art/node48.cpp +5 -8
  40. package/src/duckdb/src/execution/index/art/prefix.cpp +2 -3
  41. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +6 -27
  42. package/src/duckdb/src/execution/operator/helper/physical_reset.cpp +1 -9
  43. package/src/duckdb/src/execution/operator/helper/physical_set.cpp +1 -9
  44. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +7 -9
  45. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +9 -0
  46. package/src/duckdb/src/execution/physical_operator.cpp +6 -6
  47. package/src/duckdb/src/function/pragma/pragma_queries.cpp +38 -11
  48. package/src/duckdb/src/function/scalar/generic/current_setting.cpp +2 -2
  49. package/src/duckdb/src/function/scalar/list/array_slice.cpp +2 -3
  50. package/src/duckdb/src/function/scalar/map/map.cpp +69 -21
  51. package/src/duckdb/src/function/scalar/string/like.cpp +6 -3
  52. package/src/duckdb/src/function/table/read_csv.cpp +16 -5
  53. package/src/duckdb/src/function/table/system/duckdb_temporary_files.cpp +59 -0
  54. package/src/duckdb/src/function/table/system_functions.cpp +1 -0
  55. package/src/duckdb/src/function/table/table_scan.cpp +3 -0
  56. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  57. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +7 -1
  58. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  59. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  60. package/src/duckdb/src/include/duckdb/common/bind_helpers.hpp +2 -0
  61. package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +1 -1
  62. package/src/duckdb/src/include/duckdb/common/enums/wal_type.hpp +3 -0
  63. package/src/duckdb/src/include/duckdb/common/file_system.hpp +1 -1
  64. package/src/duckdb/src/include/duckdb/common/hive_partitioning.hpp +9 -1
  65. package/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp +4 -4
  66. package/src/duckdb/src/include/duckdb/common/string_util.hpp +9 -2
  67. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +37 -41
  68. package/src/duckdb/src/include/duckdb/execution/index/art/art_key.hpp +8 -11
  69. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +2 -0
  70. package/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp +2 -1
  71. package/src/duckdb/src/include/duckdb/function/table/system_functions.hpp +4 -0
  72. package/src/duckdb/src/include/duckdb/main/client_data.hpp +2 -2
  73. package/src/duckdb/src/include/duckdb/main/config.hpp +2 -0
  74. package/src/duckdb/src/include/duckdb/main/{extension_functions.hpp → extension_entries.hpp} +27 -5
  75. package/src/duckdb/src/include/duckdb/main/extension_helper.hpp +11 -1
  76. package/src/duckdb/src/include/duckdb/main/settings.hpp +9 -0
  77. package/src/duckdb/src/include/duckdb/parallel/pipeline_executor.hpp +0 -7
  78. package/src/duckdb/src/include/duckdb/parser/query_node/select_node.hpp +1 -1
  79. package/src/duckdb/src/include/duckdb/parser/sql_statement.hpp +2 -2
  80. package/src/duckdb/src/include/duckdb/parser/statement/copy_statement.hpp +1 -1
  81. package/src/duckdb/src/include/duckdb/parser/statement/select_statement.hpp +3 -3
  82. package/src/duckdb/src/include/duckdb/parser/tableref/subqueryref.hpp +1 -1
  83. package/src/duckdb/src/include/duckdb/planner/binder.hpp +3 -0
  84. package/src/duckdb/src/include/duckdb/planner/expression_binder/index_binder.hpp +10 -3
  85. package/src/duckdb/src/include/duckdb/planner/operator/logical_execute.hpp +1 -5
  86. package/src/duckdb/src/include/duckdb/planner/operator/logical_show.hpp +1 -2
  87. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +8 -0
  88. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +7 -1
  89. package/src/duckdb/src/include/duckdb/storage/index.hpp +47 -38
  90. package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +7 -0
  91. package/src/duckdb/src/main/client_context.cpp +2 -0
  92. package/src/duckdb/src/main/config.cpp +1 -0
  93. package/src/duckdb/src/main/database.cpp +14 -5
  94. package/src/duckdb/src/main/extension/extension_alias.cpp +2 -1
  95. package/src/duckdb/src/main/extension/extension_helper.cpp +15 -0
  96. package/src/duckdb/src/main/extension/extension_install.cpp +60 -16
  97. package/src/duckdb/src/main/extension/extension_load.cpp +62 -13
  98. package/src/duckdb/src/main/settings/settings.cpp +16 -0
  99. package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +2 -6
  100. package/src/duckdb/src/parallel/pipeline_executor.cpp +1 -55
  101. package/src/duckdb/src/parser/parsed_data/create_index_info.cpp +3 -0
  102. package/src/duckdb/src/parser/statement/copy_statement.cpp +2 -13
  103. package/src/duckdb/src/parser/statement/delete_statement.cpp +3 -0
  104. package/src/duckdb/src/parser/statement/insert_statement.cpp +9 -0
  105. package/src/duckdb/src/parser/statement/update_statement.cpp +3 -0
  106. package/src/duckdb/src/parser/transform/expression/transform_case.cpp +3 -3
  107. package/src/duckdb/src/planner/bind_context.cpp +1 -1
  108. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +3 -0
  109. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +7 -14
  110. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +13 -0
  111. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +2 -2
  112. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +22 -1
  113. package/src/duckdb/src/planner/expression_binder/index_binder.cpp +32 -1
  114. package/src/duckdb/src/planner/logical_operator.cpp +4 -1
  115. package/src/duckdb/src/storage/buffer_manager.cpp +105 -26
  116. package/src/duckdb/src/storage/compression/bitpacking.cpp +16 -7
  117. package/src/duckdb/src/storage/data_table.cpp +66 -3
  118. package/src/duckdb/src/storage/index.cpp +1 -1
  119. package/src/duckdb/src/storage/local_storage.cpp +1 -1
  120. package/src/duckdb/src/storage/table_index_list.cpp +1 -2
  121. package/src/duckdb/src/storage/wal_replay.cpp +68 -0
  122. package/src/duckdb/src/storage/write_ahead_log.cpp +21 -1
  123. package/src/duckdb/src/transaction/commit_state.cpp +5 -2
  124. package/src/duckdb/third_party/concurrentqueue/blockingconcurrentqueue.h +2 -2
  125. package/src/duckdb/third_party/fmt/include/fmt/core.h +1 -2
  126. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +4 -4
  127. package/src/duckdb/ub_src_function_table_system.cpp +2 -0
  128. package/src/statement.cpp +46 -12
  129. package/test/arrow.test.ts +3 -3
  130. package/test/prepare.test.ts +39 -1
  131. package/test/typescript_decls.test.ts +1 -1
@@ -88,7 +88,8 @@ struct LengthFun {
88
88
 
89
89
  struct LikeFun {
90
90
  static void RegisterFunction(BuiltinFunctions &set);
91
- DUCKDB_API static bool Glob(const char *s, idx_t slen, const char *pattern, idx_t plen);
91
+ DUCKDB_API static bool Glob(const char *s, idx_t slen, const char *pattern, idx_t plen,
92
+ bool allow_question_mark = true);
92
93
  };
93
94
 
94
95
  struct LikeEscapeFun {
@@ -89,6 +89,10 @@ struct DuckDBTablesFun {
89
89
  static void RegisterFunction(BuiltinFunctions &set);
90
90
  };
91
91
 
92
+ struct DuckDBTemporaryFilesFun {
93
+ static void RegisterFunction(BuiltinFunctions &set);
94
+ };
95
+
92
96
  struct DuckDBTypesFun {
93
97
  static void RegisterFunction(BuiltinFunctions &set);
94
98
  };
@@ -11,7 +11,7 @@
11
11
  #include "duckdb/common/common.hpp"
12
12
  #include "duckdb/common/enums/output_type.hpp"
13
13
  #include "duckdb/common/types/value.hpp"
14
- #include "duckdb/common/unordered_map.hpp"
14
+ #include "duckdb/common/case_insensitive_map.hpp"
15
15
  #include "duckdb/common/atomic.hpp"
16
16
 
17
17
  namespace duckdb {
@@ -39,7 +39,7 @@ struct ClientData {
39
39
  //! The set of temporary objects that belong to this client
40
40
  shared_ptr<AttachedDatabase> temporary_objects;
41
41
  //! The set of bound prepared statements that belong to this client
42
- unordered_map<string, shared_ptr<PreparedStatementData>> prepared_statements;
42
+ case_insensitive_map_t<shared_ptr<PreparedStatementData>> prepared_statements;
43
43
 
44
44
  //! The writer used to log queries (if logging is enabled)
45
45
  unique_ptr<BufferedFileWriter> log_query_writer;
@@ -136,6 +136,8 @@ struct DBConfigOptions {
136
136
  case_insensitive_map_t<Value> set_variables;
137
137
  //! Database configuration variable default values;
138
138
  case_insensitive_map_t<Value> set_variable_defaults;
139
+ //! Directory to store extension binaries in
140
+ string extension_directory;
139
141
  //! Whether unsigned extensions should be loaded
140
142
  bool allow_unsigned_extensions = false;
141
143
  //! Enable emitting FSST Vectors
@@ -1,7 +1,7 @@
1
1
  //===----------------------------------------------------------------------===//
2
2
  // DuckDB
3
3
  //
4
- // duckdb/main/extension_functions.hpp
4
+ // duckdb/main/extension_entries.hpp
5
5
  //
6
6
  //
7
7
  //===----------------------------------------------------------------------===//
@@ -12,12 +12,12 @@
12
12
 
13
13
  namespace duckdb {
14
14
 
15
- struct ExtensionFunction {
16
- char function[48];
15
+ struct ExtensionEntry {
16
+ char name[48];
17
17
  char extension[48];
18
18
  };
19
19
 
20
- static constexpr ExtensionFunction EXTENSION_FUNCTIONS[] = {
20
+ static constexpr ExtensionEntry EXTENSION_FUNCTIONS[] = {
21
21
  {"->>", "json"},
22
22
  {"array_to_json", "json"},
23
23
  {"create_fts_index", "fts"},
@@ -30,9 +30,9 @@ static constexpr ExtensionFunction EXTENSION_FUNCTIONS[] = {
30
30
  {"from_json", "json"},
31
31
  {"from_json_strict", "json"},
32
32
  {"from_substrait", "substrait"},
33
+ {"from_substrait_json", "substrait"},
33
34
  {"get_substrait", "substrait"},
34
35
  {"get_substrait_json", "substrait"},
35
- {"from_substrait_json", "substrait"},
36
36
  {"icu_calendar_names", "icu"},
37
37
  {"icu_sort_key", "icu"},
38
38
  {"json", "json"},
@@ -88,4 +88,26 @@ static constexpr ExtensionFunction EXTENSION_FUNCTIONS[] = {
88
88
  {"visualize_json_profiling_output", "visualizer"},
89
89
  {"visualize_last_profiling_output", "visualizer"},
90
90
  };
91
+
92
+ static constexpr ExtensionEntry EXTENSION_SETTINGS[] = {
93
+ {"binary_as_string", "parquet"},
94
+ {"calendar", "icu"},
95
+ {"http_retries", "httpfs"},
96
+ {"http_retry_backoff", "httpfs"},
97
+ {"http_retry_wait_ms", "httpfs"},
98
+ {"http_timeout", "httpfs"},
99
+ {"s3_access_key_id", "httpfs"},
100
+ {"s3_endpoint", "httpfs"},
101
+ {"s3_region", "httpfs"},
102
+ {"s3_secret_access_key", "httpfs"},
103
+ {"s3_session_token", "httpfs"},
104
+ {"s3_uploader_max_filesize", "httpfs"},
105
+ {"s3_uploader_max_parts_per_file", "httpfs"},
106
+ {"s3_uploader_thread_limit", "httpfs"},
107
+ {"s3_url_compatibility_mode", "httpfs"},
108
+ {"s3_url_style", "httpfs"},
109
+ {"s3_use_ssl", "httpfs"},
110
+ {"sqlite_all_varchar", "sqlite_scanner"},
111
+ {"timezone", "icu"},
112
+ };
91
113
  } // namespace duckdb
@@ -41,10 +41,12 @@ public:
41
41
  static ExtensionLoadResult LoadExtension(DuckDB &db, const std::string &extension);
42
42
 
43
43
  static void InstallExtension(ClientContext &context, const string &extension, bool force_install);
44
+ static void InstallExtension(DBConfig &config, FileSystem &fs, const string &extension, bool force_install);
44
45
  static void LoadExternalExtension(ClientContext &context, const string &extension);
45
46
  static void LoadExternalExtension(DatabaseInstance &db, FileOpener *opener, const string &extension);
46
47
 
47
48
  static string ExtensionDirectory(ClientContext &context);
49
+ static string ExtensionDirectory(DBConfig &config, FileSystem &fs, FileOpener *opener);
48
50
 
49
51
  static idx_t DefaultExtensionCount();
50
52
  static DefaultExtension GetDefaultExtension(idx_t index);
@@ -62,9 +64,17 @@ public:
62
64
  //! Apply any known extension aliases
63
65
  static string ApplyExtensionAlias(string extension_name);
64
66
 
67
+ static string GetExtensionName(const string &extension);
68
+ static bool IsFullPath(const string &extension);
69
+
65
70
  private:
71
+ static void InstallExtensionInternal(DBConfig &config, ClientConfig *client_config, FileSystem &fs,
72
+ const string &local_path, const string &extension, bool force_install);
66
73
  static const vector<string> PathComponents();
67
- static ExtensionInitResult InitialLoad(DBConfig &context, FileOpener *opener, const string &extension);
74
+ static bool AllowAutoInstall(const string &extension);
75
+ static ExtensionInitResult InitialLoad(DBConfig &config, FileOpener *opener, const string &extension);
76
+ static bool TryInitialLoad(DBConfig &config, FileOpener *opener, const string &extension,
77
+ ExtensionInitResult &result, string &error);
68
78
  //! For tagged releases we use the tag, else we use the git commit hash
69
79
  static const string GetVersionDirectoryName();
70
80
  //! Version tags occur with and without 'v', tag in extension path is always with 'v'
@@ -216,6 +216,15 @@ struct ExplainOutputSetting {
216
216
  static Value GetSetting(ClientContext &context);
217
217
  };
218
218
 
219
+ struct ExtensionDirectorySetting {
220
+ static constexpr const char *Name = "extension_directory";
221
+ static constexpr const char *Description = "Set the directory to store extensions in";
222
+ static constexpr const LogicalTypeId InputType = LogicalTypeId::VARCHAR;
223
+ static void SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &parameter);
224
+ static void ResetGlobal(DatabaseInstance *db, DBConfig &config);
225
+ static Value GetSetting(ClientContext &context);
226
+ };
227
+
219
228
  struct ExternalThreadsSetting {
220
229
  static constexpr const char *Name = "external_threads";
221
230
  static constexpr const char *Description = "The number of external threads that work on DuckDB tasks.";
@@ -69,13 +69,6 @@ private:
69
69
  //! The final chunk used for moving data into the sink
70
70
  DataChunk final_chunk;
71
71
 
72
- //! Indicates that the first non-finished operator in the pipeline with RequireFinalExecute has some pending result
73
- bool pending_final_execute = false;
74
- //! The OperatorFinalizeResultType corresponding to the currently pending final_execute result
75
- OperatorFinalizeResultType cached_final_execute_result;
76
- //! Source has been exhausted
77
- bool source_empty = false;
78
-
79
72
  //! The operators that are not yet finished executing and have data remaining
80
73
  //! If the stack of in_process_operators is empty, we fetch from the source instead
81
74
  stack<idx_t> in_process_operators;
@@ -21,7 +21,7 @@ namespace duckdb {
21
21
  //! SelectNode represents a standard SELECT statement
22
22
  class SelectNode : public QueryNode {
23
23
  public:
24
- SelectNode();
24
+ DUCKDB_API SelectNode();
25
25
 
26
26
  //! The projection list
27
27
  vector<unique_ptr<ParsedExpression>> select_list;
@@ -40,11 +40,11 @@ protected:
40
40
  SQLStatement(const SQLStatement &other) = default;
41
41
 
42
42
  public:
43
- virtual string ToString() const {
43
+ DUCKDB_API virtual string ToString() const {
44
44
  throw InternalException("ToString not supported for this type of SQLStatement: '%s'",
45
45
  StatementTypeToString(type));
46
46
  }
47
47
  //! Create a copy of this SelectStatement
48
- virtual unique_ptr<SQLStatement> Copy() const = 0;
48
+ DUCKDB_API virtual unique_ptr<SQLStatement> Copy() const = 0;
49
49
  };
50
50
  } // namespace duckdb
@@ -28,7 +28,7 @@ protected:
28
28
  CopyStatement(const CopyStatement &other);
29
29
 
30
30
  public:
31
- unique_ptr<SQLStatement> Copy() const override;
31
+ DUCKDB_API unique_ptr<SQLStatement> Copy() const override;
32
32
 
33
33
  private:
34
34
  };
@@ -21,7 +21,7 @@ class QueryNode;
21
21
  //! SelectStatement is a typical SELECT clause
22
22
  class SelectStatement : public SQLStatement {
23
23
  public:
24
- SelectStatement() : SQLStatement(StatementType::SELECT_STATEMENT) {
24
+ DUCKDB_API SelectStatement() : SQLStatement(StatementType::SELECT_STATEMENT) {
25
25
  }
26
26
 
27
27
  //! The main query node
@@ -32,9 +32,9 @@ protected:
32
32
 
33
33
  public:
34
34
  //! Convert the SELECT statement to a string
35
- string ToString() const override;
35
+ DUCKDB_API string ToString() const override;
36
36
  //! Create a copy of this SelectStatement
37
- unique_ptr<SQLStatement> Copy() const override;
37
+ DUCKDB_API unique_ptr<SQLStatement> Copy() const override;
38
38
  //! Serializes a SelectStatement to a stand-alone binary blob
39
39
  void Serialize(Serializer &serializer) const;
40
40
  //! Deserializes a blob back into a SelectStatement, returns nullptr if
@@ -15,7 +15,7 @@ namespace duckdb {
15
15
  //! Represents a subquery
16
16
  class SubqueryRef : public TableRef {
17
17
  public:
18
- explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
18
+ DUCKDB_API explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
19
19
 
20
20
  //! The subquery
21
21
  unique_ptr<SelectStatement> subquery;
@@ -108,6 +108,9 @@ public:
108
108
 
109
109
  unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info);
110
110
  unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry *schema);
111
+
112
+ vector<unique_ptr<Expression>> BindCreateIndexExpressions(TableCatalogEntry *table, CreateIndexInfo *info);
113
+
111
114
  void BindCreateViewInfo(CreateViewInfo &base);
112
115
  SchemaCatalogEntry *BindSchema(CreateInfo &info);
113
116
  SchemaCatalogEntry *BindCreateFunctionInfo(CreateInfo &info);
@@ -10,20 +10,27 @@
10
10
 
11
11
  #include "duckdb/planner/expression_binder.hpp"
12
12
  #include "duckdb/common/unordered_map.hpp"
13
+ #include "duckdb/parser/parsed_data/create_index_info.hpp"
14
+ #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
13
15
 
14
16
  namespace duckdb {
15
17
  class BoundColumnRefExpression;
16
18
 
17
- //! The INDEX binder is responsible for binding an expression within an Index statement
19
+ //! The IndexBinder is responsible for binding an expression within an index statement
18
20
  class IndexBinder : public ExpressionBinder {
19
21
  public:
20
- IndexBinder(Binder &binder, ClientContext &context);
22
+ IndexBinder(Binder &binder, ClientContext &context, TableCatalogEntry *table = nullptr,
23
+ CreateIndexInfo *info = nullptr);
21
24
 
22
25
  protected:
23
26
  BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
24
27
  bool root_expression = false) override;
25
-
26
28
  string UnsupportedAggregateMessage() override;
29
+
30
+ private:
31
+ // only for WAL replay
32
+ TableCatalogEntry *table;
33
+ CreateIndexInfo *info;
27
34
  };
28
35
 
29
36
  } // namespace duckdb
@@ -32,11 +32,7 @@ protected:
32
32
  // already resolved
33
33
  }
34
34
  vector<ColumnBinding> GetColumnBindings() override {
35
- vector<ColumnBinding> bindings;
36
- for (idx_t i = 0; i < types.size(); i++) {
37
- bindings.push_back(ColumnBinding(0, i));
38
- }
39
- return bindings;
35
+ return GenerateColumnBindings(0, types.size());
40
36
  }
41
37
  };
42
38
  } // namespace duckdb
@@ -33,8 +33,7 @@ protected:
33
33
  LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR};
34
34
  }
35
35
  vector<ColumnBinding> GetColumnBindings() override {
36
- return {ColumnBinding(0, 0), ColumnBinding(0, 1), ColumnBinding(0, 2),
37
- ColumnBinding(0, 3), ColumnBinding(0, 4), ColumnBinding(0, 5)};
36
+ return GenerateColumnBindings(0, types.size());
38
37
  }
39
38
  };
40
39
  } // namespace duckdb
@@ -23,6 +23,11 @@ class DatabaseInstance;
23
23
  class TemporaryDirectoryHandle;
24
24
  struct EvictionQueue;
25
25
 
26
+ struct TemporaryFileInformation {
27
+ string path;
28
+ idx_t size;
29
+ };
30
+
26
31
  //! The buffer manager is in charge of handling memory management for the database. It hands out memory buffers that can
27
32
  //! be used by the database internally.
28
33
  //
@@ -98,6 +103,9 @@ public:
98
103
  DUCKDB_API void ReserveMemory(idx_t size);
99
104
  DUCKDB_API void FreeReservedMemory(idx_t size);
100
105
 
106
+ //! Returns a list of all temporary files
107
+ vector<TemporaryFileInformation> GetTemporaryFiles();
108
+
101
109
  private:
102
110
  //! Register an in-memory buffer of arbitrary size, as long as it is >= BLOCK_SIZE. can_destroy signifies whether or
103
111
  //! not the buffer can be destroyed when unpinned, or whether or not it needs to be written to a temporary file so
@@ -122,6 +122,12 @@ public:
122
122
  void UpdateColumn(TableCatalogEntry &table, ClientContext &context, Vector &row_ids,
123
123
  const vector<column_t> &column_path, DataChunk &updates);
124
124
 
125
+ //! Add an index to the DataTable. NOTE: for CREATE (UNIQUE) INDEX statements, we use the PhysicalCreateIndex
126
+ //! operator. This function is only used during the WAL replay, and is a much less performant index creation
127
+ //! approach.
128
+ void WALAddIndex(ClientContext &context, unique_ptr<Index> index,
129
+ const vector<unique_ptr<Expression>> &expressions);
130
+
125
131
  //! Fetches an append lock
126
132
  void AppendLock(TableAppendState &state);
127
133
  //! Begin appending structs to this table, obtaining necessary locks, etc
@@ -176,7 +182,7 @@ public:
176
182
  static bool IsForeignKeyIndex(const vector<PhysicalIndex> &fk_keys, Index &index, ForeignKeyType fk_type);
177
183
 
178
184
  //! Initializes a special scan that is used to create an index on the table, it keeps locks on the table
179
- void InitializeCreateIndexScan(CreateIndexScanState &state, const vector<column_t> &column_ids);
185
+ void InitializeWALCreateIndexScan(CreateIndexScanState &state, const vector<column_t> &column_ids);
180
186
  //! Scans the next chunk for the CREATE INDEX operator
181
187
  bool CreateIndexScan(TableScanState &state, DataChunk &result, TableScanType type);
182
188
 
@@ -40,11 +40,11 @@ public:
40
40
  IndexType type;
41
41
  //! Associated table io manager
42
42
  TableIOManager &table_io_manager;
43
- //! Column identifiers to extract from the base table
43
+ //! Column identifiers to extract key columns from the base table
44
44
  vector<column_t> column_ids;
45
- //! Unordered_set of column_ids used by the index
45
+ //! Unordered set of column_ids used by the index
46
46
  unordered_set<column_t> column_id_set;
47
- //! Unbound expressions used by the index
47
+ //! Unbound expressions used by the index during optimizations
48
48
  vector<unique_ptr<Expression>> unbound_expressions;
49
49
  //! The physical types stored in the index
50
50
  vector<PhysicalType> types;
@@ -64,94 +64,103 @@ public:
64
64
  bool track_memory;
65
65
 
66
66
  public:
67
- //! Initialize a scan on the index with the given expression and column ids
68
- //! to fetch from the base table when we only have one query predicate
67
+ //! Initialize a single predicate scan on the index with the given expression and column IDs
69
68
  virtual unique_ptr<IndexScanState> InitializeScanSinglePredicate(const Transaction &transaction, const Value &value,
70
69
  ExpressionType expressionType) = 0;
71
- //! Initialize a scan on the index with the given expression and column ids
72
- //! to fetch from the base table for two query predicates
70
+ //! Initialize a two predicate scan on the index with the given expression and column IDs
73
71
  virtual unique_ptr<IndexScanState> InitializeScanTwoPredicates(Transaction &transaction, const Value &low_value,
74
72
  ExpressionType low_expression_type,
75
73
  const Value &high_value,
76
74
  ExpressionType high_expression_type) = 0;
77
- //! Perform a lookup on the index, fetching up to max_count result ids. Returns true if all row ids were fetched,
78
- //! and false otherwise.
75
+ //! Performs a lookup on the index, fetching up to max_count result IDs. Returns true if all row IDs were fetched,
76
+ //! and false otherwise
79
77
  virtual bool Scan(Transaction &transaction, DataTable &table, IndexScanState &state, idx_t max_count,
80
78
  vector<row_t> &result_ids) = 0;
81
79
 
82
80
  //! Obtain a lock on the index
83
81
  virtual void InitializeLock(IndexLock &state);
84
- //! Called when data is appended to the index. The lock obtained from InitializeAppend must be held
82
+ //! Called when data is appended to the index. The lock obtained from InitializeLock must be held
85
83
  virtual bool Append(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
84
+ //! Obtains a lock and calls Append while holding that lock
86
85
  bool Append(DataChunk &entries, Vector &row_identifiers);
87
- //! Verify that data can be appended to the index
86
+ //! Verify that data can be appended to the index without a constraint violation
88
87
  virtual void VerifyAppend(DataChunk &chunk) = 0;
89
- //! Verify that data can be appended to the index
88
+ //! Verify that data can be appended to the index without a constraint violation using the conflict manager
90
89
  virtual void VerifyAppend(DataChunk &chunk, ConflictManager &conflict_manager) = 0;
91
- //! Verify that data can be appended to the index for foreign key constraint
92
- virtual void VerifyAppendForeignKey(DataChunk &chunk) = 0;
93
- //! Verify that data can be delete from the index for foreign key constraint
94
- virtual void VerifyDeleteForeignKey(DataChunk &chunk) = 0;
90
+ //! Performs constraint checking for a chunk of input data
91
+ virtual void CheckConstraintsForChunk(DataChunk &input, ConflictManager &conflict_manager) = 0;
95
92
 
96
- //! Called when data inside the index is Deleted
93
+ //! Delete a chunk of entries from the index. The lock obtained from InitializeLock must be held
97
94
  virtual void Delete(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
95
+ //! Obtains a lock and calls Delete while holding that lock
98
96
  void Delete(DataChunk &entries, Vector &row_identifiers);
99
97
 
100
- //! Insert data into the index. Does not lock the index.
98
+ //! Insert a chunk of entries into the index
101
99
  virtual bool Insert(IndexLock &lock, DataChunk &input, Vector &row_identifiers) = 0;
102
100
 
103
- //! Merge other_index into this index.
101
+ //! Merge another index into this index. The lock obtained from InitializeLock must be held, and the other
102
+ //! index must also be locked during the merge
104
103
  virtual bool MergeIndexes(IndexLock &state, Index *other_index) = 0;
104
+ //! Obtains a lock and calls MergeIndexes while holding that lock
105
105
  bool MergeIndexes(Index *other_index);
106
106
 
107
107
  //! Returns the string representation of an index
108
108
  virtual string ToString() = 0;
109
- //! Verifies that the memory_size value of the index matches its actual size
109
+ //! Verifies that the in-memory size value of the index matches its actual size
110
110
  virtual void Verify() = 0;
111
-
112
- //! Returns true if the index is affected by updates on the specified column ids, and false otherwise
111
+ //! Increases the memory size by the difference between the old size and the current size
112
+ //! and performs verifications
113
+ virtual void IncreaseAndVerifyMemorySize(idx_t old_memory_size) = 0;
114
+
115
+ //! Increases the in-memory size value
116
+ inline void IncreaseMemorySize(idx_t size) {
117
+ memory_size += size;
118
+ };
119
+ //! Decreases the in-memory size value
120
+ inline void DecreaseMemorySize(idx_t size) {
121
+ D_ASSERT(memory_size >= size);
122
+ memory_size -= size;
123
+ };
124
+
125
+ //! Returns true if the index is affected by updates on the specified column IDs, and false otherwise
113
126
  bool IndexIsUpdated(const vector<PhysicalIndex> &column_ids) const;
114
127
 
115
- //! Returns how many of the input values were found in the 'input' chunk, with the option to also record what those
116
- //! matches were. For this purpose, nulls count as a match, and are returned in 'null_count'
117
- virtual void LookupValues(DataChunk &input, ConflictManager &conflict_manager) = 0;
118
-
119
128
  //! Returns unique flag
120
129
  bool IsUnique() {
121
130
  return (constraint_type == IndexConstraintType::UNIQUE || constraint_type == IndexConstraintType::PRIMARY);
122
131
  }
123
- //! Returns primary flag
132
+ //! Returns primary key flag
124
133
  bool IsPrimary() {
125
134
  return (constraint_type == IndexConstraintType::PRIMARY);
126
135
  }
127
- //! Returns foreign flag
136
+ //! Returns foreign key flag
128
137
  bool IsForeign() {
129
138
  return (constraint_type == IndexConstraintType::FOREIGN);
130
139
  }
131
- //! Serializes the index and returns the pair of block_id offset positions
132
- virtual BlockPointer Serialize(duckdb::MetaBlockWriter &writer);
133
- BlockPointer GetBlockPointer();
134
140
 
135
- //! Returns block/offset of where index was most recently serialized.
141
+ //! Serializes the index and returns the pair of block_id offset positions
142
+ virtual BlockPointer Serialize(MetaBlockWriter &writer);
143
+ //! Returns the serialized data pointer to the block and offset of the serialized index
136
144
  BlockPointer GetSerializedDataPointer() const {
137
145
  return serialized_data_pointer;
138
146
  }
139
147
 
140
- protected:
148
+ //! Execute the index expressions on an input chunk
141
149
  void ExecuteExpressions(DataChunk &input, DataChunk &result);
142
150
 
143
- //! Lock used for updating the index
151
+ protected:
152
+ //! Lock used for any changes to the index
144
153
  mutex lock;
145
-
146
- //! Pointer to most recently checkpointed index data.
154
+ //! Pointer to serialized index data
147
155
  BlockPointer serialized_data_pointer;
148
156
 
149
157
  private:
150
- //! Bound expressions used by the index
158
+ //! Bound expressions used during expression execution
151
159
  vector<unique_ptr<Expression>> bound_expressions;
152
- //! Expression executor for the index expressions
160
+ //! Expression executor to execute the index expressions
153
161
  ExpressionExecutor executor;
154
162
 
163
+ //! Bind the unbound expressions of the index
155
164
  unique_ptr<Expression> BindExpression(unique_ptr<Expression> expr);
156
165
  };
157
166
 
@@ -15,6 +15,7 @@
15
15
  #include "duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp"
16
16
  #include "duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp"
17
17
  #include "duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp"
18
+ #include "duckdb/catalog/catalog_entry/index_catalog_entry.hpp"
18
19
  #include "duckdb/main/attached_database.hpp"
19
20
  #include "duckdb/storage/storage_info.hpp"
20
21
 
@@ -77,6 +78,9 @@ protected:
77
78
  void ReplayCreateTableMacro();
78
79
  void ReplayDropTableMacro();
79
80
 
81
+ void ReplayCreateIndex();
82
+ void ReplayDropIndex();
83
+
80
84
  void ReplayUseTable();
81
85
  void ReplayInsert();
82
86
  void ReplayDelete();
@@ -125,6 +129,9 @@ public:
125
129
  void WriteCreateTableMacro(TableMacroCatalogEntry *entry);
126
130
  void WriteDropTableMacro(TableMacroCatalogEntry *entry);
127
131
 
132
+ void WriteCreateIndex(IndexCatalogEntry *entry);
133
+ void WriteDropIndex(IndexCatalogEntry *entry);
134
+
128
135
  void WriteCreateType(TypeCatalogEntry *entry);
129
136
  void WriteDropType(TypeCatalogEntry *entry);
130
137
  //! Sets the table used for subsequent insert/delete/update commands
@@ -665,6 +665,7 @@ unique_ptr<PendingQueryResult> ClientContext::PendingStatementOrPreparedStatemen
665
665
  statement = std::move(copied_statement);
666
666
  break;
667
667
  }
668
+ #ifndef DUCKDB_ALTERNATIVE_VERIFY
668
669
  case StatementType::COPY_STATEMENT:
669
670
  case StatementType::INSERT_STATEMENT:
670
671
  case StatementType::DELETE_STATEMENT:
@@ -685,6 +686,7 @@ unique_ptr<PendingQueryResult> ClientContext::PendingStatementOrPreparedStatemen
685
686
  statement = std::move(parser.statements[0]);
686
687
  break;
687
688
  }
689
+ #endif
688
690
  default:
689
691
  statement = std::move(copied_statement);
690
692
  break;
@@ -67,6 +67,7 @@ static ConfigurationOption internal_options[] = {DUCKDB_GLOBAL(AccessModeSetting
67
67
  DUCKDB_LOCAL(EnableProgressBarPrintSetting),
68
68
  DUCKDB_GLOBAL(ExperimentalParallelCSVSetting),
69
69
  DUCKDB_LOCAL(ExplainOutputSetting),
70
+ DUCKDB_GLOBAL(ExtensionDirectorySetting),
70
71
  DUCKDB_GLOBAL(ExternalThreadsSetting),
71
72
  DUCKDB_LOCAL(FileSearchPathSetting),
72
73
  DUCKDB_GLOBAL(ForceCompressionSetting),
@@ -144,9 +144,15 @@ unique_ptr<AttachedDatabase> DatabaseInstance::CreateAttachedDatabase(AttachInfo
144
144
  if (entry == config.storage_extensions.end()) {
145
145
  throw BinderException("Unrecognized storage type \"%s\"", type);
146
146
  }
147
- // use storage extension to create the initial database
148
- attached_database = make_unique<AttachedDatabase>(*this, Catalog::GetSystemCatalog(*this), *entry->second,
149
- info.name, info, access_mode);
147
+
148
+ if (entry->second->attach != nullptr && entry->second->create_transaction_manager != nullptr) {
149
+ // use storage extension to create the initial database
150
+ attached_database = make_unique<AttachedDatabase>(*this, Catalog::GetSystemCatalog(*this), *entry->second,
151
+ info.name, info, access_mode);
152
+ } else {
153
+ attached_database = make_unique<AttachedDatabase>(*this, Catalog::GetSystemCatalog(*this), info.name,
154
+ info.path, access_mode);
155
+ }
150
156
  } else {
151
157
  // check if this is an in-memory database or not
152
158
  attached_database =
@@ -200,6 +206,7 @@ void DatabaseInstance::Initialize(const char *database_path, DBConfig *user_conf
200
206
  AttachInfo info;
201
207
  info.name = AttachedDatabase::ExtractDatabaseName(config.options.database_path);
202
208
  info.path = config.options.database_path;
209
+
203
210
  auto attached_database = CreateAttachedDatabase(info, database_type, config.options.access_mode);
204
211
  auto initial_database = attached_database.get();
205
212
  {
@@ -356,7 +363,8 @@ idx_t DuckDB::NumberOfThreads() {
356
363
  }
357
364
 
358
365
  bool DatabaseInstance::ExtensionIsLoaded(const std::string &name) {
359
- return loaded_extensions.find(name) != loaded_extensions.end();
366
+ auto extension_name = ExtensionHelper::GetExtensionName(name);
367
+ return loaded_extensions.find(extension_name) != loaded_extensions.end();
360
368
  }
361
369
 
362
370
  bool DuckDB::ExtensionIsLoaded(const std::string &name) {
@@ -364,7 +372,8 @@ bool DuckDB::ExtensionIsLoaded(const std::string &name) {
364
372
  }
365
373
 
366
374
  void DatabaseInstance::SetExtensionLoaded(const std::string &name) {
367
- loaded_extensions.insert(name);
375
+ auto extension_name = ExtensionHelper::GetExtensionName(name);
376
+ loaded_extensions.insert(extension_name);
368
377
  }
369
378
 
370
379
  bool DatabaseInstance::TryGetCurrentSetting(const std::string &key, Value &result) {
@@ -24,8 +24,9 @@ ExtensionAlias ExtensionHelper::GetExtensionAlias(idx_t index) {
24
24
  }
25
25
 
26
26
  string ExtensionHelper::ApplyExtensionAlias(string extension_name) {
27
+ auto lname = StringUtil::Lower(extension_name);
27
28
  for (idx_t index = 0; internal_aliases[index].alias; index++) {
28
- if (extension_name == internal_aliases[index].alias) {
29
+ if (lname == internal_aliases[index].alias) {
29
30
  return internal_aliases[index].extension;
30
31
  }
31
32
  }