duckdb 0.7.2-dev457.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.
- package/binding.gyp +9 -9
- package/package.json +1 -1
- package/src/duckdb/extension/parquet/parquet-extension.cpp +1 -0
- package/src/duckdb/src/catalog/catalog.cpp +13 -0
- package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +2 -21
- package/src/duckdb/src/catalog/catalog_entry/type_catalog_entry.cpp +8 -2
- package/src/duckdb/src/catalog/catalog_set.cpp +1 -0
- package/src/duckdb/src/common/arrow/arrow_appender.cpp +48 -4
- package/src/duckdb/src/common/arrow/arrow_converter.cpp +1 -1
- package/src/duckdb/src/common/field_writer.cpp +1 -0
- package/src/duckdb/src/common/serializer/buffered_deserializer.cpp +4 -0
- package/src/duckdb/src/common/serializer/buffered_file_reader.cpp +15 -2
- package/src/duckdb/src/common/types.cpp +136 -53
- package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +20 -40
- package/src/duckdb/src/function/table/arrow.cpp +3 -0
- package/src/duckdb/src/function/table/arrow_conversion.cpp +18 -0
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/function/table_function.cpp +11 -11
- package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +3 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/field_writer.hpp +12 -4
- package/src/duckdb/src/include/duckdb/common/{http_stats.hpp → http_state.hpp} +18 -4
- package/src/duckdb/src/include/duckdb/common/serializer/buffered_deserializer.hpp +4 -2
- package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_reader.hpp +8 -2
- package/src/duckdb/src/include/duckdb/common/serializer.hpp +13 -0
- package/src/duckdb/src/include/duckdb/common/types.hpp +27 -1
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_file_handle.hpp +1 -0
- package/src/duckdb/src/include/duckdb/function/table/arrow.hpp +12 -1
- package/src/duckdb/src/include/duckdb/function/table_function.hpp +8 -0
- package/src/duckdb/src/include/duckdb/main/client_data.hpp +3 -3
- package/src/duckdb/src/include/duckdb/main/connection_manager.hpp +2 -0
- package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +1 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +3 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +6 -0
- package/src/duckdb/src/include/duckdb/storage/checkpoint_manager.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/meta_block_reader.hpp +7 -0
- package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +1 -1
- package/src/duckdb/src/main/client_context.cpp +30 -32
- package/src/duckdb/src/main/client_data.cpp +7 -6
- package/src/duckdb/src/main/database.cpp +9 -0
- package/src/duckdb/src/main/query_profiler.cpp +17 -15
- package/src/duckdb/src/optimizer/rule/regex_optimizations.cpp +9 -2
- package/src/duckdb/src/parser/transform/statement/transform_rename.cpp +3 -4
- package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +11 -1
- package/src/duckdb/src/planner/logical_operator.cpp +4 -2
- package/src/duckdb/src/planner/planner.cpp +2 -1
- package/src/duckdb/src/storage/checkpoint_manager.cpp +8 -3
- package/src/duckdb/src/storage/meta_block_reader.cpp +22 -0
- package/src/duckdb/src/storage/storage_info.cpp +1 -1
- package/src/duckdb/src/storage/wal_replay.cpp +8 -5
- package/src/duckdb/src/storage/write_ahead_log.cpp +2 -2
- package/src/duckdb/src/transaction/commit_state.cpp +11 -7
- package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +1152 -1152
- package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +4 -4
@@ -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/
|
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/
|
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/
|
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/
|
49
|
-
#include "duckdb/
|
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->
|
160
|
-
client_data->
|
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
|
-
|
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
|
-
|
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
|
-
|
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/
|
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/
|
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
|
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->
|
382
|
+
if (context.client_data->http_state && !context.client_data->http_state->IsEmpty()) {
|
381
383
|
string read =
|
382
|
-
"in: " + StringUtil::BytesToHumanReadableString(context.client_data->
|
384
|
+
"in: " + StringUtil::BytesToHumanReadableString(context.client_data->http_state->total_bytes_received);
|
383
385
|
string written =
|
384
|
-
"out: " + StringUtil::BytesToHumanReadableString(context.client_data->
|
385
|
-
string head = "#HEAD: " + to_string(context.client_data->
|
386
|
-
string get = "#GET: " + to_string(context.client_data->
|
387
|
-
string put = "#PUT: " + to_string(context.client_data->
|
388
|
-
string post = "#POST: " + to_string(context.client_data->
|
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";
|
@@ -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
|
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
|
-
|
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;
|
@@ -6,7 +6,9 @@ namespace duckdb {
|
|
6
6
|
unique_ptr<AlterStatement> Transformer::TransformRename(duckdb_libpgquery::PGNode *node) {
|
7
7
|
auto stmt = reinterpret_cast<duckdb_libpgquery::PGRenameStmt *>(node);
|
8
8
|
D_ASSERT(stmt);
|
9
|
-
|
9
|
+
if (!stmt->relation) {
|
10
|
+
throw NotImplementedException("Altering schemas is not yet supported");
|
11
|
+
}
|
10
12
|
|
11
13
|
unique_ptr<AlterInfo> info;
|
12
14
|
|
@@ -17,8 +19,6 @@ unique_ptr<AlterStatement> Transformer::TransformRename(duckdb_libpgquery::PGNod
|
|
17
19
|
if (stmt->relation->relname) {
|
18
20
|
data.name = stmt->relation->relname;
|
19
21
|
}
|
20
|
-
if (stmt->relation->schemaname) {
|
21
|
-
}
|
22
22
|
// first we check the type of ALTER
|
23
23
|
switch (stmt->renameType) {
|
24
24
|
case duckdb_libpgquery::PG_OBJECT_COLUMN: {
|
@@ -36,7 +36,6 @@ unique_ptr<AlterStatement> Transformer::TransformRename(duckdb_libpgquery::PGNod
|
|
36
36
|
info = make_unique<RenameTableInfo>(std::move(data), new_name);
|
37
37
|
break;
|
38
38
|
}
|
39
|
-
|
40
39
|
case duckdb_libpgquery::PG_OBJECT_VIEW: {
|
41
40
|
// change view name
|
42
41
|
string new_name = stmt->newname;
|
@@ -126,9 +126,18 @@ Binder::BindTableFunctionInternal(TableFunction &table_function, const string &f
|
|
126
126
|
unique_ptr<FunctionData> bind_data;
|
127
127
|
vector<LogicalType> return_types;
|
128
128
|
vector<string> return_names;
|
129
|
-
if (table_function.bind) {
|
129
|
+
if (table_function.bind || table_function.bind_replace) {
|
130
130
|
TableFunctionBindInput bind_input(parameters, named_parameters, input_table_types, input_table_names,
|
131
131
|
table_function.function_info.get());
|
132
|
+
if (table_function.bind_replace) {
|
133
|
+
auto new_plan = table_function.bind_replace(context, bind_input);
|
134
|
+
if (new_plan != nullptr) {
|
135
|
+
return CreatePlan(*Bind(*new_plan));
|
136
|
+
} else if (!table_function.bind) {
|
137
|
+
throw BinderException("Failed to bind \"%s\": nullptr returned from bind_replace without bind function",
|
138
|
+
table_function.name);
|
139
|
+
}
|
140
|
+
}
|
132
141
|
bind_data = table_function.bind(context, bind_input, return_types, return_names);
|
133
142
|
if (table_function.name == "pandas_scan" || table_function.name == "arrow_scan") {
|
134
143
|
auto arrow_bind = (PyTableFunctionData *)bind_data.get();
|
@@ -153,6 +162,7 @@ Binder::BindTableFunctionInternal(TableFunction &table_function, const string &f
|
|
153
162
|
return_names[i] = "C" + to_string(i);
|
154
163
|
}
|
155
164
|
}
|
165
|
+
|
156
166
|
auto get = make_unique<LogicalGet>(bind_index, table_function, std::move(bind_data), return_types, return_names);
|
157
167
|
get->parameters = parameters;
|
158
168
|
get->named_parameters = named_parameters;
|
@@ -128,6 +128,8 @@ void LogicalOperator::Verify(ClientContext &context) {
|
|
128
128
|
continue;
|
129
129
|
}
|
130
130
|
BufferedSerializer serializer;
|
131
|
+
// We are serializing a query plan
|
132
|
+
serializer.is_query_plan = true;
|
131
133
|
try {
|
132
134
|
expressions[expr_idx]->Serialize(serializer);
|
133
135
|
} catch (NotImplementedException &ex) {
|
@@ -136,7 +138,7 @@ void LogicalOperator::Verify(ClientContext &context) {
|
|
136
138
|
}
|
137
139
|
|
138
140
|
auto data = serializer.GetData();
|
139
|
-
auto deserializer =
|
141
|
+
auto deserializer = BufferedContextDeserializer(context, data.data.get(), data.size);
|
140
142
|
|
141
143
|
PlanDeserializationState state(context);
|
142
144
|
auto deserialized_expression = Expression::Deserialize(deserializer, state);
|
@@ -371,7 +373,7 @@ unique_ptr<LogicalOperator> LogicalOperator::Copy(ClientContext &context) const
|
|
371
373
|
std::string(ex.what()));
|
372
374
|
}
|
373
375
|
auto data = logical_op_serializer.GetData();
|
374
|
-
auto logical_op_deserializer =
|
376
|
+
auto logical_op_deserializer = BufferedContextDeserializer(context, data.data.get(), data.size);
|
375
377
|
PlanDeserializationState state(context);
|
376
378
|
auto op_copy = LogicalOperator::Deserialize(logical_op_deserializer, state);
|
377
379
|
return op_copy;
|
@@ -184,6 +184,7 @@ void Planner::VerifyPlan(ClientContext &context, unique_ptr<LogicalOperator> &op
|
|
184
184
|
}
|
185
185
|
|
186
186
|
BufferedSerializer serializer;
|
187
|
+
serializer.is_query_plan = true;
|
187
188
|
try {
|
188
189
|
op->Serialize(serializer);
|
189
190
|
} catch (NotImplementedException &ex) {
|
@@ -191,7 +192,7 @@ void Planner::VerifyPlan(ClientContext &context, unique_ptr<LogicalOperator> &op
|
|
191
192
|
return;
|
192
193
|
}
|
193
194
|
auto data = serializer.GetData();
|
194
|
-
auto deserializer =
|
195
|
+
auto deserializer = BufferedContextDeserializer(context, data.data.get(), data.size);
|
195
196
|
|
196
197
|
PlanDeserializationState state(context);
|
197
198
|
auto new_plan = LogicalOperator::Deserialize(deserializer, state);
|
@@ -128,6 +128,8 @@ void SingleFileCheckpointReader::LoadFromStorage() {
|
|
128
128
|
con.BeginTransaction();
|
129
129
|
// create the MetaBlockReader to read from the storage
|
130
130
|
MetaBlockReader reader(block_manager, meta_block);
|
131
|
+
reader.SetCatalog(&catalog.GetAttached().GetCatalog());
|
132
|
+
reader.SetContext(con.context.get());
|
131
133
|
LoadCheckpoint(*con.context, reader);
|
132
134
|
con.Commit();
|
133
135
|
}
|
@@ -395,13 +397,16 @@ void CheckpointReader::ReadIndex(ClientContext &context, MetaBlockReader &reader
|
|
395
397
|
//===--------------------------------------------------------------------===//
|
396
398
|
// Custom Types
|
397
399
|
//===--------------------------------------------------------------------===//
|
398
|
-
void CheckpointWriter::WriteType(TypeCatalogEntry &
|
399
|
-
|
400
|
+
void CheckpointWriter::WriteType(TypeCatalogEntry &type) {
|
401
|
+
type.Serialize(GetMetaBlockWriter());
|
400
402
|
}
|
401
403
|
|
402
404
|
void CheckpointReader::ReadType(ClientContext &context, MetaBlockReader &reader) {
|
403
405
|
auto info = TypeCatalogEntry::Deserialize(reader);
|
404
|
-
catalog.CreateType(context, info.get());
|
406
|
+
auto catalog_entry = (TypeCatalogEntry *)catalog.CreateType(context, info.get());
|
407
|
+
if (info->type.id() == LogicalTypeId::ENUM) {
|
408
|
+
EnumType::SetCatalog(info->type, catalog_entry);
|
409
|
+
}
|
405
410
|
}
|
406
411
|
|
407
412
|
//===--------------------------------------------------------------------===//
|
@@ -1,5 +1,7 @@
|
|
1
1
|
#include "duckdb/storage/meta_block_reader.hpp"
|
2
2
|
#include "duckdb/storage/buffer_manager.hpp"
|
3
|
+
#include "duckdb/main/connection_manager.hpp"
|
4
|
+
#include "duckdb/main/database.hpp"
|
3
5
|
|
4
6
|
#include <cstring>
|
5
7
|
|
@@ -34,6 +36,16 @@ void MetaBlockReader::ReadData(data_ptr_t buffer, idx_t read_size) {
|
|
34
36
|
offset += read_size;
|
35
37
|
}
|
36
38
|
|
39
|
+
ClientContext &MetaBlockReader::GetContext() {
|
40
|
+
if (!context) {
|
41
|
+
throw InternalException("Meta Block Reader is missing context");
|
42
|
+
}
|
43
|
+
return *context;
|
44
|
+
}
|
45
|
+
Catalog *MetaBlockReader::GetCatalog() {
|
46
|
+
return catalog;
|
47
|
+
}
|
48
|
+
|
37
49
|
void MetaBlockReader::ReadNewBlock(block_id_t id) {
|
38
50
|
auto &buffer_manager = block_manager.buffer_manager;
|
39
51
|
|
@@ -52,4 +64,14 @@ void MetaBlockReader::ReadNewBlock(block_id_t id) {
|
|
52
64
|
offset = sizeof(block_id_t);
|
53
65
|
}
|
54
66
|
|
67
|
+
void MetaBlockReader::SetCatalog(Catalog *catalog_p) {
|
68
|
+
D_ASSERT(!catalog);
|
69
|
+
catalog = catalog_p;
|
70
|
+
}
|
71
|
+
|
72
|
+
void MetaBlockReader::SetContext(ClientContext *context_p) {
|
73
|
+
D_ASSERT(!context);
|
74
|
+
context = context_p;
|
75
|
+
}
|
76
|
+
|
55
77
|
} // namespace duckdb
|
@@ -24,17 +24,19 @@
|
|
24
24
|
namespace duckdb {
|
25
25
|
|
26
26
|
bool WriteAheadLog::Replay(AttachedDatabase &database, string &path) {
|
27
|
-
|
27
|
+
Connection con(database.GetDatabase());
|
28
|
+
auto initial_reader = make_unique<BufferedFileReader>(FileSystem::Get(database), path.c_str(), con.context.get());
|
28
29
|
if (initial_reader->Finished()) {
|
29
30
|
// WAL is empty
|
30
31
|
return false;
|
31
32
|
}
|
32
|
-
|
33
|
+
|
33
34
|
con.BeginTransaction();
|
34
35
|
|
35
36
|
// first deserialize the WAL to look for a checkpoint flag
|
36
37
|
// if there is a checkpoint flag, we might have already flushed the contents of the WAL to disk
|
37
38
|
ReplayState checkpoint_state(database, *con.context, *initial_reader);
|
39
|
+
initial_reader->catalog = &checkpoint_state.catalog;
|
38
40
|
checkpoint_state.deserialize_only = true;
|
39
41
|
try {
|
40
42
|
while (true) {
|
@@ -70,7 +72,8 @@ bool WriteAheadLog::Replay(AttachedDatabase &database, string &path) {
|
|
70
72
|
}
|
71
73
|
|
72
74
|
// we need to recover from the WAL: actually set up the replay state
|
73
|
-
BufferedFileReader reader(FileSystem::Get(database), path.c_str());
|
75
|
+
BufferedFileReader reader(FileSystem::Get(database), path.c_str(), con.context.get());
|
76
|
+
reader.catalog = &checkpoint_state.catalog;
|
74
77
|
ReplayState state(database, *con.context, reader);
|
75
78
|
|
76
79
|
// replay the WAL
|
@@ -192,6 +195,7 @@ void ReplayState::ReplayEntry(WALType entry_type) {
|
|
192
195
|
// Replay Table
|
193
196
|
//===--------------------------------------------------------------------===//
|
194
197
|
void ReplayState::ReplayCreateTable() {
|
198
|
+
|
195
199
|
auto info = TableCatalogEntry::Deserialize(source, context);
|
196
200
|
if (deserialize_only) {
|
197
201
|
return;
|
@@ -278,10 +282,9 @@ void ReplayState::ReplayDropSchema() {
|
|
278
282
|
//===--------------------------------------------------------------------===//
|
279
283
|
void ReplayState::ReplayCreateType() {
|
280
284
|
auto info = TypeCatalogEntry::Deserialize(source);
|
281
|
-
if (
|
285
|
+
if (Catalog::TypeExists(context, info->catalog, info->schema, info->name)) {
|
282
286
|
return;
|
283
287
|
}
|
284
|
-
|
285
288
|
catalog.CreateType(context, info.get());
|
286
289
|
}
|
287
290
|
|
@@ -281,12 +281,12 @@ void WriteAheadLog::WriteUpdate(DataChunk &chunk, const vector<column_t> &column
|
|
281
281
|
//===--------------------------------------------------------------------===//
|
282
282
|
// Write ALTER Statement
|
283
283
|
//===--------------------------------------------------------------------===//
|
284
|
-
void WriteAheadLog::WriteAlter(
|
284
|
+
void WriteAheadLog::WriteAlter(data_ptr_t ptr, idx_t data_size) {
|
285
285
|
if (skip_writing) {
|
286
286
|
return;
|
287
287
|
}
|
288
288
|
writer->Write<WALType>(WALType::ALTER_INFO);
|
289
|
-
|
289
|
+
writer->WriteData(ptr, data_size);
|
290
290
|
}
|
291
291
|
|
292
292
|
//===--------------------------------------------------------------------===//
|
@@ -46,12 +46,16 @@ void CommitState::WriteCatalogEntry(CatalogEntry *entry, data_ptr_t dataptr) {
|
|
46
46
|
// ALTER TABLE statement, read the extra data after the entry
|
47
47
|
auto extra_data_size = Load<idx_t>(dataptr);
|
48
48
|
auto extra_data = (data_ptr_t)(dataptr + sizeof(idx_t));
|
49
|
-
|
49
|
+
|
50
50
|
BufferedDeserializer source(extra_data, extra_data_size);
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
string column_name = source.Read<string>();
|
52
|
+
|
53
|
+
if (!column_name.empty()) {
|
54
|
+
// write the alter table in the log
|
55
|
+
table_entry->CommitAlter(column_name);
|
56
|
+
}
|
57
|
+
|
58
|
+
log->WriteAlter(source.ptr, source.endptr - source.ptr);
|
55
59
|
} else {
|
56
60
|
// CREATE TABLE statement
|
57
61
|
log->WriteCreateTable((TableCatalogEntry *)parent);
|
@@ -71,9 +75,9 @@ void CommitState::WriteCatalogEntry(CatalogEntry *entry, data_ptr_t dataptr) {
|
|
71
75
|
auto extra_data = (data_ptr_t)(dataptr + sizeof(idx_t));
|
72
76
|
// deserialize it
|
73
77
|
BufferedDeserializer source(extra_data, extra_data_size);
|
74
|
-
|
78
|
+
string column_name = source.Read<string>();
|
75
79
|
// write the alter table in the log
|
76
|
-
log->WriteAlter(
|
80
|
+
log->WriteAlter(source.ptr, source.endptr - source.ptr);
|
77
81
|
} else {
|
78
82
|
log->WriteCreateView((ViewCatalogEntry *)parent);
|
79
83
|
}
|