duckdb 0.3.2-dev722.0 → 0.3.2-dev741.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/src/duckdb.cpp CHANGED
@@ -71,47 +71,6 @@ private:
71
71
 
72
72
 
73
73
 
74
- //===----------------------------------------------------------------------===//
75
- // DuckDB
76
- //
77
- // duckdb/parser/parsed_data/create_aggregate_function_info.hpp
78
- //
79
- //
80
- //===----------------------------------------------------------------------===//
81
-
82
-
83
-
84
-
85
-
86
-
87
- namespace duckdb {
88
-
89
- struct CreateAggregateFunctionInfo : public CreateFunctionInfo {
90
- explicit CreateAggregateFunctionInfo(AggregateFunction function)
91
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(function.name) {
92
- this->name = function.name;
93
- functions.AddFunction(move(function));
94
- }
95
-
96
- explicit CreateAggregateFunctionInfo(AggregateFunctionSet set)
97
- : CreateFunctionInfo(CatalogType::AGGREGATE_FUNCTION_ENTRY), functions(move(set)) {
98
- this->name = functions.name;
99
- for (auto &func : functions.functions) {
100
- func.name = functions.name;
101
- }
102
- }
103
-
104
- AggregateFunctionSet functions;
105
-
106
- public:
107
- unique_ptr<CreateInfo> Copy() const override {
108
- auto result = make_unique<CreateAggregateFunctionInfo>(functions);
109
- CopyProperties(*result);
110
- return move(result);
111
- }
112
- };
113
-
114
- } // namespace duckdb
115
74
 
116
75
 
117
76
  namespace duckdb {
@@ -141,48 +100,6 @@ public:
141
100
 
142
101
 
143
102
 
144
- //===----------------------------------------------------------------------===//
145
- // DuckDB
146
- //
147
- // duckdb/parser/parsed_data/create_collation_info.hpp
148
- //
149
- //
150
- //===----------------------------------------------------------------------===//
151
-
152
-
153
-
154
-
155
-
156
-
157
- namespace duckdb {
158
-
159
- struct CreateCollationInfo : public CreateInfo {
160
- CreateCollationInfo(string name_p, ScalarFunction function_p, bool combinable_p, bool not_required_for_equality_p)
161
- : CreateInfo(CatalogType::COLLATION_ENTRY), function(move(function_p)), combinable(combinable_p),
162
- not_required_for_equality(not_required_for_equality_p) {
163
- this->name = move(name_p);
164
- }
165
-
166
- //! The name of the collation
167
- string name;
168
- //! The collation function to push in case collation is required
169
- ScalarFunction function;
170
- //! Whether or not the collation can be combined with other collations.
171
- bool combinable;
172
- //! Whether or not the collation is required for equality comparisons or not. For many collations a binary
173
- //! comparison for equality comparisons is correct, allowing us to skip the collation in these cases which greatly
174
- //! speeds up processing.
175
- bool not_required_for_equality;
176
-
177
- public:
178
- unique_ptr<CreateInfo> Copy() const override {
179
- auto result = make_unique<CreateCollationInfo>(name, function, combinable, not_required_for_equality);
180
- CopyProperties(*result);
181
- return move(result);
182
- }
183
- };
184
-
185
- } // namespace duckdb
186
103
 
187
104
 
188
105
  namespace duckdb {
@@ -246,117 +163,6 @@ public:
246
163
 
247
164
 
248
165
 
249
- //===----------------------------------------------------------------------===//
250
- // DuckDB
251
- //
252
- // duckdb/parser/parsed_data/create_index_info.hpp
253
- //
254
- //
255
- //===----------------------------------------------------------------------===//
256
-
257
-
258
-
259
-
260
- //===----------------------------------------------------------------------===//
261
- // DuckDB
262
- //
263
- // duckdb/common/enums/index_type.hpp
264
- //
265
- //
266
- //===----------------------------------------------------------------------===//
267
-
268
-
269
-
270
-
271
-
272
- namespace duckdb {
273
-
274
- //===--------------------------------------------------------------------===//
275
- // Index Types
276
- //===--------------------------------------------------------------------===//
277
- enum class IndexType {
278
- INVALID = 0, // invalid index type
279
- ART = 1 // Adaptive Radix Tree
280
- };
281
-
282
- } // namespace duckdb
283
-
284
-
285
- //===----------------------------------------------------------------------===//
286
- // DuckDB
287
- //
288
- // duckdb/parser/tableref/basetableref.hpp
289
- //
290
- //
291
- //===----------------------------------------------------------------------===//
292
-
293
-
294
-
295
-
296
-
297
-
298
- namespace duckdb {
299
- //! Represents a TableReference to a base table in the schema
300
- class BaseTableRef : public TableRef {
301
- public:
302
- BaseTableRef() : TableRef(TableReferenceType::BASE_TABLE), schema_name(INVALID_SCHEMA) {
303
- }
304
-
305
- //! Schema name
306
- string schema_name;
307
- //! Table name
308
- string table_name;
309
- //! Aliases for the column names
310
- vector<string> column_name_alias;
311
-
312
- public:
313
- string ToString() const override;
314
- bool Equals(const TableRef *other_p) const override;
315
-
316
- unique_ptr<TableRef> Copy() override;
317
-
318
- //! Serializes a blob into a BaseTableRef
319
- void Serialize(Serializer &serializer) override;
320
- //! Deserializes a blob back into a BaseTableRef
321
- static unique_ptr<TableRef> Deserialize(Deserializer &source);
322
- };
323
- } // namespace duckdb
324
-
325
-
326
-
327
- namespace duckdb {
328
-
329
- struct CreateIndexInfo : public CreateInfo {
330
- CreateIndexInfo() : CreateInfo(CatalogType::INDEX_ENTRY) {
331
- }
332
-
333
- //! Index Type (e.g., B+-tree, Skip-List, ...)
334
- IndexType index_type;
335
- //! Name of the Index
336
- string index_name;
337
- //! If it is an unique index
338
- bool unique = false;
339
- //! The table to create the index on
340
- unique_ptr<BaseTableRef> table;
341
- //! Set of expressions to index by
342
- vector<unique_ptr<ParsedExpression>> expressions;
343
-
344
- public:
345
- unique_ptr<CreateInfo> Copy() const override {
346
- auto result = make_unique<CreateIndexInfo>();
347
- CopyProperties(*result);
348
- result->index_type = index_type;
349
- result->index_name = index_name;
350
- result->unique = unique;
351
- result->table = unique_ptr_cast<TableRef, BaseTableRef>(table->Copy());
352
- for (auto &expr : expressions) {
353
- result->expressions.push_back(expr->Copy());
354
- }
355
- return move(result);
356
- }
357
- };
358
-
359
- } // namespace duckdb
360
166
 
361
167
 
362
168
  namespace duckdb {
@@ -393,78 +199,7 @@ public:
393
199
 
394
200
 
395
201
 
396
- //===----------------------------------------------------------------------===//
397
- // DuckDB
398
- //
399
- // duckdb/function/macro_function.hpp
400
- //
401
- //
402
- //===----------------------------------------------------------------------===//
403
-
404
-
405
-
406
-
407
-
408
-
409
-
410
-
411
- namespace duckdb {
412
-
413
- class MacroCatalogEntry;
414
-
415
- class MacroFunction {
416
- public:
417
- explicit MacroFunction(unique_ptr<ParsedExpression> expression);
418
-
419
- //! Check whether the supplied arguments are valid
420
- static string ValidateArguments(MacroCatalogEntry &macro_func, FunctionExpression &function_expr,
421
- vector<unique_ptr<ParsedExpression>> &positionals,
422
- unordered_map<string, unique_ptr<ParsedExpression>> &defaults);
423
- //! The macro expression
424
- unique_ptr<ParsedExpression> expression;
425
- //! The positional parameters
426
- vector<unique_ptr<ParsedExpression>> parameters;
427
- //! The default parameters and their associated values
428
- unordered_map<string, unique_ptr<ParsedExpression>> default_parameters;
429
-
430
- public:
431
- unique_ptr<MacroFunction> Copy();
432
- };
433
-
434
- } // namespace duckdb
435
-
436
- //===----------------------------------------------------------------------===//
437
- // DuckDB
438
- //
439
- // duckdb/parser/parsed_data/create_macro_info.hpp
440
- //
441
- //
442
- //===----------------------------------------------------------------------===//
443
-
444
-
445
-
446
-
447
-
448
202
 
449
- namespace duckdb {
450
-
451
- struct CreateMacroInfo : public CreateFunctionInfo {
452
- CreateMacroInfo() : CreateFunctionInfo(CatalogType::MACRO_ENTRY, INVALID_SCHEMA) {
453
- }
454
-
455
- unique_ptr<MacroFunction> function;
456
-
457
- public:
458
- unique_ptr<CreateInfo> Copy() const override {
459
- auto result = make_unique<CreateMacroInfo>();
460
- result->function = function->Copy();
461
- result->name = name;
462
- CopyProperties(*result);
463
- return move(result);
464
- }
465
- };
466
-
467
- } // namespace duckdb
468
203
 
469
204
 
470
205
  namespace duckdb {
@@ -496,101 +231,6 @@ public:
496
231
 
497
232
 
498
233
 
499
- //===----------------------------------------------------------------------===//
500
- // DuckDB
501
- //
502
- // duckdb/function/pragma_function.hpp
503
- //
504
- //
505
- //===----------------------------------------------------------------------===//
506
-
507
-
508
-
509
-
510
- //===----------------------------------------------------------------------===//
511
- // DuckDB
512
- //
513
- // duckdb/parser/parsed_data/pragma_info.hpp
514
- //
515
- //
516
- //===----------------------------------------------------------------------===//
517
-
518
-
519
-
520
-
521
-
522
-
523
-
524
-
525
- namespace duckdb {
526
-
527
- enum class PragmaType : uint8_t { PRAGMA_STATEMENT, PRAGMA_CALL };
528
-
529
- struct PragmaInfo : public ParseInfo {
530
- //! Name of the PRAGMA statement
531
- string name;
532
- //! Parameter list (if any)
533
- vector<Value> parameters;
534
- //! Named parameter list (if any)
535
- unordered_map<string, Value> named_parameters;
536
-
537
- public:
538
- unique_ptr<PragmaInfo> Copy() const {
539
- auto result = make_unique<PragmaInfo>();
540
- result->name = name;
541
- result->parameters = parameters;
542
- result->named_parameters = named_parameters;
543
- return result;
544
- }
545
- };
546
-
547
- } // namespace duckdb
548
-
549
-
550
-
551
- namespace duckdb {
552
- class ClientContext;
553
-
554
- //! Return a substitute query to execute instead of this pragma statement
555
- typedef string (*pragma_query_t)(ClientContext &context, const FunctionParameters &parameters);
556
- //! Execute the main pragma function
557
- typedef void (*pragma_function_t)(ClientContext &context, const FunctionParameters &parameters);
558
-
559
- //! Pragma functions are invoked by calling PRAGMA x
560
- //! Pragma functions come in three types:
561
- //! * Call: function call, e.g. PRAGMA table_info('tbl')
562
- //! -> call statements can take multiple parameters
563
- //! * Statement: statement without parameters, e.g. PRAGMA show_tables
564
- //! -> this is similar to a call pragma but without parameters
565
- //! Pragma functions can either return a new query to execute (pragma_query_t)
566
- //! or they can
567
- class PragmaFunction : public SimpleNamedParameterFunction {
568
- public:
569
- // Call
570
- DUCKDB_API static PragmaFunction PragmaCall(const string &name, pragma_query_t query, vector<LogicalType> arguments,
571
- LogicalType varargs = LogicalType::INVALID);
572
- DUCKDB_API static PragmaFunction PragmaCall(const string &name, pragma_function_t function,
573
- vector<LogicalType> arguments,
574
- LogicalType varargs = LogicalType::INVALID);
575
- // Statement
576
- DUCKDB_API static PragmaFunction PragmaStatement(const string &name, pragma_query_t query);
577
- DUCKDB_API static PragmaFunction PragmaStatement(const string &name, pragma_function_t function);
578
-
579
- DUCKDB_API string ToString() override;
580
-
581
- public:
582
- PragmaType type;
583
-
584
- pragma_query_t query;
585
- pragma_function_t function;
586
- unordered_map<string, LogicalType> named_parameters;
587
-
588
- private:
589
- PragmaFunction(string name, PragmaType pragma_type, pragma_query_t query, pragma_function_t function,
590
- vector<LogicalType> arguments, LogicalType varargs);
591
- };
592
-
593
- } // namespace duckdb
594
234
 
595
235
 
596
236
  namespace duckdb {
@@ -608,77 +248,6 @@ public:
608
248
  };
609
249
  } // namespace duckdb
610
250
 
611
- //===----------------------------------------------------------------------===//
612
- // DuckDB
613
- //
614
- // duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp
615
- //
616
- //
617
- //===----------------------------------------------------------------------===//
618
-
619
-
620
-
621
-
622
-
623
-
624
- //===----------------------------------------------------------------------===//
625
- // DuckDB
626
- //
627
- // duckdb/parser/parsed_data/create_scalar_function_info.hpp
628
- //
629
- //
630
- //===----------------------------------------------------------------------===//
631
-
632
-
633
-
634
-
635
-
636
-
637
-
638
- namespace duckdb {
639
-
640
- struct CreateScalarFunctionInfo : public CreateFunctionInfo {
641
- explicit CreateScalarFunctionInfo(ScalarFunction function)
642
- : CreateFunctionInfo(CatalogType::SCALAR_FUNCTION_ENTRY) {
643
- this->name = function.name;
644
- functions.push_back(function);
645
- }
646
- explicit CreateScalarFunctionInfo(ScalarFunctionSet set)
647
- : CreateFunctionInfo(CatalogType::SCALAR_FUNCTION_ENTRY), functions(move(set.functions)) {
648
- this->name = set.name;
649
- for (auto &func : functions) {
650
- func.name = set.name;
651
- }
652
- }
653
-
654
- vector<ScalarFunction> functions;
655
-
656
- public:
657
- unique_ptr<CreateInfo> Copy() const override {
658
- ScalarFunctionSet set(name);
659
- set.functions = functions;
660
- auto result = make_unique<CreateScalarFunctionInfo>(move(set));
661
- CopyProperties(*result);
662
- return move(result);
663
- }
664
- };
665
-
666
- } // namespace duckdb
667
-
668
-
669
- namespace duckdb {
670
-
671
- //! A table function in the catalog
672
- class ScalarFunctionCatalogEntry : public StandardEntry {
673
- public:
674
- ScalarFunctionCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateScalarFunctionInfo *info)
675
- : StandardEntry(CatalogType::SCALAR_FUNCTION_ENTRY, schema, catalog, info->name), functions(info->functions) {
676
- }
677
-
678
- //! The scalar functions
679
- vector<ScalarFunction> functions;
680
- };
681
- } // namespace duckdb
682
251
 
683
252
 
684
253
 
@@ -870,937 +439,20 @@ private:
870
439
 
871
440
 
872
441
 
873
- //===----------------------------------------------------------------------===//
874
- // DuckDB
875
- //
876
- // duckdb/parser/expression/function_expression.hpp
877
- //
878
- //
879
- //===----------------------------------------------------------------------===//
880
-
881
-
882
-
883
-
884
-
885
-
886
-
887
- namespace duckdb {
888
- //! Represents a function call
889
- class FunctionExpression : public ParsedExpression {
890
- public:
891
- FunctionExpression(string schema_name, const string &function_name, vector<unique_ptr<ParsedExpression>> children,
892
- unique_ptr<ParsedExpression> filter = nullptr, unique_ptr<OrderModifier> order_bys = nullptr,
893
- bool distinct = false, bool is_operator = false);
894
- FunctionExpression(const string &function_name, vector<unique_ptr<ParsedExpression>> children,
895
- unique_ptr<ParsedExpression> filter = nullptr, unique_ptr<OrderModifier> order_bys = nullptr,
896
- bool distinct = false, bool is_operator = false);
897
-
898
- //! Schema of the function
899
- string schema;
900
- //! Function name
901
- string function_name;
902
- //! Whether or not the function is an operator, only used for rendering
903
- bool is_operator;
904
- //! List of arguments to the function
905
- vector<unique_ptr<ParsedExpression>> children;
906
- //! Whether or not the aggregate function is distinct, only used for aggregates
907
- bool distinct;
908
- //! Expression representing a filter, only used for aggregates
909
- unique_ptr<ParsedExpression> filter;
910
- //! Modifier representing an ORDER BY, only used for aggregates
911
- unique_ptr<OrderModifier> order_bys;
912
-
913
- public:
914
- string ToString() const override;
915
-
916
- unique_ptr<ParsedExpression> Copy() const override;
917
-
918
- static bool Equals(const FunctionExpression *a, const FunctionExpression *b);
919
- hash_t Hash() const override;
920
-
921
- //! Serializes a FunctionExpression to a stand-alone binary blob
922
- void Serialize(Serializer &serializer) override;
923
- //! Deserializes a blob back into an FunctionExpression
924
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
925
- };
926
- } // namespace duckdb
927
-
928
-
929
-
930
-
931
-
932
-
933
- //===----------------------------------------------------------------------===//
934
- // DuckDB
935
- //
936
- // duckdb/parser/parsed_data/create_pragma_function_info.hpp
937
- //
938
- //
939
- //===----------------------------------------------------------------------===//
940
-
941
-
942
-
943
-
944
-
945
-
946
- namespace duckdb {
947
-
948
- struct CreatePragmaFunctionInfo : public CreateFunctionInfo {
949
- explicit CreatePragmaFunctionInfo(PragmaFunction function)
950
- : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY) {
951
- functions.push_back(move(function));
952
- this->name = function.name;
953
- }
954
- CreatePragmaFunctionInfo(string name, vector<PragmaFunction> functions_)
955
- : CreateFunctionInfo(CatalogType::PRAGMA_FUNCTION_ENTRY), functions(move(functions_)) {
956
- this->name = name;
957
- for (auto &function : functions) {
958
- function.name = name;
959
- }
960
- }
961
-
962
- vector<PragmaFunction> functions;
963
-
964
- public:
965
- unique_ptr<CreateInfo> Copy() const override {
966
- auto result = make_unique<CreatePragmaFunctionInfo>(functions[0].name, functions);
967
- CopyProperties(*result);
968
- return move(result);
969
- }
970
- };
971
-
972
- } // namespace duckdb
973
-
974
-
975
- //===----------------------------------------------------------------------===//
976
- // DuckDB
977
- //
978
- // duckdb/parser/parsed_data/create_schema_info.hpp
979
- //
980
- //
981
- //===----------------------------------------------------------------------===//
982
-
983
-
984
-
985
-
986
-
987
- namespace duckdb {
988
-
989
- struct CreateSchemaInfo : public CreateInfo {
990
- CreateSchemaInfo() : CreateInfo(CatalogType::SCHEMA_ENTRY) {
991
- }
992
-
993
- public:
994
- unique_ptr<CreateInfo> Copy() const override {
995
- auto result = make_unique<CreateSchemaInfo>();
996
- CopyProperties(*result);
997
- return move(result);
998
- }
999
- };
1000
-
1001
- } // namespace duckdb
1002
-
1003
-
1004
-
1005
- //===----------------------------------------------------------------------===//
1006
- // DuckDB
1007
- //
1008
- // duckdb/parser/parsed_data/create_type_info.hpp
1009
- //
1010
- //
1011
- //===----------------------------------------------------------------------===//
1012
-
1013
-
1014
-
1015
-
1016
-
1017
-
1018
-
1019
-
1020
- namespace duckdb {
1021
-
1022
- struct CreateTypeInfo : public CreateInfo {
1023
-
1024
- CreateTypeInfo() : CreateInfo(CatalogType::TYPE_ENTRY) {
1025
- }
1026
-
1027
- //! Name of the Type
1028
- string name;
1029
- //! Shared Pointer of Logical Type
1030
- unique_ptr<LogicalType> type;
1031
-
1032
- public:
1033
- unique_ptr<CreateInfo> Copy() const override {
1034
- auto result = make_unique<CreateTypeInfo>();
1035
- CopyProperties(*result);
1036
- result->name = name;
1037
- result->type = make_unique<LogicalType>(*type);
1038
- return move(result);
1039
- }
1040
- };
1041
-
1042
- } // namespace duckdb
1043
-
1044
- //===----------------------------------------------------------------------===//
1045
- // DuckDB
1046
- //
1047
- // duckdb/parser/parsed_data/create_view_info.hpp
1048
- //
1049
- //
1050
- //===----------------------------------------------------------------------===//
1051
-
1052
-
1053
-
1054
-
1055
-
1056
-
1057
- namespace duckdb {
1058
-
1059
- struct CreateViewInfo : public CreateInfo {
1060
- CreateViewInfo() : CreateInfo(CatalogType::VIEW_ENTRY, INVALID_SCHEMA) {
1061
- }
1062
- CreateViewInfo(string schema, string view_name)
1063
- : CreateInfo(CatalogType::VIEW_ENTRY, schema), view_name(view_name) {
1064
- }
1065
-
1066
- //! Table name to insert to
1067
- string view_name;
1068
- //! Aliases of the view
1069
- vector<string> aliases;
1070
- //! Return types
1071
- vector<LogicalType> types;
1072
- //! The SelectStatement of the view
1073
- unique_ptr<SelectStatement> query;
1074
-
1075
- public:
1076
- unique_ptr<CreateInfo> Copy() const override {
1077
- auto result = make_unique<CreateViewInfo>(schema, view_name);
1078
- CopyProperties(*result);
1079
- result->aliases = aliases;
1080
- result->types = types;
1081
- result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
1082
- return move(result);
1083
- }
1084
- };
1085
-
1086
- } // namespace duckdb
1087
-
1088
- //===----------------------------------------------------------------------===//
1089
- // DuckDB
1090
- //
1091
- // duckdb/parser/parsed_data/drop_info.hpp
1092
- //
1093
- //
1094
- //===----------------------------------------------------------------------===//
1095
-
1096
-
1097
-
1098
-
1099
-
1100
-
1101
- namespace duckdb {
1102
-
1103
- struct DropInfo : public ParseInfo {
1104
- DropInfo() : schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
1105
- }
1106
-
1107
- //! The catalog type to drop
1108
- CatalogType type;
1109
- //! Schema name to drop from, if any
1110
- string schema;
1111
- //! Element name to drop
1112
- string name;
1113
- //! Ignore if the entry does not exist instead of failing
1114
- bool if_exists = false;
1115
- //! Cascade drop (drop all dependents instead of throwing an error if there
1116
- //! are any)
1117
- bool cascade = false;
1118
-
1119
- public:
1120
- unique_ptr<DropInfo> Copy() const {
1121
- auto result = make_unique<DropInfo>();
1122
- result->type = type;
1123
- result->schema = schema;
1124
- result->name = name;
1125
- result->if_exists = if_exists;
1126
- result->cascade = cascade;
1127
- return result;
1128
- }
1129
- };
1130
-
1131
- } // namespace duckdb
1132
-
1133
- //===----------------------------------------------------------------------===//
1134
- // DuckDB
1135
- //
1136
- // duckdb/planner/parsed_data/bound_create_table_info.hpp
1137
- //
1138
- //
1139
- //===----------------------------------------------------------------------===//
1140
-
1141
-
1142
-
1143
- //===----------------------------------------------------------------------===//
1144
- // DuckDB
1145
- //
1146
- // duckdb/parser/parsed_data/create_table_info.hpp
1147
- //
1148
- //
1149
- //===----------------------------------------------------------------------===//
1150
-
1151
-
1152
-
1153
-
1154
-
1155
-
1156
-
1157
-
1158
-
1159
- namespace duckdb {
1160
-
1161
- struct CreateTableInfo : public CreateInfo {
1162
- CreateTableInfo() : CreateInfo(CatalogType::TABLE_ENTRY, INVALID_SCHEMA) {
1163
- }
1164
- CreateTableInfo(string schema, string name) : CreateInfo(CatalogType::TABLE_ENTRY, schema), table(name) {
1165
- }
1166
-
1167
- //! Table name to insert to
1168
- string table;
1169
- //! List of columns of the table
1170
- vector<ColumnDefinition> columns;
1171
- //! List of constraints on the table
1172
- vector<unique_ptr<Constraint>> constraints;
1173
- //! CREATE TABLE from QUERY
1174
- unique_ptr<SelectStatement> query;
1175
-
1176
- public:
1177
- unique_ptr<CreateInfo> Copy() const override {
1178
- auto result = make_unique<CreateTableInfo>(schema, table);
1179
- CopyProperties(*result);
1180
- for (auto &column : columns) {
1181
- result->columns.push_back(column.Copy());
1182
- }
1183
- for (auto &constraint : constraints) {
1184
- result->constraints.push_back(constraint->Copy());
1185
- }
1186
- if (query) {
1187
- result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
1188
- }
1189
- return move(result);
1190
- }
1191
- };
1192
-
1193
- } // namespace duckdb
1194
-
1195
-
1196
-
1197
-
1198
- //===----------------------------------------------------------------------===//
1199
- // DuckDB
1200
- //
1201
- // duckdb/storage/table/persistent_table_data.hpp
1202
- //
1203
- //
1204
- //===----------------------------------------------------------------------===//
1205
-
1206
-
1207
-
1208
-
1209
-
1210
- //===----------------------------------------------------------------------===//
1211
- // DuckDB
1212
- //
1213
- // duckdb/storage/table/segment_tree.hpp
1214
- //
1215
- //
1216
- //===----------------------------------------------------------------------===//
1217
-
1218
-
1219
-
1220
-
1221
-
1222
- //===----------------------------------------------------------------------===//
1223
- // DuckDB
1224
- //
1225
- // duckdb/storage/table/segment_base.hpp
1226
- //
1227
- //
1228
- //===----------------------------------------------------------------------===//
1229
-
1230
-
1231
-
1232
-
1233
-
1234
-
1235
- namespace duckdb {
1236
-
1237
- class SegmentBase {
1238
- public:
1239
- SegmentBase(idx_t start, idx_t count) : start(start), count(count) {
1240
- }
1241
- virtual ~SegmentBase() {
1242
- // destroy the chain of segments iteratively (rather than recursively)
1243
- while (next && next->next) {
1244
- next = move(next->next);
1245
- }
1246
- }
1247
-
1248
- //! The start row id of this chunk
1249
- const idx_t start;
1250
- //! The amount of entries in this storage chunk
1251
- atomic<idx_t> count;
1252
- //! The next segment after this one
1253
- unique_ptr<SegmentBase> next;
1254
- };
1255
-
1256
- } // namespace duckdb
1257
-
1258
-
1259
-
1260
-
1261
- namespace duckdb {
1262
-
1263
- struct SegmentNode {
1264
- idx_t row_start;
1265
- SegmentBase *node;
1266
- };
1267
-
1268
- //! The SegmentTree maintains a list of all segments of a specific column in a table, and allows searching for a segment
1269
- //! by row number
1270
- class SegmentTree {
1271
- public:
1272
- //! The initial segment of the tree
1273
- unique_ptr<SegmentBase> root_node;
1274
- //! The nodes in the tree, can be binary searched
1275
- vector<SegmentNode> nodes;
1276
- //! Lock to access or modify the nodes
1277
- mutex node_lock;
1278
-
1279
- public:
1280
- //! Gets a pointer to the first segment. Useful for scans.
1281
- SegmentBase *GetRootSegment();
1282
- //! Gets a pointer to the last segment. Useful for appends.
1283
- SegmentBase *GetLastSegment();
1284
- //! Gets a pointer to a specific column segment for the given row
1285
- SegmentBase *GetSegment(idx_t row_number);
1286
- //! Append a column segment to the tree
1287
- void AppendSegment(unique_ptr<SegmentBase> segment);
1288
-
1289
- //! Replace this tree with another tree, taking over its nodes in-place
1290
- void Replace(SegmentTree &other);
1291
-
1292
- //! Get the segment index of the column segment for the given row (does not lock the segment tree!)
1293
- idx_t GetSegmentIndex(idx_t row_number);
1294
- };
1295
-
1296
- } // namespace duckdb
1297
-
1298
- //===----------------------------------------------------------------------===//
1299
- // DuckDB
1300
- //
1301
- // duckdb/storage/data_pointer.hpp
1302
- //
1303
- //
1304
- //===----------------------------------------------------------------------===//
1305
-
1306
-
1307
-
1308
-
1309
442
 
1310
443
 
1311
- //===----------------------------------------------------------------------===//
1312
- // DuckDB
1313
- //
1314
- // duckdb/storage/block.hpp
1315
- //
1316
- //
1317
- //===----------------------------------------------------------------------===//
1318
-
1319
444
 
1320
445
 
1321
446
 
1322
447
 
1323
448
 
1324
449
 
1325
- namespace duckdb {
1326
450
 
1327
- class Block : public FileBuffer {
1328
- public:
1329
- Block(Allocator &allocator, block_id_t id);
1330
- Block(FileBuffer &source, block_id_t id);
1331
451
 
1332
- block_id_t id;
1333
- };
1334
452
 
1335
- struct BlockPointer {
1336
- block_id_t block_id;
1337
- uint32_t offset;
1338
- };
1339
453
 
1340
- } // namespace duckdb
1341
454
 
1342
- //===----------------------------------------------------------------------===//
1343
- // DuckDB
1344
- //
1345
- // duckdb/storage/table/row_group.hpp
1346
- //
1347
- //
1348
- //===----------------------------------------------------------------------===//
1349
-
1350
-
1351
-
1352
-
1353
-
1354
- //===----------------------------------------------------------------------===//
1355
- // DuckDB
1356
- //
1357
- // duckdb/storage/table/chunk_info.hpp
1358
- //
1359
- //
1360
- //===----------------------------------------------------------------------===//
1361
-
1362
-
1363
-
1364
-
1365
-
1366
-
1367
-
1368
- namespace duckdb {
1369
- class RowGroup;
1370
- struct SelectionVector;
1371
- class Transaction;
1372
455
 
1373
- enum class ChunkInfoType : uint8_t { CONSTANT_INFO, VECTOR_INFO, EMPTY_INFO };
1374
-
1375
- class ChunkInfo {
1376
- public:
1377
- ChunkInfo(idx_t start, ChunkInfoType type) : start(start), type(type) {
1378
- }
1379
- virtual ~ChunkInfo() {
1380
- }
1381
-
1382
- //! The row index of the first row
1383
- idx_t start;
1384
- //! The ChunkInfo type
1385
- ChunkInfoType type;
1386
-
1387
- public:
1388
- //! Gets up to max_count entries from the chunk info. If the ret is 0>ret>max_count, the selection vector is filled
1389
- //! with the tuples
1390
- virtual idx_t GetSelVector(Transaction &transaction, SelectionVector &sel_vector, idx_t max_count) = 0;
1391
- virtual idx_t GetCommittedSelVector(transaction_t min_start_id, transaction_t min_transaction_id,
1392
- SelectionVector &sel_vector, idx_t max_count) = 0;
1393
- //! Returns whether or not a single row in the ChunkInfo should be used or not for the given transaction
1394
- virtual bool Fetch(Transaction &transaction, row_t row) = 0;
1395
- virtual void CommitAppend(transaction_t commit_id, idx_t start, idx_t end) = 0;
1396
-
1397
- virtual void Serialize(Serializer &serialize) = 0;
1398
- static unique_ptr<ChunkInfo> Deserialize(Deserializer &source);
1399
- };
1400
-
1401
- class ChunkConstantInfo : public ChunkInfo {
1402
- public:
1403
- ChunkConstantInfo(idx_t start);
1404
-
1405
- atomic<transaction_t> insert_id;
1406
- atomic<transaction_t> delete_id;
1407
-
1408
- public:
1409
- idx_t GetSelVector(Transaction &transaction, SelectionVector &sel_vector, idx_t max_count) override;
1410
- idx_t GetCommittedSelVector(transaction_t min_start_id, transaction_t min_transaction_id,
1411
- SelectionVector &sel_vector, idx_t max_count) override;
1412
- bool Fetch(Transaction &transaction, row_t row) override;
1413
- void CommitAppend(transaction_t commit_id, idx_t start, idx_t end) override;
1414
-
1415
- void Serialize(Serializer &serialize) override;
1416
- static unique_ptr<ChunkInfo> Deserialize(Deserializer &source);
1417
-
1418
- private:
1419
- template <class OP>
1420
- idx_t TemplatedGetSelVector(transaction_t start_time, transaction_t transaction_id, SelectionVector &sel_vector,
1421
- idx_t max_count);
1422
- };
1423
-
1424
- class ChunkVectorInfo : public ChunkInfo {
1425
- public:
1426
- ChunkVectorInfo(idx_t start);
1427
-
1428
- //! The transaction ids of the transactions that inserted the tuples (if any)
1429
- atomic<transaction_t> inserted[STANDARD_VECTOR_SIZE];
1430
- atomic<transaction_t> insert_id;
1431
- atomic<bool> same_inserted_id;
1432
-
1433
- //! The transaction ids of the transactions that deleted the tuples (if any)
1434
- atomic<transaction_t> deleted[STANDARD_VECTOR_SIZE];
1435
- atomic<bool> any_deleted;
1436
-
1437
- public:
1438
- idx_t GetSelVector(transaction_t start_time, transaction_t transaction_id, SelectionVector &sel_vector,
1439
- idx_t max_count);
1440
- idx_t GetSelVector(Transaction &transaction, SelectionVector &sel_vector, idx_t max_count) override;
1441
- idx_t GetCommittedSelVector(transaction_t min_start_id, transaction_t min_transaction_id,
1442
- SelectionVector &sel_vector, idx_t max_count) override;
1443
- bool Fetch(Transaction &transaction, row_t row) override;
1444
- void CommitAppend(transaction_t commit_id, idx_t start, idx_t end) override;
1445
-
1446
- void Append(idx_t start, idx_t end, transaction_t commit_id);
1447
- idx_t Delete(Transaction &transaction, row_t rows[], idx_t count);
1448
- void CommitDelete(transaction_t commit_id, row_t rows[], idx_t count);
1449
-
1450
- void Serialize(Serializer &serialize) override;
1451
- static unique_ptr<ChunkInfo> Deserialize(Deserializer &source);
1452
-
1453
- private:
1454
- template <class OP>
1455
- idx_t TemplatedGetSelVector(transaction_t start_time, transaction_t transaction_id, SelectionVector &sel_vector,
1456
- idx_t max_count);
1457
- };
1458
-
1459
- } // namespace duckdb
1460
-
1461
- //===----------------------------------------------------------------------===//
1462
- // DuckDB
1463
- //
1464
- // duckdb/storage/table/append_state.hpp
1465
- //
1466
- //
1467
- //===----------------------------------------------------------------------===//
1468
-
1469
-
1470
-
1471
-
1472
-
1473
-
1474
-
1475
-
1476
- namespace duckdb {
1477
- class ColumnSegment;
1478
- class DataTable;
1479
- class RowGroup;
1480
- class UpdateSegment;
1481
- class ValiditySegment;
1482
-
1483
- struct TableAppendState;
1484
-
1485
- struct ColumnAppendState {
1486
- //! The current segment of the append
1487
- ColumnSegment *current;
1488
- //! Child append states
1489
- vector<ColumnAppendState> child_appends;
1490
- //! The write lock that is held by the append
1491
- unique_ptr<StorageLockKey> lock;
1492
- };
1493
-
1494
- struct RowGroupAppendState {
1495
- RowGroupAppendState(TableAppendState &parent_p) : parent(parent_p) {
1496
- }
1497
-
1498
- //! The parent append state
1499
- TableAppendState &parent;
1500
- //! The current row_group we are appending to
1501
- RowGroup *row_group;
1502
- //! The column append states
1503
- unique_ptr<ColumnAppendState[]> states;
1504
- //! Offset within the row_group
1505
- idx_t offset_in_row_group;
1506
- };
1507
-
1508
- struct IndexLock {
1509
- unique_lock<mutex> index_lock;
1510
- };
1511
-
1512
- struct TableAppendState {
1513
- TableAppendState() : row_group_append_state(*this) {
1514
- }
1515
-
1516
- RowGroupAppendState row_group_append_state;
1517
- unique_lock<mutex> append_lock;
1518
- row_t row_start;
1519
- row_t current_row;
1520
- idx_t remaining_append_count;
1521
- };
1522
-
1523
- } // namespace duckdb
1524
-
1525
-
1526
- //===----------------------------------------------------------------------===//
1527
- // DuckDB
1528
- //
1529
- // duckdb/storage/statistics/segment_statistics.hpp
1530
- //
1531
- //
1532
- //===----------------------------------------------------------------------===//
1533
-
1534
-
1535
-
1536
-
1537
-
1538
-
1539
-
1540
- namespace duckdb {
1541
-
1542
- class SegmentStatistics {
1543
- public:
1544
- SegmentStatistics(LogicalType type);
1545
- SegmentStatistics(LogicalType type, unique_ptr<BaseStatistics> statistics);
1546
-
1547
- LogicalType type;
1548
-
1549
- //! Type-specific statistics of the segment
1550
- unique_ptr<BaseStatistics> statistics;
1551
-
1552
- public:
1553
- void Reset();
1554
- };
1555
-
1556
- } // namespace duckdb
1557
-
1558
- //===----------------------------------------------------------------------===//
1559
- // DuckDB
1560
- //
1561
- // duckdb/common/enums/scan_options.hpp
1562
- //
1563
- //
1564
- //===----------------------------------------------------------------------===//
1565
-
1566
-
1567
-
1568
-
1569
-
1570
- namespace duckdb {
1571
-
1572
- enum class TableScanType : uint8_t {
1573
- //! Regular table scan: scan all tuples that are relevant for the current transaction
1574
- TABLE_SCAN_REGULAR = 0,
1575
- //! Scan all rows, including any deleted rows. Committed updates are merged in.
1576
- TABLE_SCAN_COMMITTED_ROWS = 1,
1577
- //! Scan all rows, including any deleted rows. Throws an exception if there are any uncommitted updates.
1578
- TABLE_SCAN_COMMITTED_ROWS_DISALLOW_UPDATES = 2,
1579
- //! Scan all rows, excluding any permanently deleted rows.
1580
- //! Permanently deleted rows are rows which no transaction will ever need again.
1581
- TABLE_SCAN_COMMITTED_ROWS_OMIT_PERMANENTLY_DELETED = 3
1582
- };
1583
-
1584
- } // namespace duckdb
1585
-
1586
-
1587
-
1588
- namespace duckdb {
1589
- class ColumnData;
1590
- class DatabaseInstance;
1591
- class DataTable;
1592
- struct DataTableInfo;
1593
- class ExpressionExecutor;
1594
- class TableDataWriter;
1595
- class UpdateSegment;
1596
- class Vector;
1597
- struct RowGroupPointer;
1598
- struct VersionNode;
1599
-
1600
- class RowGroup : public SegmentBase {
1601
- public:
1602
- friend class ColumnData;
1603
- friend class VersionDeleteState;
1604
-
1605
- public:
1606
- static constexpr const idx_t ROW_GROUP_VECTOR_COUNT = 120;
1607
- static constexpr const idx_t ROW_GROUP_SIZE = STANDARD_VECTOR_SIZE * ROW_GROUP_VECTOR_COUNT;
1608
-
1609
- public:
1610
- RowGroup(DatabaseInstance &db, DataTableInfo &table_info, idx_t start, idx_t count);
1611
- RowGroup(DatabaseInstance &db, DataTableInfo &table_info, const vector<LogicalType> &types,
1612
- RowGroupPointer &pointer);
1613
- ~RowGroup();
1614
-
1615
- private:
1616
- //! The database instance
1617
- DatabaseInstance &db;
1618
- //! The table info of this row_group
1619
- DataTableInfo &table_info;
1620
- //! The version info of the row_group (inserted and deleted tuple info)
1621
- shared_ptr<VersionNode> version_info;
1622
- //! The column data of the row_group
1623
- vector<shared_ptr<ColumnData>> columns;
1624
- //! The segment statistics for each of the columns
1625
- vector<shared_ptr<SegmentStatistics>> stats;
1626
-
1627
- public:
1628
- DatabaseInstance &GetDatabase() {
1629
- return db;
1630
- }
1631
- DataTableInfo &GetTableInfo() {
1632
- return table_info;
1633
- }
1634
- idx_t GetColumnIndex(ColumnData *data) {
1635
- for (idx_t i = 0; i < columns.size(); i++) {
1636
- if (columns[i].get() == data) {
1637
- return i;
1638
- }
1639
- }
1640
- return 0;
1641
- }
1642
-
1643
- unique_ptr<RowGroup> AlterType(ClientContext &context, const LogicalType &target_type, idx_t changed_idx,
1644
- ExpressionExecutor &executor, TableScanState &scan_state, DataChunk &scan_chunk);
1645
- unique_ptr<RowGroup> AddColumn(ClientContext &context, ColumnDefinition &new_column, ExpressionExecutor &executor,
1646
- Expression *default_value, Vector &intermediate);
1647
- unique_ptr<RowGroup> RemoveColumn(idx_t removed_column);
1648
-
1649
- void CommitDrop();
1650
- void CommitDropColumn(idx_t index);
1651
-
1652
- void InitializeEmpty(const vector<LogicalType> &types);
1653
-
1654
- //! Initialize a scan over this row_group
1655
- bool InitializeScan(RowGroupScanState &state);
1656
- bool InitializeScanWithOffset(RowGroupScanState &state, idx_t vector_offset);
1657
- //! Checks the given set of table filters against the row-group statistics. Returns false if the entire row group
1658
- //! can be skipped.
1659
- bool CheckZonemap(TableFilterSet &filters, const vector<column_t> &column_ids);
1660
- //! Checks the given set of table filters against the per-segment statistics. Returns false if any segments were
1661
- //! skipped.
1662
- bool CheckZonemapSegments(RowGroupScanState &state);
1663
- void Scan(Transaction &transaction, RowGroupScanState &state, DataChunk &result);
1664
- void ScanCommitted(RowGroupScanState &state, DataChunk &result, TableScanType type);
1665
-
1666
- idx_t GetSelVector(Transaction &transaction, idx_t vector_idx, SelectionVector &sel_vector, idx_t max_count);
1667
- idx_t GetCommittedSelVector(transaction_t start_time, transaction_t transaction_id, idx_t vector_idx,
1668
- SelectionVector &sel_vector, idx_t max_count);
1669
-
1670
- //! For a specific row, returns true if it should be used for the transaction and false otherwise.
1671
- bool Fetch(Transaction &transaction, idx_t row);
1672
- //! Fetch a specific row from the row_group and insert it into the result at the specified index
1673
- void FetchRow(Transaction &transaction, ColumnFetchState &state, const vector<column_t> &column_ids, row_t row_id,
1674
- DataChunk &result, idx_t result_idx);
1675
-
1676
- //! Append count rows to the version info
1677
- void AppendVersionInfo(Transaction &transaction, idx_t start, idx_t count, transaction_t commit_id);
1678
- //! Commit a previous append made by RowGroup::AppendVersionInfo
1679
- void CommitAppend(transaction_t commit_id, idx_t start, idx_t count);
1680
- //! Revert a previous append made by RowGroup::AppendVersionInfo
1681
- void RevertAppend(idx_t start);
1682
-
1683
- //! Delete the given set of rows in the version manager
1684
- idx_t Delete(Transaction &transaction, DataTable *table, row_t *row_ids, idx_t count);
1685
-
1686
- RowGroupPointer Checkpoint(TableDataWriter &writer, vector<unique_ptr<BaseStatistics>> &global_stats);
1687
- static void Serialize(RowGroupPointer &pointer, Serializer &serializer);
1688
- static RowGroupPointer Deserialize(Deserializer &source, const vector<ColumnDefinition> &columns);
1689
-
1690
- void InitializeAppend(Transaction &transaction, RowGroupAppendState &append_state, idx_t remaining_append_count);
1691
- void Append(RowGroupAppendState &append_state, DataChunk &chunk, idx_t append_count);
1692
-
1693
- void Update(Transaction &transaction, DataChunk &updates, row_t *ids, idx_t offset, idx_t count,
1694
- const vector<column_t> &column_ids);
1695
- //! Update a single column; corresponds to DataTable::UpdateColumn
1696
- //! This method should only be called from the WAL
1697
- void UpdateColumn(Transaction &transaction, DataChunk &updates, Vector &row_ids,
1698
- const vector<column_t> &column_path);
1699
-
1700
- void MergeStatistics(idx_t column_idx, BaseStatistics &other);
1701
- unique_ptr<BaseStatistics> GetStatistics(idx_t column_idx);
1702
-
1703
- void GetStorageInfo(idx_t row_group_index, vector<vector<Value>> &result);
1704
-
1705
- void Verify();
1706
-
1707
- void NextVector(RowGroupScanState &state);
1708
-
1709
- private:
1710
- ChunkInfo *GetChunkInfo(idx_t vector_idx);
1711
-
1712
- template <TableScanType TYPE>
1713
- void TemplatedScan(Transaction *transaction, RowGroupScanState &state, DataChunk &result);
1714
-
1715
- static void CheckpointDeletes(VersionNode *versions, Serializer &serializer);
1716
- static shared_ptr<VersionNode> DeserializeDeletes(Deserializer &source);
1717
-
1718
- private:
1719
- mutex row_group_lock;
1720
- mutex stats_lock;
1721
- };
1722
-
1723
- struct VersionNode {
1724
- unique_ptr<ChunkInfo> info[RowGroup::ROW_GROUP_VECTOR_COUNT];
1725
- };
1726
-
1727
- } // namespace duckdb
1728
-
1729
-
1730
-
1731
- namespace duckdb {
1732
-
1733
- struct DataPointer {
1734
- uint64_t row_start;
1735
- uint64_t tuple_count;
1736
- BlockPointer block_pointer;
1737
- CompressionType compression_type;
1738
- //! Type-specific statistics of the segment
1739
- unique_ptr<BaseStatistics> statistics;
1740
- };
1741
-
1742
- struct RowGroupPointer {
1743
- uint64_t row_start;
1744
- uint64_t tuple_count;
1745
- //! The data pointers of the column segments stored in the row group
1746
- vector<BlockPointer> data_pointers;
1747
- //! The per-column statistics of the row group
1748
- vector<unique_ptr<BaseStatistics>> statistics;
1749
- //! The versions information of the row group (if any)
1750
- shared_ptr<VersionNode> versions;
1751
- };
1752
-
1753
- } // namespace duckdb
1754
-
1755
-
1756
- namespace duckdb {
1757
- class BaseStatistics;
1758
-
1759
- class PersistentTableData {
1760
- public:
1761
- explicit PersistentTableData(idx_t column_count);
1762
- ~PersistentTableData();
1763
-
1764
- vector<RowGroupPointer> row_groups;
1765
- vector<unique_ptr<BaseStatistics>> column_stats;
1766
- };
1767
-
1768
- } // namespace duckdb
1769
-
1770
-
1771
-
1772
- namespace duckdb {
1773
- class CatalogEntry;
1774
-
1775
- struct BoundCreateTableInfo {
1776
- explicit BoundCreateTableInfo(unique_ptr<CreateInfo> base) : base(move(base)) {
1777
- }
1778
-
1779
- //! The schema to create the table in
1780
- SchemaCatalogEntry *schema;
1781
- //! The base CreateInfo object
1782
- unique_ptr<CreateInfo> base;
1783
- //! The map of column names -> column index, used during binding
1784
- case_insensitive_map_t<column_t> name_map;
1785
- //! List of constraints on the table
1786
- vector<unique_ptr<Constraint>> constraints;
1787
- //! List of bound constraints on the table
1788
- vector<unique_ptr<BoundConstraint>> bound_constraints;
1789
- //! Bound default values
1790
- vector<unique_ptr<Expression>> bound_defaults;
1791
- //! Dependents of the table (in e.g. default values)
1792
- unordered_set<CatalogEntry *> dependencies;
1793
- //! The existing table data on disk (if any)
1794
- unique_ptr<PersistentTableData> data;
1795
- //! CREATE TABLE from QUERY
1796
- unique_ptr<LogicalOperator> query;
1797
-
1798
- CreateTableInfo &Base() {
1799
- return (CreateTableInfo &)*base;
1800
- }
1801
- };
1802
-
1803
- } // namespace duckdb
1804
456
 
1805
457
 
1806
458
 
@@ -2175,1122 +827,6 @@ CopyFunctionCatalogEntry::CopyFunctionCatalogEntry(Catalog *catalog, SchemaCatal
2175
827
 
2176
828
  } // namespace duckdb
2177
829
 
2178
- //===----------------------------------------------------------------------===//
2179
- // DuckDB
2180
- //
2181
- // duckdb/storage/data_table.hpp
2182
- //
2183
- //
2184
- //===----------------------------------------------------------------------===//
2185
-
2186
-
2187
-
2188
-
2189
-
2190
- //===----------------------------------------------------------------------===//
2191
- // DuckDB
2192
- //
2193
- // duckdb/storage/index.hpp
2194
- //
2195
- //
2196
- //===----------------------------------------------------------------------===//
2197
-
2198
-
2199
-
2200
-
2201
-
2202
-
2203
-
2204
-
2205
-
2206
- //===----------------------------------------------------------------------===//
2207
- // DuckDB
2208
- //
2209
- // duckdb/execution/expression_executor.hpp
2210
- //
2211
- //
2212
- //===----------------------------------------------------------------------===//
2213
-
2214
-
2215
-
2216
-
2217
-
2218
-
2219
-
2220
-
2221
- namespace duckdb {
2222
- class ExecutionContext;
2223
- //! ExpressionExecutor is responsible for executing a set of expressions and storing the result in a data chunk
2224
- class ExpressionExecutor {
2225
- public:
2226
- DUCKDB_API ExpressionExecutor();
2227
- DUCKDB_API explicit ExpressionExecutor(const Expression *expression);
2228
- DUCKDB_API explicit ExpressionExecutor(const Expression &expression);
2229
- DUCKDB_API explicit ExpressionExecutor(const vector<unique_ptr<Expression>> &expressions);
2230
-
2231
- //! Add an expression to the set of to-be-executed expressions of the executor
2232
- DUCKDB_API void AddExpression(const Expression &expr);
2233
-
2234
- //! Execute the set of expressions with the given input chunk and store the result in the output chunk
2235
- DUCKDB_API void Execute(DataChunk *input, DataChunk &result);
2236
- inline void Execute(DataChunk &input, DataChunk &result) {
2237
- Execute(&input, result);
2238
- }
2239
- inline void Execute(DataChunk &result) {
2240
- Execute(nullptr, result);
2241
- }
2242
-
2243
- //! Execute the ExpressionExecutor and put the result in the result vector; this should only be used for expression
2244
- //! executors with a single expression
2245
- DUCKDB_API void ExecuteExpression(DataChunk &input, Vector &result);
2246
- //! Execute the ExpressionExecutor and put the result in the result vector; this should only be used for expression
2247
- //! executors with a single expression
2248
- DUCKDB_API void ExecuteExpression(Vector &result);
2249
- //! Execute the ExpressionExecutor and generate a selection vector from all true values in the result; this should
2250
- //! only be used with a single boolean expression
2251
- DUCKDB_API idx_t SelectExpression(DataChunk &input, SelectionVector &sel);
2252
-
2253
- //! Execute the expression with index `expr_idx` and store the result in the result vector
2254
- DUCKDB_API void ExecuteExpression(idx_t expr_idx, Vector &result);
2255
- //! Evaluate a scalar expression and fold it into a single value
2256
- DUCKDB_API static Value EvaluateScalar(const Expression &expr);
2257
- //! Try to evaluate a scalar expression and fold it into a single value, returns false if an exception is thrown
2258
- DUCKDB_API static bool TryEvaluateScalar(const Expression &expr, Value &result);
2259
-
2260
- //! Initialize the state of a given expression
2261
- static unique_ptr<ExpressionState> InitializeState(const Expression &expr, ExpressionExecutorState &state);
2262
-
2263
- inline void SetChunk(DataChunk *chunk) {
2264
- this->chunk = chunk;
2265
- }
2266
- inline void SetChunk(DataChunk &chunk) {
2267
- SetChunk(&chunk);
2268
- }
2269
-
2270
- DUCKDB_API vector<unique_ptr<ExpressionExecutorState>> &GetStates();
2271
-
2272
- //! The expressions of the executor
2273
- vector<const Expression *> expressions;
2274
- //! The data chunk of the current physical operator, used to resolve
2275
- //! column references and determines the output cardinality
2276
- DataChunk *chunk = nullptr;
2277
-
2278
- protected:
2279
- void Initialize(const Expression &expr, ExpressionExecutorState &state);
2280
-
2281
- static unique_ptr<ExpressionState> InitializeState(const BoundReferenceExpression &expr,
2282
- ExpressionExecutorState &state);
2283
- static unique_ptr<ExpressionState> InitializeState(const BoundBetweenExpression &expr,
2284
- ExpressionExecutorState &state);
2285
- static unique_ptr<ExpressionState> InitializeState(const BoundCaseExpression &expr, ExpressionExecutorState &state);
2286
- static unique_ptr<ExpressionState> InitializeState(const BoundCastExpression &expr, ExpressionExecutorState &state);
2287
- static unique_ptr<ExpressionState> InitializeState(const BoundComparisonExpression &expr,
2288
- ExpressionExecutorState &state);
2289
- static unique_ptr<ExpressionState> InitializeState(const BoundConjunctionExpression &expr,
2290
- ExpressionExecutorState &state);
2291
- static unique_ptr<ExpressionState> InitializeState(const BoundConstantExpression &expr,
2292
- ExpressionExecutorState &state);
2293
- static unique_ptr<ExpressionState> InitializeState(const BoundFunctionExpression &expr,
2294
- ExpressionExecutorState &state);
2295
- static unique_ptr<ExpressionState> InitializeState(const BoundOperatorExpression &expr,
2296
- ExpressionExecutorState &state);
2297
- static unique_ptr<ExpressionState> InitializeState(const BoundParameterExpression &expr,
2298
- ExpressionExecutorState &state);
2299
-
2300
- void Execute(const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2301
- Vector &result);
2302
-
2303
- void Execute(const BoundBetweenExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2304
- Vector &result);
2305
- void Execute(const BoundCaseExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2306
- Vector &result);
2307
- void Execute(const BoundCastExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2308
- Vector &result);
2309
-
2310
- void Execute(const BoundComparisonExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2311
- Vector &result);
2312
- void Execute(const BoundConjunctionExpression &expr, ExpressionState *state, const SelectionVector *sel,
2313
- idx_t count, Vector &result);
2314
- void Execute(const BoundConstantExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2315
- Vector &result);
2316
- void Execute(const BoundFunctionExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2317
- Vector &result);
2318
- void Execute(const BoundOperatorExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2319
- Vector &result);
2320
- void Execute(const BoundParameterExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2321
- Vector &result);
2322
- void Execute(const BoundReferenceExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2323
- Vector &result);
2324
-
2325
- //! Execute the (boolean-returning) expression and generate a selection vector with all entries that are "true" in
2326
- //! the result
2327
- idx_t Select(const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2328
- SelectionVector *true_sel, SelectionVector *false_sel);
2329
- idx_t DefaultSelect(const Expression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2330
- SelectionVector *true_sel, SelectionVector *false_sel);
2331
-
2332
- idx_t Select(const BoundBetweenExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2333
- SelectionVector *true_sel, SelectionVector *false_sel);
2334
- idx_t Select(const BoundComparisonExpression &expr, ExpressionState *state, const SelectionVector *sel, idx_t count,
2335
- SelectionVector *true_sel, SelectionVector *false_sel);
2336
- idx_t Select(const BoundConjunctionExpression &expr, ExpressionState *state, const SelectionVector *sel,
2337
- idx_t count, SelectionVector *true_sel, SelectionVector *false_sel);
2338
-
2339
- //! Verify that the output of a step in the ExpressionExecutor is correct
2340
- void Verify(const Expression &expr, Vector &result, idx_t count);
2341
-
2342
- void FillSwitch(Vector &vector, Vector &result, const SelectionVector &sel, sel_t count);
2343
-
2344
- private:
2345
- //! The states of the expression executor; this holds any intermediates and temporary states of expressions
2346
- vector<unique_ptr<ExpressionExecutorState>> states;
2347
- };
2348
- } // namespace duckdb
2349
-
2350
-
2351
- namespace duckdb {
2352
-
2353
- class ClientContext;
2354
- class Transaction;
2355
-
2356
- struct IndexLock;
2357
-
2358
- //! The index is an abstract base class that serves as the basis for indexes
2359
- class Index {
2360
- public:
2361
- Index(IndexType type, const vector<column_t> &column_ids, const vector<unique_ptr<Expression>> &unbound_expressions,
2362
- bool is_unique, bool is_primary);
2363
- virtual ~Index() = default;
2364
-
2365
- //! The type of the index
2366
- IndexType type;
2367
- //! Column identifiers to extract from the base table
2368
- vector<column_t> column_ids;
2369
- //! unordered_set of column_ids used by the index
2370
- unordered_set<column_t> column_id_set;
2371
- //! Unbound expressions used by the index
2372
- vector<unique_ptr<Expression>> unbound_expressions;
2373
- //! The physical types stored in the index
2374
- vector<PhysicalType> types;
2375
- //! The logical types of the expressions
2376
- vector<LogicalType> logical_types;
2377
- //! Whether or not the index is an index built to enforce a UNIQUE or PRIMARY KEY constraint
2378
- bool is_unique;
2379
- //! Whether or not the index is an index built to enforce a PRIMARY KEY constraint
2380
- bool is_primary;
2381
-
2382
- public:
2383
- //! Initialize a scan on the index with the given expression and column ids
2384
- //! to fetch from the base table when we only have one query predicate
2385
- virtual unique_ptr<IndexScanState> InitializeScanSinglePredicate(Transaction &transaction, Value value,
2386
- ExpressionType expressionType) = 0;
2387
- //! Initialize a scan on the index with the given expression and column ids
2388
- //! to fetch from the base table for two query predicates
2389
- virtual unique_ptr<IndexScanState> InitializeScanTwoPredicates(Transaction &transaction, Value low_value,
2390
- ExpressionType low_expression_type, Value high_value,
2391
- ExpressionType high_expression_type) = 0;
2392
- //! Perform a lookup on the index, fetching up to max_count result ids. Returns true if all row ids were fetched,
2393
- //! and false otherwise.
2394
- virtual bool Scan(Transaction &transaction, DataTable &table, IndexScanState &state, idx_t max_count,
2395
- vector<row_t> &result_ids) = 0;
2396
-
2397
- //! Obtain a lock on the index
2398
- virtual void InitializeLock(IndexLock &state);
2399
- //! Called when data is appended to the index. The lock obtained from InitializeAppend must be held
2400
- virtual bool Append(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
2401
- bool Append(DataChunk &entries, Vector &row_identifiers);
2402
- //! Verify that data can be appended to the index
2403
- virtual void VerifyAppend(DataChunk &chunk) = 0;
2404
-
2405
- //! Called when data inside the index is Deleted
2406
- virtual void Delete(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
2407
- void Delete(DataChunk &entries, Vector &row_identifiers);
2408
-
2409
- //! Insert data into the index. Does not lock the index.
2410
- virtual bool Insert(IndexLock &lock, DataChunk &input, Vector &row_identifiers) = 0;
2411
-
2412
- //! Returns true if the index is affected by updates on the specified column ids, and false otherwise
2413
- bool IndexIsUpdated(const vector<column_t> &column_ids) const;
2414
-
2415
- protected:
2416
- void ExecuteExpressions(DataChunk &input, DataChunk &result);
2417
-
2418
- //! Lock used for updating the index
2419
- mutex lock;
2420
-
2421
- private:
2422
- //! Bound expressions used by the index
2423
- vector<unique_ptr<Expression>> bound_expressions;
2424
- //! Expression executor for the index expressions
2425
- ExpressionExecutor executor;
2426
-
2427
- unique_ptr<Expression> BindExpression(unique_ptr<Expression> expr);
2428
- };
2429
-
2430
- } // namespace duckdb
2431
-
2432
- //===----------------------------------------------------------------------===//
2433
- // DuckDB
2434
- //
2435
- // duckdb/storage/table_statistics.hpp
2436
- //
2437
- //
2438
- //===----------------------------------------------------------------------===//
2439
-
2440
-
2441
-
2442
-
2443
-
2444
-
2445
- namespace duckdb {
2446
-
2447
- struct TableStatistics {
2448
- idx_t estimated_cardinality;
2449
- };
2450
-
2451
- } // namespace duckdb
2452
-
2453
-
2454
- //===----------------------------------------------------------------------===//
2455
- // DuckDB
2456
- //
2457
- // duckdb/storage/table/column_segment.hpp
2458
- //
2459
- //
2460
- //===----------------------------------------------------------------------===//
2461
-
2462
-
2463
-
2464
-
2465
-
2466
-
2467
-
2468
- //===----------------------------------------------------------------------===//
2469
- // DuckDB
2470
- //
2471
- // duckdb/storage/buffer_manager.hpp
2472
- //
2473
- //
2474
- //===----------------------------------------------------------------------===//
2475
-
2476
-
2477
-
2478
-
2479
-
2480
-
2481
-
2482
- //===----------------------------------------------------------------------===//
2483
- // DuckDB
2484
- //
2485
- // duckdb/storage/block_manager.hpp
2486
- //
2487
- //
2488
- //===----------------------------------------------------------------------===//
2489
-
2490
-
2491
-
2492
-
2493
-
2494
-
2495
-
2496
- namespace duckdb {
2497
- class ClientContext;
2498
- class DatabaseInstance;
2499
-
2500
- //! BlockManager is an abstract representation to manage blocks on DuckDB. When writing or reading blocks, the
2501
- //! BlockManager creates and accesses blocks. The concrete types implements how blocks are stored.
2502
- class BlockManager {
2503
- public:
2504
- virtual ~BlockManager() = default;
2505
-
2506
- virtual void StartCheckpoint() = 0;
2507
- //! Creates a new block inside the block manager
2508
- virtual unique_ptr<Block> CreateBlock(block_id_t block_id) = 0;
2509
- //! Return the next free block id
2510
- virtual block_id_t GetFreeBlockId() = 0;
2511
- //! Returns whether or not a specified block is the root block
2512
- virtual bool IsRootBlock(block_id_t root) = 0;
2513
- //! Mark a block as "modified"; modified blocks are added to the free list after a checkpoint (i.e. their data is
2514
- //! assumed to be rewritten)
2515
- virtual void MarkBlockAsModified(block_id_t block_id) = 0;
2516
- //! Increase the reference count of a block. The block should hold at least one reference before this method is
2517
- //! called.
2518
- virtual void IncreaseBlockReferenceCount(block_id_t block_id) = 0;
2519
- //! Get the first meta block id
2520
- virtual block_id_t GetMetaBlock() = 0;
2521
- //! Read the content of the block from disk
2522
- virtual void Read(Block &block) = 0;
2523
- //! Writes the block to disk
2524
- virtual void Write(FileBuffer &block, block_id_t block_id) = 0;
2525
- //! Writes the block to disk
2526
- void Write(Block &block) {
2527
- Write(block, block.id);
2528
- }
2529
- //! Write the header; should be the final step of a checkpoint
2530
- virtual void WriteHeader(DatabaseHeader header) = 0;
2531
-
2532
- //! Returns the number of total blocks
2533
- virtual idx_t TotalBlocks() = 0;
2534
- //! Returns the number of free blocks
2535
- virtual idx_t FreeBlocks() = 0;
2536
-
2537
- static BlockManager &GetBlockManager(ClientContext &context);
2538
- static BlockManager &GetBlockManager(DatabaseInstance &db);
2539
- };
2540
- } // namespace duckdb
2541
-
2542
- //===----------------------------------------------------------------------===//
2543
- // DuckDB
2544
- //
2545
- // duckdb/storage/buffer/block_handle.hpp
2546
- //
2547
- //
2548
- //===----------------------------------------------------------------------===//
2549
-
2550
-
2551
-
2552
-
2553
-
2554
-
2555
-
2556
-
2557
- namespace duckdb {
2558
- class BufferHandle;
2559
- class BufferManager;
2560
- class DatabaseInstance;
2561
- class FileBuffer;
2562
-
2563
- enum class BlockState : uint8_t { BLOCK_UNLOADED = 0, BLOCK_LOADED = 1 };
2564
-
2565
- class BlockHandle {
2566
- friend struct BufferEvictionNode;
2567
- friend class BufferHandle;
2568
- friend class BufferManager;
2569
-
2570
- public:
2571
- BlockHandle(DatabaseInstance &db, block_id_t block_id);
2572
- BlockHandle(DatabaseInstance &db, block_id_t block_id, unique_ptr<FileBuffer> buffer, bool can_destroy,
2573
- idx_t block_size);
2574
- ~BlockHandle();
2575
-
2576
- DatabaseInstance &db;
2577
-
2578
- public:
2579
- block_id_t BlockId() {
2580
- return block_id;
2581
- }
2582
-
2583
- int32_t Readers() const {
2584
- return readers;
2585
- }
2586
-
2587
- private:
2588
- static unique_ptr<BufferHandle> Load(shared_ptr<BlockHandle> &handle);
2589
- void Unload();
2590
- bool CanUnload();
2591
-
2592
- //! The block-level lock
2593
- mutex lock;
2594
- //! Whether or not the block is loaded/unloaded
2595
- BlockState state;
2596
- //! Amount of concurrent readers
2597
- atomic<int32_t> readers;
2598
- //! The block id of the block
2599
- const block_id_t block_id;
2600
- //! Pointer to loaded data (if any)
2601
- unique_ptr<FileBuffer> buffer;
2602
- //! Internal eviction timestamp
2603
- atomic<idx_t> eviction_timestamp;
2604
- //! Whether or not the buffer can be destroyed (only used for temporary buffers)
2605
- const bool can_destroy;
2606
- //! The memory usage of the block
2607
- idx_t memory_usage;
2608
- };
2609
-
2610
- } // namespace duckdb
2611
-
2612
-
2613
- //===----------------------------------------------------------------------===//
2614
- // DuckDB
2615
- //
2616
- // duckdb/storage/buffer/managed_buffer.hpp
2617
- //
2618
- //
2619
- //===----------------------------------------------------------------------===//
2620
-
2621
-
2622
-
2623
-
2624
-
2625
-
2626
-
2627
- namespace duckdb {
2628
- class DatabaseInstance;
2629
-
2630
- //! Managed buffer is an arbitrarily-sized buffer that is at least of size >= BLOCK_SIZE
2631
- class ManagedBuffer : public FileBuffer {
2632
- public:
2633
- ManagedBuffer(DatabaseInstance &db, idx_t size, bool can_destroy, block_id_t id);
2634
-
2635
- DatabaseInstance &db;
2636
- //! Whether or not the managed buffer can be freely destroyed when unpinned.
2637
- //! - If can_destroy is true, the buffer can be destroyed when unpinned and hence be unrecoverable. After being
2638
- //! destroyed, Pin() will return false.
2639
- //! - If can_destroy is false, the buffer will instead be written to a temporary file on disk when unloaded from
2640
- //! memory, and read back into memory when Pin() is called.
2641
- bool can_destroy;
2642
- //! The internal id of the buffer
2643
- block_id_t id;
2644
- };
2645
-
2646
- } // namespace duckdb
2647
-
2648
-
2649
- namespace duckdb {
2650
- class DatabaseInstance;
2651
- class TemporaryDirectoryHandle;
2652
- struct EvictionQueue;
2653
-
2654
- //! The buffer manager is in charge of handling memory management for the database. It hands out memory buffers that can
2655
- //! be used by the database internally.
2656
- class BufferManager {
2657
- friend class BufferHandle;
2658
- friend class BlockHandle;
2659
-
2660
- public:
2661
- BufferManager(DatabaseInstance &db, string temp_directory, idx_t maximum_memory);
2662
- ~BufferManager();
2663
-
2664
- //! Register a block with the given block id in the base file
2665
- shared_ptr<BlockHandle> RegisterBlock(block_id_t block_id);
2666
-
2667
- //! Register an in-memory buffer of arbitrary size, as long as it is >= BLOCK_SIZE. can_destroy signifies whether or
2668
- //! not the buffer can be destroyed when unpinned, or whether or not it needs to be written to a temporary file so
2669
- //! it can be reloaded. The resulting buffer will already be allocated, but needs to be pinned in order to be used.
2670
- shared_ptr<BlockHandle> RegisterMemory(idx_t block_size, bool can_destroy);
2671
-
2672
- //! Convert an existing in-memory buffer into a persistent disk-backed block
2673
- shared_ptr<BlockHandle> ConvertToPersistent(BlockManager &block_manager, block_id_t block_id,
2674
- shared_ptr<BlockHandle> old_block);
2675
-
2676
- //! Allocate an in-memory buffer with a single pin.
2677
- //! The allocated memory is released when the buffer handle is destroyed.
2678
- unique_ptr<BufferHandle> Allocate(idx_t block_size);
2679
-
2680
- //! Reallocate an in-memory buffer that is pinned.
2681
- void ReAllocate(shared_ptr<BlockHandle> &handle, idx_t block_size);
2682
-
2683
- unique_ptr<BufferHandle> Pin(shared_ptr<BlockHandle> &handle);
2684
- void Unpin(shared_ptr<BlockHandle> &handle);
2685
-
2686
- void UnregisterBlock(block_id_t block_id, bool can_destroy);
2687
-
2688
- //! Set a new memory limit to the buffer manager, throws an exception if the new limit is too low and not enough
2689
- //! blocks can be evicted
2690
- void SetLimit(idx_t limit = (idx_t)-1);
2691
-
2692
- static BufferManager &GetBufferManager(ClientContext &context);
2693
- static BufferManager &GetBufferManager(DatabaseInstance &db);
2694
-
2695
- idx_t GetUsedMemory() {
2696
- return current_memory;
2697
- }
2698
- idx_t GetMaxMemory() {
2699
- return maximum_memory;
2700
- }
2701
-
2702
- const string &GetTemporaryDirectory() {
2703
- return temp_directory;
2704
- }
2705
-
2706
- void SetTemporaryDirectory(string new_dir);
2707
-
2708
- private:
2709
- //! Evict blocks until the currently used memory + extra_memory fit, returns false if this was not possible
2710
- //! (i.e. not enough blocks could be evicted)
2711
- bool EvictBlocks(idx_t extra_memory, idx_t memory_limit);
2712
-
2713
- //! Garbage collect eviction queue
2714
- void PurgeQueue();
2715
-
2716
- //! Write a temporary buffer to disk
2717
- void WriteTemporaryBuffer(ManagedBuffer &buffer);
2718
- //! Read a temporary buffer from disk
2719
- unique_ptr<FileBuffer> ReadTemporaryBuffer(block_id_t id);
2720
- //! Get the path of the temporary buffer
2721
- string GetTemporaryPath(block_id_t id);
2722
-
2723
- void DeleteTemporaryFile(block_id_t id);
2724
-
2725
- void RequireTemporaryDirectory();
2726
-
2727
- void AddToEvictionQueue(shared_ptr<BlockHandle> &handle);
2728
-
2729
- string InMemoryWarning();
2730
-
2731
- private:
2732
- //! The database instance
2733
- DatabaseInstance &db;
2734
- //! The lock for changing the memory limit
2735
- mutex limit_lock;
2736
- //! The current amount of memory that is occupied by the buffer manager (in bytes)
2737
- atomic<idx_t> current_memory;
2738
- //! The maximum amount of memory that the buffer manager can keep (in bytes)
2739
- atomic<idx_t> maximum_memory;
2740
- //! The directory name where temporary files are stored
2741
- string temp_directory;
2742
- //! Lock for creating the temp handle
2743
- mutex temp_handle_lock;
2744
- //! Handle for the temporary directory
2745
- unique_ptr<TemporaryDirectoryHandle> temp_directory_handle;
2746
- //! The lock for the set of blocks
2747
- mutex blocks_lock;
2748
- //! A mapping of block id -> BlockHandle
2749
- unordered_map<block_id_t, weak_ptr<BlockHandle>> blocks;
2750
- //! Eviction queue
2751
- unique_ptr<EvictionQueue> queue;
2752
- //! The temporary id used for managed buffers
2753
- atomic<block_id_t> temporary_id;
2754
- };
2755
- } // namespace duckdb
2756
-
2757
-
2758
-
2759
-
2760
- //===----------------------------------------------------------------------===//
2761
- // DuckDB
2762
- //
2763
- // duckdb/function/compression_function.hpp
2764
- //
2765
- //
2766
- //===----------------------------------------------------------------------===//
2767
-
2768
-
2769
-
2770
-
2771
-
2772
-
2773
- //===----------------------------------------------------------------------===//
2774
- // DuckDB
2775
- //
2776
- // duckdb/common/map.hpp
2777
- //
2778
- //
2779
- //===----------------------------------------------------------------------===//
2780
-
2781
-
2782
-
2783
- #include <map>
2784
-
2785
- namespace duckdb {
2786
- using std::map;
2787
- using std::multimap;
2788
- } // namespace duckdb
2789
-
2790
-
2791
-
2792
- namespace duckdb {
2793
- class DatabaseInstance;
2794
- class ColumnData;
2795
- class ColumnDataCheckpointer;
2796
- class ColumnSegment;
2797
- class SegmentStatistics;
2798
-
2799
- struct ColumnFetchState;
2800
- struct ColumnScanState;
2801
- struct SegmentScanState;
2802
-
2803
- struct AnalyzeState {
2804
- virtual ~AnalyzeState() {
2805
- }
2806
- };
2807
-
2808
- struct CompressionState {
2809
- virtual ~CompressionState() {
2810
- }
2811
- };
2812
-
2813
- struct CompressedSegmentState {
2814
- virtual ~CompressedSegmentState() {
2815
- }
2816
- };
2817
-
2818
- //===--------------------------------------------------------------------===//
2819
- // Analyze
2820
- //===--------------------------------------------------------------------===//
2821
- //! The analyze functions are used to determine whether or not to use this compression method
2822
- //! The system first determines the potential compression methods to use based on the physical type of the column
2823
- //! After that the following steps are taken:
2824
- //! 1. The init_analyze is called to initialize the analyze state of every candidate compression method
2825
- //! 2. The analyze method is called with all of the input data in the order in which it must be stored.
2826
- //! analyze can return "false". In that case, the compression method is taken out of consideration early.
2827
- //! 3. The final_analyze method is called, which should return a score for the compression method
2828
-
2829
- //! The system then decides which compression function to use based on the analyzed score (returned from final_analyze)
2830
- typedef unique_ptr<AnalyzeState> (*compression_init_analyze_t)(ColumnData &col_data, PhysicalType type);
2831
- typedef bool (*compression_analyze_t)(AnalyzeState &state, Vector &input, idx_t count);
2832
- typedef idx_t (*compression_final_analyze_t)(AnalyzeState &state);
2833
-
2834
- //===--------------------------------------------------------------------===//
2835
- // Compress
2836
- //===--------------------------------------------------------------------===//
2837
- typedef unique_ptr<CompressionState> (*compression_init_compression_t)(ColumnDataCheckpointer &checkpointer,
2838
- unique_ptr<AnalyzeState> state);
2839
- typedef void (*compression_compress_data_t)(CompressionState &state, Vector &scan_vector, idx_t count);
2840
- typedef void (*compression_compress_finalize_t)(CompressionState &state);
2841
-
2842
- //===--------------------------------------------------------------------===//
2843
- // Uncompress / Scan
2844
- //===--------------------------------------------------------------------===//
2845
- typedef unique_ptr<SegmentScanState> (*compression_init_segment_scan_t)(ColumnSegment &segment);
2846
- typedef void (*compression_scan_vector_t)(ColumnSegment &segment, ColumnScanState &state, idx_t scan_count,
2847
- Vector &result);
2848
- typedef void (*compression_scan_partial_t)(ColumnSegment &segment, ColumnScanState &state, idx_t scan_count,
2849
- Vector &result, idx_t result_offset);
2850
- typedef void (*compression_fetch_row_t)(ColumnSegment &segment, ColumnFetchState &state, row_t row_id, Vector &result,
2851
- idx_t result_idx);
2852
- typedef void (*compression_skip_t)(ColumnSegment &segment, ColumnScanState &state, idx_t skip_count);
2853
-
2854
- //===--------------------------------------------------------------------===//
2855
- // Append (optional)
2856
- //===--------------------------------------------------------------------===//
2857
- typedef unique_ptr<CompressedSegmentState> (*compression_init_segment_t)(ColumnSegment &segment, block_id_t block_id);
2858
- typedef idx_t (*compression_append_t)(ColumnSegment &segment, SegmentStatistics &stats, VectorData &data, idx_t offset,
2859
- idx_t count);
2860
- typedef idx_t (*compression_finalize_append_t)(ColumnSegment &segment, SegmentStatistics &stats);
2861
- typedef void (*compression_revert_append_t)(ColumnSegment &segment, idx_t start_row);
2862
-
2863
- class CompressionFunction {
2864
- public:
2865
- CompressionFunction(CompressionType type, PhysicalType data_type, compression_init_analyze_t init_analyze,
2866
- compression_analyze_t analyze, compression_final_analyze_t final_analyze,
2867
- compression_init_compression_t init_compression, compression_compress_data_t compress,
2868
- compression_compress_finalize_t compress_finalize, compression_init_segment_scan_t init_scan,
2869
- compression_scan_vector_t scan_vector, compression_scan_partial_t scan_partial,
2870
- compression_fetch_row_t fetch_row, compression_skip_t skip,
2871
- compression_init_segment_t init_segment = nullptr, compression_append_t append = nullptr,
2872
- compression_finalize_append_t finalize_append = nullptr,
2873
- compression_revert_append_t revert_append = nullptr)
2874
- : type(type), data_type(data_type), init_analyze(init_analyze), analyze(analyze), final_analyze(final_analyze),
2875
- init_compression(init_compression), compress(compress), compress_finalize(compress_finalize),
2876
- init_scan(init_scan), scan_vector(scan_vector), scan_partial(scan_partial), fetch_row(fetch_row), skip(skip),
2877
- init_segment(init_segment), append(append), finalize_append(finalize_append), revert_append(revert_append) {
2878
- }
2879
-
2880
- //! Compression type
2881
- CompressionType type;
2882
- //! The data type this function can compress
2883
- PhysicalType data_type;
2884
-
2885
- //! Analyze step: determine which compression function is the most effective
2886
- //! init_analyze is called once to set up the analyze state
2887
- compression_init_analyze_t init_analyze;
2888
- //! analyze is called several times (once per vector in the row group)
2889
- //! analyze should return true, unless compression is no longer possible with this compression method
2890
- //! in that case false should be returned
2891
- compression_analyze_t analyze;
2892
- //! final_analyze should return the score of the compression function
2893
- //! ideally this is the exact number of bytes required to store the data
2894
- //! this is not required/enforced: it can be an estimate as well
2895
- compression_final_analyze_t final_analyze;
2896
-
2897
- //! Compression step: actually compress the data
2898
- //! init_compression is called once to set up the comperssion state
2899
- compression_init_compression_t init_compression;
2900
- //! compress is called several times (once per vector in the row group)
2901
- compression_compress_data_t compress;
2902
- //! compress_finalize is called after
2903
- compression_compress_finalize_t compress_finalize;
2904
-
2905
- //! init_scan is called to set up the scan state
2906
- compression_init_segment_scan_t init_scan;
2907
- //! scan_vector scans an entire vector using the scan state
2908
- compression_scan_vector_t scan_vector;
2909
- //! scan_partial scans a subset of a vector
2910
- //! this can request > vector_size as well
2911
- //! this is used if a vector crosses segment boundaries, or for child columns of lists
2912
- compression_scan_partial_t scan_partial;
2913
- //! fetch an individual row from the compressed vector
2914
- //! used for index lookups
2915
- compression_fetch_row_t fetch_row;
2916
- //! Skip forward in the compressed segment
2917
- compression_skip_t skip;
2918
-
2919
- // Append functions
2920
- //! This only really needs to be defined for uncompressed segments
2921
-
2922
- //! Initialize a compressed segment (optional)
2923
- compression_init_segment_t init_segment;
2924
- //! Append to the compressed segment (optional)
2925
- compression_append_t append;
2926
- //! Finalize an append to the segment
2927
- compression_finalize_append_t finalize_append;
2928
- //! Revert append (optional)
2929
- compression_revert_append_t revert_append;
2930
- };
2931
-
2932
- //! The set of compression functions
2933
- struct CompressionFunctionSet {
2934
- map<CompressionType, map<PhysicalType, CompressionFunction>> functions;
2935
- };
2936
-
2937
- } // namespace duckdb
2938
-
2939
-
2940
- namespace duckdb {
2941
- class ColumnSegment;
2942
- class BlockManager;
2943
- class ColumnSegment;
2944
- class ColumnData;
2945
- class DatabaseInstance;
2946
- class Transaction;
2947
- class BaseStatistics;
2948
- class UpdateSegment;
2949
- class TableFilter;
2950
- struct ColumnFetchState;
2951
- struct ColumnScanState;
2952
- struct ColumnAppendState;
2953
-
2954
- enum class ColumnSegmentType : uint8_t { TRANSIENT, PERSISTENT };
2955
- //! TableFilter represents a filter pushed down into the table scan.
2956
-
2957
- class ColumnSegment : public SegmentBase {
2958
- public:
2959
- ~ColumnSegment() override;
2960
-
2961
- //! The database instance
2962
- DatabaseInstance &db;
2963
- //! The type stored in the column
2964
- LogicalType type;
2965
- //! The size of the type
2966
- idx_t type_size;
2967
- //! The column segment type (transient or persistent)
2968
- ColumnSegmentType segment_type;
2969
- //! The compression function
2970
- CompressionFunction *function;
2971
- //! The statistics for the segment
2972
- SegmentStatistics stats;
2973
- //! The block that this segment relates to
2974
- shared_ptr<BlockHandle> block;
2975
-
2976
- static unique_ptr<ColumnSegment> CreatePersistentSegment(DatabaseInstance &db, block_id_t id, idx_t offset,
2977
- const LogicalType &type_p, idx_t start, idx_t count,
2978
- CompressionType compression_type,
2979
- unique_ptr<BaseStatistics> statistics);
2980
- static unique_ptr<ColumnSegment> CreateTransientSegment(DatabaseInstance &db, const LogicalType &type, idx_t start);
2981
-
2982
- public:
2983
- void InitializeScan(ColumnScanState &state);
2984
- //! Scan one vector from this segment
2985
- void Scan(ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset, bool entire_vector);
2986
- //! Fetch a value of the specific row id and append it to the result
2987
- void FetchRow(ColumnFetchState &state, row_t row_id, Vector &result, idx_t result_idx);
2988
-
2989
- static void FilterSelection(SelectionVector &sel, Vector &result, const TableFilter &filter,
2990
- idx_t &approved_tuple_count, ValidityMask &mask);
2991
-
2992
- //! Skip a scan forward to the row_index specified in the scan state
2993
- void Skip(ColumnScanState &state);
2994
-
2995
- //! Initialize an append of this segment. Appends are only supported on transient segments.
2996
- void InitializeAppend(ColumnAppendState &state);
2997
- //! Appends a (part of) vector to the segment, returns the amount of entries successfully appended
2998
- idx_t Append(ColumnAppendState &state, VectorData &data, idx_t offset, idx_t count);
2999
- //! Finalize the segment for appending - no more appends can follow on this segment
3000
- //! The segment should be compacted as much as possible
3001
- //! Returns the number of bytes occupied within the segment
3002
- idx_t FinalizeAppend();
3003
- //! Revert an append made to this segment
3004
- void RevertAppend(idx_t start_row);
3005
-
3006
- //! Convert a transient in-memory segment into a persistent segment blocked by an on-disk block.
3007
- //! Only used during checkpointing.
3008
- void ConvertToPersistent(block_id_t block_id);
3009
- //! Convert a transient in-memory segment into a persistent segment blocked by an on-disk block.
3010
- void ConvertToPersistent(shared_ptr<BlockHandle> block, block_id_t block_id, uint32_t offset_in_block);
3011
-
3012
- block_id_t GetBlockId() {
3013
- D_ASSERT(segment_type == ColumnSegmentType::PERSISTENT);
3014
- return block_id;
3015
- }
3016
-
3017
- idx_t GetBlockOffset() {
3018
- D_ASSERT(segment_type == ColumnSegmentType::PERSISTENT || offset == 0);
3019
- return offset;
3020
- }
3021
-
3022
- idx_t GetRelativeIndex(idx_t row_index) {
3023
- D_ASSERT(row_index >= this->start);
3024
- D_ASSERT(row_index <= this->start + this->count);
3025
- return row_index - this->start;
3026
- }
3027
-
3028
- CompressedSegmentState *GetSegmentState() {
3029
- return segment_state.get();
3030
- }
3031
-
3032
- public:
3033
- ColumnSegment(DatabaseInstance &db, LogicalType type, ColumnSegmentType segment_type, idx_t start, idx_t count,
3034
- CompressionFunction *function, unique_ptr<BaseStatistics> statistics, block_id_t block_id,
3035
- idx_t offset);
3036
-
3037
- private:
3038
- void Scan(ColumnScanState &state, idx_t scan_count, Vector &result);
3039
- void ScanPartial(ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset);
3040
-
3041
- private:
3042
- //! The block id that this segment relates to (persistent segment only)
3043
- block_id_t block_id;
3044
- //! The offset into the block (persistent segment only)
3045
- idx_t offset;
3046
- //! Storage associated with the compressed segment
3047
- unique_ptr<CompressedSegmentState> segment_state;
3048
- };
3049
-
3050
- } // namespace duckdb
3051
-
3052
-
3053
-
3054
-
3055
-
3056
-
3057
-
3058
-
3059
-
3060
- namespace duckdb {
3061
- class ClientContext;
3062
- class ColumnDefinition;
3063
- class DataTable;
3064
- class RowGroup;
3065
- class StorageManager;
3066
- class TableCatalogEntry;
3067
- class Transaction;
3068
- class WriteAheadLog;
3069
- class TableDataWriter;
3070
-
3071
- class TableIndexList {
3072
- public:
3073
- //! Scan the catalog set, invoking the callback method for every entry
3074
- template <class T>
3075
- void Scan(T &&callback) {
3076
- // lock the catalog set
3077
- lock_guard<mutex> lock(indexes_lock);
3078
- for (auto &index : indexes) {
3079
- if (callback(*index)) {
3080
- break;
3081
- }
3082
- }
3083
- }
3084
-
3085
- void AddIndex(unique_ptr<Index> index) {
3086
- D_ASSERT(index);
3087
- lock_guard<mutex> lock(indexes_lock);
3088
- indexes.push_back(move(index));
3089
- }
3090
-
3091
- void RemoveIndex(Index *index) {
3092
- D_ASSERT(index);
3093
- lock_guard<mutex> lock(indexes_lock);
3094
-
3095
- for (idx_t index_idx = 0; index_idx < indexes.size(); index_idx++) {
3096
- auto &index_entry = indexes[index_idx];
3097
- if (index_entry.get() == index) {
3098
- indexes.erase(indexes.begin() + index_idx);
3099
- break;
3100
- }
3101
- }
3102
- }
3103
-
3104
- bool Empty() {
3105
- lock_guard<mutex> lock(indexes_lock);
3106
- return indexes.empty();
3107
- }
3108
-
3109
- idx_t Count() {
3110
- lock_guard<mutex> lock(indexes_lock);
3111
- return indexes.size();
3112
- }
3113
-
3114
- private:
3115
- //! Indexes associated with the current table
3116
- mutex indexes_lock;
3117
- vector<unique_ptr<Index>> indexes;
3118
- };
3119
-
3120
- struct DataTableInfo {
3121
- DataTableInfo(DatabaseInstance &db, string schema, string table)
3122
- : db(db), cardinality(0), schema(move(schema)), table(move(table)) {
3123
- }
3124
-
3125
- //! The database instance of the table
3126
- DatabaseInstance &db;
3127
- //! The amount of elements in the table. Note that this number signifies the amount of COMMITTED entries in the
3128
- //! table. It can be inaccurate inside of transactions. More work is needed to properly support that.
3129
- atomic<idx_t> cardinality;
3130
- // schema of the table
3131
- string schema;
3132
- // name of the table
3133
- string table;
3134
-
3135
- TableIndexList indexes;
3136
-
3137
- bool IsTemporary() {
3138
- return schema == TEMP_SCHEMA;
3139
- }
3140
- };
3141
-
3142
- struct ParallelTableScanState {
3143
- RowGroup *current_row_group;
3144
- idx_t vector_index;
3145
- idx_t max_row;
3146
- LocalScanState local_state;
3147
- bool transaction_local_data;
3148
- };
3149
-
3150
- //! DataTable represents a physical table on disk
3151
- class DataTable {
3152
- public:
3153
- //! Constructs a new data table from an (optional) set of persistent segments
3154
- DataTable(DatabaseInstance &db, const string &schema, const string &table,
3155
- vector<ColumnDefinition> column_definitions_p, unique_ptr<PersistentTableData> data = nullptr);
3156
- //! Constructs a DataTable as a delta on an existing data table with a newly added column
3157
- DataTable(ClientContext &context, DataTable &parent, ColumnDefinition &new_column, Expression *default_value);
3158
- //! Constructs a DataTable as a delta on an existing data table but with one column removed
3159
- DataTable(ClientContext &context, DataTable &parent, idx_t removed_column);
3160
- //! Constructs a DataTable as a delta on an existing data table but with one column changed type
3161
- DataTable(ClientContext &context, DataTable &parent, idx_t changed_idx, const LogicalType &target_type,
3162
- vector<column_t> bound_columns, Expression &cast_expr);
3163
-
3164
- shared_ptr<DataTableInfo> info;
3165
-
3166
- vector<ColumnDefinition> column_definitions;
3167
-
3168
- //! A reference to the database instance
3169
- DatabaseInstance &db;
3170
-
3171
- public:
3172
- //! Returns a list of types of the table
3173
- vector<LogicalType> GetTypes();
3174
-
3175
- void InitializeScan(TableScanState &state, const vector<column_t> &column_ids,
3176
- TableFilterSet *table_filter = nullptr);
3177
- void InitializeScan(Transaction &transaction, TableScanState &state, const vector<column_t> &column_ids,
3178
- TableFilterSet *table_filters = nullptr);
3179
-
3180
- //! Returns the maximum amount of threads that should be assigned to scan this data table
3181
- idx_t MaxThreads(ClientContext &context);
3182
- void InitializeParallelScan(ClientContext &context, ParallelTableScanState &state);
3183
- bool NextParallelScan(ClientContext &context, ParallelTableScanState &state, TableScanState &scan_state,
3184
- const vector<column_t> &column_ids);
3185
-
3186
- //! Scans up to STANDARD_VECTOR_SIZE elements from the table starting
3187
- //! from offset and store them in result. Offset is incremented with how many
3188
- //! elements were returned.
3189
- //! Returns true if all pushed down filters were executed during data fetching
3190
- void Scan(Transaction &transaction, DataChunk &result, TableScanState &state, vector<column_t> &column_ids);
3191
-
3192
- //! Fetch data from the specific row identifiers from the base table
3193
- void Fetch(Transaction &transaction, DataChunk &result, const vector<column_t> &column_ids, Vector &row_ids,
3194
- idx_t fetch_count, ColumnFetchState &state);
3195
-
3196
- //! Append a DataChunk to the table. Throws an exception if the columns don't match the tables' columns.
3197
- void Append(TableCatalogEntry &table, ClientContext &context, DataChunk &chunk);
3198
- //! Delete the entries with the specified row identifier from the table
3199
- idx_t Delete(TableCatalogEntry &table, ClientContext &context, Vector &row_ids, idx_t count);
3200
- //! Update the entries with the specified row identifier from the table
3201
- void Update(TableCatalogEntry &table, ClientContext &context, Vector &row_ids, const vector<column_t> &column_ids,
3202
- DataChunk &data);
3203
- //! Update a single (sub-)column along a column path
3204
- //! The column_path vector is a *path* towards a column within the table
3205
- //! i.e. if we have a table with a single column S STRUCT(A INT, B INT)
3206
- //! and we update the validity mask of "S.B"
3207
- //! the column path is:
3208
- //! 0 (first column of table)
3209
- //! -> 1 (second subcolumn of struct)
3210
- //! -> 0 (first subcolumn of INT)
3211
- //! This method should only be used from the WAL replay. It does not verify update constraints.
3212
- void UpdateColumn(TableCatalogEntry &table, ClientContext &context, Vector &row_ids,
3213
- const vector<column_t> &column_path, DataChunk &updates);
3214
-
3215
- //! Add an index to the DataTable
3216
- void AddIndex(unique_ptr<Index> index, const vector<unique_ptr<Expression>> &expressions);
3217
-
3218
- //! Begin appending structs to this table, obtaining necessary locks, etc
3219
- void InitializeAppend(Transaction &transaction, TableAppendState &state, idx_t append_count);
3220
- //! Append a chunk to the table using the AppendState obtained from BeginAppend
3221
- void Append(Transaction &transaction, DataChunk &chunk, TableAppendState &state);
3222
- //! Commit the append
3223
- void CommitAppend(transaction_t commit_id, idx_t row_start, idx_t count);
3224
- //! Write a segment of the table to the WAL
3225
- void WriteToLog(WriteAheadLog &log, idx_t row_start, idx_t count);
3226
- //! Revert a set of appends made by the given AppendState, used to revert appends in the event of an error during
3227
- //! commit (e.g. because of an I/O exception)
3228
- void RevertAppend(idx_t start_row, idx_t count);
3229
- void RevertAppendInternal(idx_t start_row, idx_t count);
3230
-
3231
- void ScanTableSegment(idx_t start_row, idx_t count, const std::function<void(DataChunk &chunk)> &function);
3232
-
3233
- //! Append a chunk with the row ids [row_start, ..., row_start + chunk.size()] to all indexes of the table, returns
3234
- //! whether or not the append succeeded
3235
- bool AppendToIndexes(TableAppendState &state, DataChunk &chunk, row_t row_start);
3236
- //! Remove a chunk with the row ids [row_start, ..., row_start + chunk.size()] from all indexes of the table
3237
- void RemoveFromIndexes(TableAppendState &state, DataChunk &chunk, row_t row_start);
3238
- //! Remove the chunk with the specified set of row identifiers from all indexes of the table
3239
- void RemoveFromIndexes(TableAppendState &state, DataChunk &chunk, Vector &row_identifiers);
3240
- //! Remove the row identifiers from all the indexes of the table
3241
- void RemoveFromIndexes(Vector &row_identifiers, idx_t count);
3242
-
3243
- void SetAsRoot() {
3244
- this->is_root = true;
3245
- }
3246
-
3247
- unique_ptr<BaseStatistics> GetStatistics(ClientContext &context, column_t column_id);
3248
-
3249
- //! Checkpoint the table to the specified table data writer
3250
- BlockPointer Checkpoint(TableDataWriter &writer);
3251
- void CommitDropTable();
3252
- void CommitDropColumn(idx_t index);
3253
-
3254
- idx_t GetTotalRows();
3255
-
3256
- //! Appends an empty row_group to the table
3257
- void AppendRowGroup(idx_t start_row);
3258
-
3259
- vector<vector<Value>> GetStorageInfo();
3260
-
3261
- private:
3262
- //! Verify constraints with a chunk from the Append containing all columns of the table
3263
- void VerifyAppendConstraints(TableCatalogEntry &table, DataChunk &chunk);
3264
- //! Verify constraints with a chunk from the Update containing only the specified column_ids
3265
- void VerifyUpdateConstraints(TableCatalogEntry &table, DataChunk &chunk, const vector<column_t> &column_ids);
3266
-
3267
- void InitializeScanWithOffset(TableScanState &state, const vector<column_t> &column_ids, idx_t start_row,
3268
- idx_t end_row);
3269
- bool InitializeScanInRowGroup(TableScanState &state, const vector<column_t> &column_ids,
3270
- TableFilterSet *table_filters, RowGroup *row_group, idx_t vector_index,
3271
- idx_t max_row);
3272
- bool ScanBaseTable(Transaction &transaction, DataChunk &result, TableScanState &state);
3273
-
3274
- //! The CreateIndexScan is a special scan that is used to create an index on the table, it keeps locks on the table
3275
- void InitializeCreateIndexScan(CreateIndexScanState &state, const vector<column_t> &column_ids);
3276
- bool ScanCreateIndex(CreateIndexScanState &state, DataChunk &result, TableScanType type);
3277
-
3278
- private:
3279
- //! Lock for appending entries to the table
3280
- mutex append_lock;
3281
- //! The number of rows in the table
3282
- atomic<idx_t> total_rows;
3283
- //! The segment trees holding the various row_groups of the table
3284
- shared_ptr<SegmentTree> row_groups;
3285
- //! Column statistics
3286
- vector<unique_ptr<BaseStatistics>> column_stats;
3287
- //! The statistics lock
3288
- mutex stats_lock;
3289
- //! Whether or not the data table is the root DataTable for this table; the root DataTable is the newest version
3290
- //! that can be appended to
3291
- atomic<bool> is_root;
3292
- };
3293
- } // namespace duckdb
3294
830
 
3295
831
 
3296
832
  namespace duckdb {
@@ -3849,40 +1385,6 @@ public:
3849
1385
 
3850
1386
  } // namespace duckdb
3851
1387
 
3852
- //===----------------------------------------------------------------------===//
3853
- // DuckDB
3854
- //
3855
- // duckdb/parser/constraints/not_null_constraint.hpp
3856
- //
3857
- //
3858
- //===----------------------------------------------------------------------===//
3859
-
3860
-
3861
-
3862
-
3863
-
3864
- namespace duckdb {
3865
-
3866
- class NotNullConstraint : public Constraint {
3867
- public:
3868
- DUCKDB_API explicit NotNullConstraint(column_t index);
3869
- DUCKDB_API ~NotNullConstraint() override;
3870
-
3871
- //! Column index this constraint pertains to
3872
- column_t index;
3873
-
3874
- public:
3875
- DUCKDB_API string ToString() const override;
3876
-
3877
- DUCKDB_API unique_ptr<Constraint> Copy() override;
3878
-
3879
- //! Serialize to a stand-alone binary blob
3880
- DUCKDB_API void Serialize(Serializer &serializer) override;
3881
- //! Deserializes a NotNullConstraint
3882
- DUCKDB_API static unique_ptr<Constraint> Deserialize(Deserializer &source);
3883
- };
3884
-
3885
- } // namespace duckdb
3886
1388
 
3887
1389
  //===----------------------------------------------------------------------===//
3888
1390
  // DuckDB
@@ -5801,42 +3303,6 @@ private:
5801
3303
 
5802
3304
 
5803
3305
 
5804
- //===----------------------------------------------------------------------===//
5805
- // DuckDB
5806
- //
5807
- // duckdb/parser/expression/constant_expression.hpp
5808
- //
5809
- //
5810
- //===----------------------------------------------------------------------===//
5811
-
5812
-
5813
-
5814
-
5815
-
5816
-
5817
- namespace duckdb {
5818
-
5819
- //! ConstantExpression represents a constant value in the query
5820
- class ConstantExpression : public ParsedExpression {
5821
- public:
5822
- explicit ConstantExpression(Value val);
5823
-
5824
- //! The constant value referenced
5825
- Value value;
5826
-
5827
- public:
5828
- string ToString() const override;
5829
-
5830
- static bool Equals(const ConstantExpression *a, const ConstantExpression *b);
5831
- hash_t Hash() const override;
5832
-
5833
- unique_ptr<ParsedExpression> Copy() const override;
5834
-
5835
- void Serialize(Serializer &serializer) override;
5836
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
5837
- };
5838
-
5839
- } // namespace duckdb
5840
3306
 
5841
3307
 
5842
3308
  namespace duckdb {
@@ -6411,101 +3877,6 @@ void CatalogSet::Scan(const std::function<void(CatalogEntry *)> &callback) {
6411
3877
  }
6412
3878
  } // namespace duckdb
6413
3879
 
6414
- //===----------------------------------------------------------------------===//
6415
- // DuckDB
6416
- //
6417
- // duckdb/parser/parser.hpp
6418
- //
6419
- //
6420
- //===----------------------------------------------------------------------===//
6421
-
6422
-
6423
-
6424
-
6425
-
6426
-
6427
-
6428
- //===----------------------------------------------------------------------===//
6429
- // DuckDB
6430
- //
6431
- // duckdb/parser/simplified_token.hpp
6432
- //
6433
- //
6434
- //===----------------------------------------------------------------------===//
6435
-
6436
-
6437
-
6438
-
6439
-
6440
- namespace duckdb {
6441
-
6442
- //! Simplified tokens are a simplified (dense) representation of the lexer
6443
- //! Used for simple syntax highlighting in the tests
6444
- enum class SimplifiedTokenType : uint8_t {
6445
- SIMPLIFIED_TOKEN_IDENTIFIER,
6446
- SIMPLIFIED_TOKEN_NUMERIC_CONSTANT,
6447
- SIMPLIFIED_TOKEN_STRING_CONSTANT,
6448
- SIMPLIFIED_TOKEN_OPERATOR,
6449
- SIMPLIFIED_TOKEN_KEYWORD,
6450
- SIMPLIFIED_TOKEN_COMMENT
6451
- };
6452
-
6453
- struct SimplifiedToken {
6454
- SimplifiedTokenType type;
6455
- idx_t start;
6456
- };
6457
-
6458
- } // namespace duckdb
6459
-
6460
-
6461
- namespace duckdb_libpgquery {
6462
- struct PGNode;
6463
- struct PGList;
6464
- } // namespace duckdb_libpgquery
6465
-
6466
- namespace duckdb {
6467
-
6468
- //! The parser is responsible for parsing the query and converting it into a set
6469
- //! of parsed statements. The parsed statements can then be converted into a
6470
- //! plan and executed.
6471
- class Parser {
6472
- public:
6473
- Parser();
6474
-
6475
- //! Attempts to parse a query into a series of SQL statements. Returns
6476
- //! whether or not the parsing was successful. If the parsing was
6477
- //! successful, the parsed statements will be stored in the statements
6478
- //! variable.
6479
- void ParseQuery(const string &query);
6480
-
6481
- //! Tokenize a query, returning the raw tokens together with their locations
6482
- static vector<SimplifiedToken> Tokenize(const string &query);
6483
-
6484
- //! Returns true if the given text matches a keyword of the parser
6485
- static bool IsKeyword(const string &text);
6486
-
6487
- //! Parses a list of expressions (i.e. the list found in a SELECT clause)
6488
- static vector<unique_ptr<ParsedExpression>> ParseExpressionList(const string &select_list);
6489
- //! Parses a list as found in an ORDER BY expression (i.e. including optional ASCENDING/DESCENDING modifiers)
6490
- static vector<OrderByNode> ParseOrderList(const string &select_list);
6491
- //! Parses an update list (i.e. the list found in the SET clause of an UPDATE statement)
6492
- static void ParseUpdateList(const string &update_list, vector<string> &update_columns,
6493
- vector<unique_ptr<ParsedExpression>> &expressions);
6494
- //! Parses a VALUES list (i.e. the list of expressions after a VALUES clause)
6495
- static vector<vector<unique_ptr<ParsedExpression>>> ParseValuesList(const string &value_list);
6496
- //! Parses a column list (i.e. as found in a CREATE TABLE statement)
6497
- static vector<ColumnDefinition> ParseColumnList(const string &column_list);
6498
-
6499
- //! The parsed SQL statements from an invocation to ParseQuery.
6500
- vector<unique_ptr<SQLStatement>> statements;
6501
-
6502
- private:
6503
- //! Transform a Postgres parse tree into a set of SQL Statements
6504
- bool TransformList(duckdb_libpgquery::PGList *tree);
6505
- //! Transform a single Postgres parse node into a SQL Statement.
6506
- unique_ptr<SQLStatement> TransformNode(duckdb_libpgquery::PGNode *stmt);
6507
- };
6508
- } // namespace duckdb
6509
3880
 
6510
3881
 
6511
3882
 
@@ -7052,73 +4423,6 @@ data_ptr_t Allocator::ReallocateData(data_ptr_t pointer, idx_t size) {
7052
4423
  }
7053
4424
 
7054
4425
  } // namespace duckdb
7055
- //===----------------------------------------------------------------------===//
7056
- // DuckDB
7057
- //
7058
- // duckdb/common/arrow_wrapper.hpp
7059
- //
7060
- //
7061
- //===----------------------------------------------------------------------===//
7062
-
7063
-
7064
-
7065
-
7066
-
7067
-
7068
- //! Here we have the internal duckdb classes that interact with Arrow's Internal Header (i.e., duckdb/commons/arrow.hpp)
7069
- namespace duckdb {
7070
- class ArrowSchemaWrapper {
7071
- public:
7072
- ArrowSchema arrow_schema;
7073
-
7074
- ArrowSchemaWrapper() {
7075
- arrow_schema.release = nullptr;
7076
- }
7077
-
7078
- ~ArrowSchemaWrapper();
7079
- };
7080
- class ArrowArrayWrapper {
7081
- public:
7082
- ArrowArray arrow_array;
7083
- ArrowArrayWrapper() {
7084
- arrow_array.length = 0;
7085
- arrow_array.release = nullptr;
7086
- }
7087
- ~ArrowArrayWrapper();
7088
- };
7089
-
7090
- class ArrowArrayStreamWrapper {
7091
- public:
7092
- ArrowArrayStream arrow_array_stream;
7093
- int64_t number_of_rows;
7094
- void GetSchema(ArrowSchemaWrapper &schema);
7095
-
7096
- unique_ptr<ArrowArrayWrapper> GetNextChunk();
7097
-
7098
- const char *GetError();
7099
-
7100
- ~ArrowArrayStreamWrapper();
7101
- ArrowArrayStreamWrapper() {
7102
- arrow_array_stream.release = nullptr;
7103
- }
7104
- };
7105
-
7106
- class ResultArrowArrayStreamWrapper {
7107
- public:
7108
- explicit ResultArrowArrayStreamWrapper(unique_ptr<QueryResult> result, idx_t approx_batch_size);
7109
- ArrowArrayStream stream;
7110
- unique_ptr<QueryResult> result;
7111
- std::string last_error;
7112
- idx_t vectors_per_chunk;
7113
-
7114
- private:
7115
- static int MyStreamGetSchema(struct ArrowArrayStream *stream, struct ArrowSchema *out);
7116
- static int MyStreamGetNext(struct ArrowArrayStream *stream, struct ArrowArray *out);
7117
- static void MyStreamRelease(struct ArrowArrayStream *stream);
7118
- static const char *MyStreamGetLastError(struct ArrowArrayStream *stream);
7119
- };
7120
-
7121
- } // namespace duckdb
7122
4426
 
7123
4427
 
7124
4428
 
@@ -7327,85 +4631,6 @@ uint64_t Checksum(uint8_t *buffer, size_t size) {
7327
4631
  return result;
7328
4632
  }
7329
4633
 
7330
- } // namespace duckdb
7331
- //===----------------------------------------------------------------------===//
7332
- // DuckDB
7333
- //
7334
- // duckdb/common/compressed_file_system.hpp
7335
- //
7336
- //
7337
- //===----------------------------------------------------------------------===//
7338
-
7339
-
7340
-
7341
-
7342
-
7343
-
7344
- namespace duckdb {
7345
- class CompressedFile;
7346
-
7347
- struct StreamData {
7348
- // various buffers & pointers
7349
- bool write = false;
7350
- unique_ptr<data_t[]> in_buff;
7351
- unique_ptr<data_t[]> out_buff;
7352
- data_ptr_t out_buff_start = nullptr;
7353
- data_ptr_t out_buff_end = nullptr;
7354
- data_ptr_t in_buff_start = nullptr;
7355
- data_ptr_t in_buff_end = nullptr;
7356
-
7357
- idx_t in_buf_size = 0;
7358
- idx_t out_buf_size = 0;
7359
- };
7360
-
7361
- struct StreamWrapper {
7362
- DUCKDB_API virtual ~StreamWrapper();
7363
-
7364
- DUCKDB_API virtual void Initialize(CompressedFile &file, bool write) = 0;
7365
- DUCKDB_API virtual bool Read(StreamData &stream_data) = 0;
7366
- DUCKDB_API virtual void Write(CompressedFile &file, StreamData &stream_data, data_ptr_t buffer,
7367
- int64_t nr_bytes) = 0;
7368
- DUCKDB_API virtual void Close() = 0;
7369
- };
7370
-
7371
- class CompressedFileSystem : public FileSystem {
7372
- public:
7373
- DUCKDB_API int64_t Read(FileHandle &handle, void *buffer, int64_t nr_bytes) override;
7374
- DUCKDB_API int64_t Write(FileHandle &handle, void *buffer, int64_t nr_bytes) override;
7375
-
7376
- DUCKDB_API void Reset(FileHandle &handle) override;
7377
-
7378
- DUCKDB_API int64_t GetFileSize(FileHandle &handle) override;
7379
-
7380
- DUCKDB_API bool OnDiskFile(FileHandle &handle) override;
7381
- DUCKDB_API bool CanSeek() override;
7382
-
7383
- DUCKDB_API virtual unique_ptr<StreamWrapper> CreateStream() = 0;
7384
- DUCKDB_API virtual idx_t InBufferSize() = 0;
7385
- DUCKDB_API virtual idx_t OutBufferSize() = 0;
7386
- };
7387
-
7388
- class CompressedFile : public FileHandle {
7389
- public:
7390
- DUCKDB_API CompressedFile(CompressedFileSystem &fs, unique_ptr<FileHandle> child_handle_p, const string &path);
7391
- DUCKDB_API virtual ~CompressedFile() override;
7392
-
7393
- CompressedFileSystem &compressed_fs;
7394
- unique_ptr<FileHandle> child_handle;
7395
- //! Whether the file is opened for reading or for writing
7396
- bool write = false;
7397
- StreamData stream_data;
7398
-
7399
- public:
7400
- DUCKDB_API void Initialize(bool write);
7401
- DUCKDB_API int64_t ReadData(void *buffer, int64_t nr_bytes);
7402
- DUCKDB_API int64_t WriteData(data_ptr_t buffer, int64_t nr_bytes);
7403
- DUCKDB_API void Close() override;
7404
-
7405
- private:
7406
- unique_ptr<StreamWrapper> stream_wrapper;
7407
- };
7408
-
7409
4634
  } // namespace duckdb
7410
4635
 
7411
4636
 
@@ -18020,47 +15245,6 @@ idx_t GZipFileSystem::OutBufferSize() {
18020
15245
 
18021
15246
 
18022
15247
 
18023
- //===----------------------------------------------------------------------===//
18024
- // DuckDB
18025
- //
18026
- // duckdb/common/windows_undefs.hpp
18027
- //
18028
- //
18029
- //===----------------------------------------------------------------------===//
18030
-
18031
-
18032
-
18033
- #ifdef WIN32
18034
-
18035
- #ifdef min
18036
- #undef min
18037
- #endif
18038
-
18039
- #ifdef max
18040
- #undef max
18041
- #endif
18042
-
18043
- #ifdef ERROR
18044
- #undef ERROR
18045
- #endif
18046
-
18047
- #ifdef small
18048
- #undef small
18049
- #endif
18050
-
18051
- #ifdef CreateDirectory
18052
- #undef CreateDirectory
18053
- #endif
18054
-
18055
- #ifdef MoveFile
18056
- #undef MoveFile
18057
- #endif
18058
-
18059
- #ifdef RemoveDirectory
18060
- #undef RemoveDirectory
18061
- #endif
18062
-
18063
- #endif
18064
15248
 
18065
15249
  #include <limits>
18066
15250
 
@@ -29189,121 +26373,6 @@ void LocalSortState::SortInMemory() {
29189
26373
 
29190
26374
 
29191
26375
 
29192
- //===----------------------------------------------------------------------===//
29193
- // DuckDB
29194
- //
29195
- // duckdb/storage/statistics/string_statistics.hpp
29196
- //
29197
- //
29198
- //===----------------------------------------------------------------------===//
29199
-
29200
-
29201
-
29202
-
29203
- //===----------------------------------------------------------------------===//
29204
- // DuckDB
29205
- //
29206
- // duckdb/common/enums/filter_propagate_result.hpp
29207
- //
29208
- //
29209
- //===----------------------------------------------------------------------===//
29210
-
29211
-
29212
-
29213
-
29214
-
29215
- namespace duckdb {
29216
-
29217
- enum class FilterPropagateResult : uint8_t {
29218
- NO_PRUNING_POSSIBLE = 0,
29219
- FILTER_ALWAYS_TRUE = 1,
29220
- FILTER_ALWAYS_FALSE = 2,
29221
- FILTER_TRUE_OR_NULL = 3,
29222
- FILTER_FALSE_OR_NULL = 4
29223
- };
29224
-
29225
- } // namespace duckdb
29226
-
29227
- //===----------------------------------------------------------------------===//
29228
- // DuckDB
29229
- //
29230
- // duckdb/storage/statistics/validity_statistics.hpp
29231
- //
29232
- //
29233
- //===----------------------------------------------------------------------===//
29234
-
29235
-
29236
-
29237
-
29238
-
29239
- namespace duckdb {
29240
- class Serializer;
29241
- class Deserializer;
29242
- class Vector;
29243
-
29244
- class ValidityStatistics : public BaseStatistics {
29245
- public:
29246
- ValidityStatistics(bool has_null = false, bool has_no_null = true);
29247
-
29248
- //! Whether or not the segment can contain NULL values
29249
- bool has_null;
29250
- //! Whether or not the segment can contain values that are not null
29251
- bool has_no_null;
29252
-
29253
- public:
29254
- void Merge(const BaseStatistics &other) override;
29255
-
29256
- bool IsConstant() override;
29257
-
29258
- unique_ptr<BaseStatistics> Copy() override;
29259
- void Serialize(Serializer &serializer) override;
29260
- static unique_ptr<BaseStatistics> Deserialize(Deserializer &source);
29261
- void Verify(Vector &vector, const SelectionVector &sel, idx_t count) override;
29262
-
29263
- static unique_ptr<BaseStatistics> Combine(const unique_ptr<BaseStatistics> &lstats,
29264
- const unique_ptr<BaseStatistics> &rstats);
29265
-
29266
- string ToString() override;
29267
- };
29268
-
29269
- } // namespace duckdb
29270
-
29271
-
29272
- namespace duckdb {
29273
-
29274
- class StringStatistics : public BaseStatistics {
29275
- public:
29276
- constexpr static uint32_t MAX_STRING_MINMAX_SIZE = 8;
29277
-
29278
- public:
29279
- explicit StringStatistics(LogicalType type);
29280
-
29281
- //! The minimum value of the segment, potentially truncated
29282
- data_t min[MAX_STRING_MINMAX_SIZE];
29283
- //! The maximum value of the segment, potentially truncated
29284
- data_t max[MAX_STRING_MINMAX_SIZE];
29285
- //! Whether or not the column can contain unicode characters
29286
- bool has_unicode;
29287
- //! The maximum string length in bytes
29288
- uint32_t max_string_length;
29289
- //! Whether or not the segment contains any big strings in overflow blocks
29290
- bool has_overflow_strings;
29291
-
29292
- public:
29293
- void Update(const string_t &value);
29294
- void Merge(const BaseStatistics &other) override;
29295
-
29296
- unique_ptr<BaseStatistics> Copy() override;
29297
- void Serialize(Serializer &serializer) override;
29298
- static unique_ptr<BaseStatistics> Deserialize(Deserializer &source, LogicalType type);
29299
- void Verify(Vector &vector, const SelectionVector &sel, idx_t count) override;
29300
-
29301
- FilterPropagateResult CheckZonemap(ExpressionType comparison_type, const string &value);
29302
-
29303
- string ToString() override;
29304
- };
29305
-
29306
- } // namespace duckdb
29307
26376
 
29308
26377
 
29309
26378
  #include <numeric>
@@ -32780,38 +29849,6 @@ struct SelCache {
32780
29849
  } // namespace duckdb
32781
29850
 
32782
29851
 
32783
- //===----------------------------------------------------------------------===//
32784
- // DuckDB
32785
- //
32786
- // duckdb/common/types/vector_cache.hpp
32787
- //
32788
- //
32789
- //===----------------------------------------------------------------------===//
32790
-
32791
-
32792
-
32793
-
32794
-
32795
-
32796
-
32797
- namespace duckdb {
32798
- class Vector;
32799
-
32800
- //! The VectorCache holds cached data that allows for re-use of the same memory by vectors
32801
- class VectorCache {
32802
- public:
32803
- //! Instantiate a vector cache with the given type
32804
- explicit VectorCache(const LogicalType &type);
32805
-
32806
- buffer_ptr<VectorBuffer> buffer;
32807
-
32808
- public:
32809
- void ResetFromCache(Vector &result) const;
32810
-
32811
- const LogicalType &GetType() const;
32812
- };
32813
-
32814
- } // namespace duckdb
32815
29852
 
32816
29853
 
32817
29854
 
@@ -45700,85 +42737,6 @@ string WindowsUtil::UTF8ToMBCS(const char *input, bool use_ansi) {
45700
42737
  } // namespace duckdb
45701
42738
 
45702
42739
 
45703
- //===----------------------------------------------------------------------===//
45704
- // DuckDB
45705
- //
45706
- // duckdb/planner/table_filter.hpp
45707
- //
45708
- //
45709
- //===----------------------------------------------------------------------===//
45710
-
45711
-
45712
-
45713
-
45714
-
45715
-
45716
-
45717
-
45718
- namespace duckdb {
45719
- class BaseStatistics;
45720
-
45721
- enum class TableFilterType : uint8_t {
45722
- CONSTANT_COMPARISON = 0, // constant comparison (e.g. =C, >C, >=C, <C, <=C)
45723
- IS_NULL = 1,
45724
- IS_NOT_NULL = 2,
45725
- CONJUNCTION_OR = 3,
45726
- CONJUNCTION_AND = 4
45727
- };
45728
-
45729
- //! TableFilter represents a filter pushed down into the table scan.
45730
- class TableFilter {
45731
- public:
45732
- TableFilter(TableFilterType filter_type_p) : filter_type(filter_type_p) {
45733
- }
45734
- virtual ~TableFilter() {
45735
- }
45736
-
45737
- TableFilterType filter_type;
45738
-
45739
- public:
45740
- //! Returns true if the statistics indicate that the segment can contain values that satisfy that filter
45741
- virtual FilterPropagateResult CheckStatistics(BaseStatistics &stats) = 0;
45742
- virtual string ToString(const string &column_name) = 0;
45743
- virtual bool Equals(const TableFilter &other) const {
45744
- return filter_type != other.filter_type;
45745
- }
45746
- };
45747
-
45748
- class TableFilterSet {
45749
- public:
45750
- unordered_map<idx_t, unique_ptr<TableFilter>> filters;
45751
-
45752
- public:
45753
- void PushFilter(idx_t table_index, unique_ptr<TableFilter> filter);
45754
-
45755
- bool Equals(TableFilterSet &other) {
45756
- if (filters.size() != other.filters.size()) {
45757
- return false;
45758
- }
45759
- for (auto &entry : filters) {
45760
- auto other_entry = other.filters.find(entry.first);
45761
- if (other_entry == other.filters.end()) {
45762
- return false;
45763
- }
45764
- if (!entry.second->Equals(*other_entry->second)) {
45765
- return false;
45766
- }
45767
- }
45768
- return true;
45769
- }
45770
- static bool Equals(TableFilterSet *left, TableFilterSet *right) {
45771
- if (left == right) {
45772
- return true;
45773
- }
45774
- if (!left || !right) {
45775
- return false;
45776
- }
45777
- return left->Equals(*right);
45778
- }
45779
- };
45780
-
45781
- } // namespace duckdb
45782
42740
 
45783
42741
  #include <vector>
45784
42742
 
@@ -50966,39 +47924,6 @@ struct MergeJoinSimple {
50966
47924
  } // namespace duckdb
50967
47925
 
50968
47926
 
50969
- //===----------------------------------------------------------------------===//
50970
- // DuckDB
50971
- //
50972
- // duckdb/parser/expression/comparison_expression.hpp
50973
- //
50974
- //
50975
- //===----------------------------------------------------------------------===//
50976
-
50977
-
50978
-
50979
-
50980
-
50981
- namespace duckdb {
50982
- //! ComparisonExpression represents a boolean comparison (e.g. =, >=, <>). Always returns a boolean
50983
- //! and has two children.
50984
- class ComparisonExpression : public ParsedExpression {
50985
- public:
50986
- ComparisonExpression(ExpressionType type, unique_ptr<ParsedExpression> left, unique_ptr<ParsedExpression> right);
50987
-
50988
- unique_ptr<ParsedExpression> left;
50989
- unique_ptr<ParsedExpression> right;
50990
-
50991
- public:
50992
- string ToString() const override;
50993
-
50994
- static bool Equals(const ComparisonExpression *a, const ComparisonExpression *b);
50995
-
50996
- unique_ptr<ParsedExpression> Copy() const override;
50997
-
50998
- void Serialize(Serializer &serializer) override;
50999
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
51000
- };
51001
- } // namespace duckdb
51002
47927
 
51003
47928
 
51004
47929
  namespace duckdb {
@@ -52072,100 +48997,6 @@ private:
52072
48997
 
52073
48998
 
52074
48999
 
52075
- //===----------------------------------------------------------------------===//
52076
- // DuckDB
52077
- //
52078
- // duckdb/storage/statistics/numeric_statistics.hpp
52079
- //
52080
- //
52081
- //===----------------------------------------------------------------------===//
52082
-
52083
-
52084
-
52085
-
52086
-
52087
-
52088
-
52089
-
52090
-
52091
-
52092
-
52093
-
52094
-
52095
-
52096
- namespace duckdb {
52097
-
52098
- class NumericStatistics : public BaseStatistics {
52099
- public:
52100
- explicit NumericStatistics(LogicalType type);
52101
- NumericStatistics(LogicalType type, Value min, Value max);
52102
-
52103
- //! The minimum value of the segment
52104
- Value min;
52105
- //! The maximum value of the segment
52106
- Value max;
52107
-
52108
- public:
52109
- void Merge(const BaseStatistics &other) override;
52110
-
52111
- bool IsConstant() override;
52112
-
52113
- FilterPropagateResult CheckZonemap(ExpressionType comparison_type, const Value &constant);
52114
-
52115
- unique_ptr<BaseStatistics> Copy() override;
52116
- void Serialize(Serializer &serializer) override;
52117
- static unique_ptr<BaseStatistics> Deserialize(Deserializer &source, LogicalType type);
52118
- void Verify(Vector &vector, const SelectionVector &sel, idx_t count) override;
52119
-
52120
- string ToString() override;
52121
-
52122
- private:
52123
- template <class T>
52124
- void TemplatedVerify(Vector &vector, const SelectionVector &sel, idx_t count);
52125
-
52126
- public:
52127
- template <class T>
52128
- static inline void UpdateValue(T new_value, T &min, T &max) {
52129
- if (LessThan::Operation(new_value, min)) {
52130
- min = new_value;
52131
- }
52132
- if (GreaterThan::Operation(new_value, max)) {
52133
- max = new_value;
52134
- }
52135
- }
52136
-
52137
- template <class T>
52138
- static inline void Update(SegmentStatistics &stats, T new_value);
52139
- };
52140
-
52141
- template <>
52142
- void NumericStatistics::Update<int8_t>(SegmentStatistics &stats, int8_t new_value);
52143
- template <>
52144
- void NumericStatistics::Update<int16_t>(SegmentStatistics &stats, int16_t new_value);
52145
- template <>
52146
- void NumericStatistics::Update<int32_t>(SegmentStatistics &stats, int32_t new_value);
52147
- template <>
52148
- void NumericStatistics::Update<int64_t>(SegmentStatistics &stats, int64_t new_value);
52149
- template <>
52150
- void NumericStatistics::Update<uint8_t>(SegmentStatistics &stats, uint8_t new_value);
52151
- template <>
52152
- void NumericStatistics::Update<uint16_t>(SegmentStatistics &stats, uint16_t new_value);
52153
- template <>
52154
- void NumericStatistics::Update<uint32_t>(SegmentStatistics &stats, uint32_t new_value);
52155
- template <>
52156
- void NumericStatistics::Update<uint64_t>(SegmentStatistics &stats, uint64_t new_value);
52157
- template <>
52158
- void NumericStatistics::Update<hugeint_t>(SegmentStatistics &stats, hugeint_t new_value);
52159
- template <>
52160
- void NumericStatistics::Update<float>(SegmentStatistics &stats, float new_value);
52161
- template <>
52162
- void NumericStatistics::Update<double>(SegmentStatistics &stats, double new_value);
52163
- template <>
52164
- void NumericStatistics::Update<interval_t>(SegmentStatistics &stats, interval_t new_value);
52165
- template <>
52166
- void NumericStatistics::Update<list_entry_t>(SegmentStatistics &stats, list_entry_t new_value);
52167
-
52168
- } // namespace duckdb
52169
49000
 
52170
49001
 
52171
49002
  namespace duckdb {
@@ -55019,36 +51850,6 @@ void PhysicalLimitPercent::GetData(ExecutionContext &context, DataChunk &chunk,
55019
51850
 
55020
51851
 
55021
51852
 
55022
- //===----------------------------------------------------------------------===//
55023
- // DuckDB
55024
- //
55025
- // duckdb/parser/parsed_data/vacuum_info.hpp
55026
- //
55027
- //
55028
- //===----------------------------------------------------------------------===//
55029
-
55030
-
55031
-
55032
-
55033
-
55034
- namespace duckdb {
55035
-
55036
- enum class LoadType { LOAD, INSTALL, FORCE_INSTALL };
55037
-
55038
- struct LoadInfo : public ParseInfo {
55039
- std::string filename;
55040
- LoadType load_type;
55041
-
55042
- public:
55043
- unique_ptr<LoadInfo> Copy() const {
55044
- auto result = make_unique<LoadInfo>();
55045
- result->filename = filename;
55046
- result->load_type = load_type;
55047
- return result;
55048
- }
55049
- };
55050
-
55051
- } // namespace duckdb
55052
51853
 
55053
51854
 
55054
51855
  namespace duckdb {
@@ -55528,25 +52329,6 @@ string PhysicalReservoirSample::ParamsToString() const {
55528
52329
 
55529
52330
 
55530
52331
 
55531
- //===----------------------------------------------------------------------===//
55532
- // DuckDB
55533
- //
55534
- // duckdb/parser/parsed_data/vacuum_info.hpp
55535
- //
55536
- //
55537
- //===----------------------------------------------------------------------===//
55538
-
55539
-
55540
-
55541
-
55542
-
55543
- namespace duckdb {
55544
-
55545
- struct VacuumInfo : public ParseInfo {
55546
- // nothing for now
55547
- };
55548
-
55549
- } // namespace duckdb
55550
52332
 
55551
52333
 
55552
52334
  namespace duckdb {
@@ -55776,31 +52558,6 @@ string PhysicalStreamingSample::ParamsToString() const {
55776
52558
 
55777
52559
 
55778
52560
 
55779
- //===----------------------------------------------------------------------===//
55780
- // DuckDB
55781
- //
55782
- // duckdb/parser/parsed_data/transaction_info.hpp
55783
- //
55784
- //
55785
- //===----------------------------------------------------------------------===//
55786
-
55787
-
55788
-
55789
-
55790
-
55791
- namespace duckdb {
55792
-
55793
- enum class TransactionType : uint8_t { INVALID, BEGIN_TRANSACTION, COMMIT, ROLLBACK };
55794
-
55795
- struct TransactionInfo : public ParseInfo {
55796
- explicit TransactionInfo(TransactionType type) : type(type) {
55797
- }
55798
-
55799
- //! The type of transaction statement
55800
- TransactionType type;
55801
- };
55802
-
55803
- } // namespace duckdb
55804
52561
 
55805
52562
 
55806
52563
  namespace duckdb {
@@ -59820,376 +56577,6 @@ string PhysicalTopN::ParamsToString() const {
59820
56577
  }
59821
56578
 
59822
56579
  } // namespace duckdb
59823
- //===----------------------------------------------------------------------===//
59824
- // DuckDB
59825
- //
59826
- // duckdb/execution/operator/persistent/buffered_csv_reader.hpp
59827
- //
59828
- //
59829
- //===----------------------------------------------------------------------===//
59830
-
59831
-
59832
-
59833
-
59834
-
59835
- //===----------------------------------------------------------------------===//
59836
- // DuckDB
59837
- //
59838
- // duckdb/function/scalar/strftime.hpp
59839
- //
59840
- //
59841
- //===----------------------------------------------------------------------===//
59842
-
59843
-
59844
-
59845
-
59846
-
59847
-
59848
- namespace duckdb {
59849
-
59850
- enum class StrTimeSpecifier : uint8_t {
59851
- ABBREVIATED_WEEKDAY_NAME = 0, // %a - Abbreviated weekday name. (Sun, Mon, ...)
59852
- FULL_WEEKDAY_NAME = 1, // %A Full weekday name. (Sunday, Monday, ...)
59853
- WEEKDAY_DECIMAL = 2, // %w - Weekday as a decimal number. (0, 1, ..., 6)
59854
- DAY_OF_MONTH_PADDED = 3, // %d - Day of the month as a zero-padded decimal. (01, 02, ..., 31)
59855
- DAY_OF_MONTH = 4, // %-d - Day of the month as a decimal number. (1, 2, ..., 30)
59856
- ABBREVIATED_MONTH_NAME = 5, // %b - Abbreviated month name. (Jan, Feb, ..., Dec)
59857
- FULL_MONTH_NAME = 6, // %B - Full month name. (January, February, ...)
59858
- MONTH_DECIMAL_PADDED = 7, // %m - Month as a zero-padded decimal number. (01, 02, ..., 12)
59859
- MONTH_DECIMAL = 8, // %-m - Month as a decimal number. (1, 2, ..., 12)
59860
- YEAR_WITHOUT_CENTURY_PADDED = 9, // %y - Year without century as a zero-padded decimal number. (00, 01, ..., 99)
59861
- YEAR_WITHOUT_CENTURY = 10, // %-y - Year without century as a decimal number. (0, 1, ..., 99)
59862
- YEAR_DECIMAL = 11, // %Y - Year with century as a decimal number. (2013, 2019 etc.)
59863
- HOUR_24_PADDED = 12, // %H - Hour (24-hour clock) as a zero-padded decimal number. (00, 01, ..., 23)
59864
- HOUR_24_DECIMAL = 13, // %-H - Hour (24-hour clock) as a decimal number. (0, 1, ..., 23)
59865
- HOUR_12_PADDED = 14, // %I - Hour (12-hour clock) as a zero-padded decimal number. (01, 02, ..., 12)
59866
- HOUR_12_DECIMAL = 15, // %-I - Hour (12-hour clock) as a decimal number. (1, 2, ... 12)
59867
- AM_PM = 16, // %p - Locale’s AM or PM. (AM, PM)
59868
- MINUTE_PADDED = 17, // %M - Minute as a zero-padded decimal number. (00, 01, ..., 59)
59869
- MINUTE_DECIMAL = 18, // %-M - Minute as a decimal number. (0, 1, ..., 59)
59870
- SECOND_PADDED = 19, // %S - Second as a zero-padded decimal number. (00, 01, ..., 59)
59871
- SECOND_DECIMAL = 20, // %-S - Second as a decimal number. (0, 1, ..., 59)
59872
- MICROSECOND_PADDED = 21, // %f - Microsecond as a decimal number, zero-padded on the left. (000000 - 999999)
59873
- MILLISECOND_PADDED = 22, // %g - Millisecond as a decimal number, zero-padded on the left. (000 - 999)
59874
- UTC_OFFSET = 23, // %z - UTC offset in the form +HHMM or -HHMM. ( )
59875
- TZ_NAME = 24, // %Z - Time zone name. ( )
59876
- DAY_OF_YEAR_PADDED = 25, // %j - Day of the year as a zero-padded decimal number. (001, 002, ..., 366)
59877
- DAY_OF_YEAR_DECIMAL = 26, // %-j - Day of the year as a decimal number. (1, 2, ..., 366)
59878
- WEEK_NUMBER_PADDED_SUN_FIRST =
59879
- 27, // %U - Week number of the year (Sunday as the first day of the week). All days in a new year preceding the
59880
- // first Sunday are considered to be in week 0. (00, 01, ..., 53)
59881
- WEEK_NUMBER_PADDED_MON_FIRST =
59882
- 28, // %W - Week number of the year (Monday as the first day of the week). All days in a new year preceding the
59883
- // first Monday are considered to be in week 0. (00, 01, ..., 53)
59884
- LOCALE_APPROPRIATE_DATE_AND_TIME =
59885
- 29, // %c - Locale’s appropriate date and time representation. (Mon Sep 30 07:06:05 2013)
59886
- LOCALE_APPROPRIATE_DATE = 30, // %x - Locale’s appropriate date representation. (09/30/13)
59887
- LOCALE_APPROPRIATE_TIME = 31 // %X - Locale’s appropriate time representation. (07:06:05)
59888
- };
59889
-
59890
- struct StrTimeFormat {
59891
- public:
59892
- virtual ~StrTimeFormat() {
59893
- }
59894
-
59895
- static string ParseFormatSpecifier(const string &format_string, StrTimeFormat &format);
59896
-
59897
- protected:
59898
- //! The format specifiers
59899
- vector<StrTimeSpecifier> specifiers;
59900
- //! The literals that appear in between the format specifiers
59901
- //! The following must hold: literals.size() = specifiers.size() + 1
59902
- //! Format is literals[0], specifiers[0], literals[1], ..., specifiers[n - 1], literals[n]
59903
- vector<string> literals;
59904
- //! The constant size that appears in the format string
59905
- idx_t constant_size;
59906
- //! The max numeric width of the specifier (if it is parsed as a number), or -1 if it is not a number
59907
- vector<int> numeric_width;
59908
-
59909
- protected:
59910
- void AddLiteral(string literal);
59911
- virtual void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier);
59912
- };
59913
-
59914
- struct StrfTimeFormat : public StrTimeFormat {
59915
- idx_t GetLength(date_t date, dtime_t time);
59916
-
59917
- void FormatString(date_t date, int32_t data[7], char *target);
59918
- void FormatString(date_t date, dtime_t time, char *target);
59919
-
59920
- static string Format(timestamp_t timestamp, const string &format);
59921
-
59922
- protected:
59923
- //! The variable-length specifiers. To determine total string size, these need to be checked.
59924
- vector<StrTimeSpecifier> var_length_specifiers;
59925
- //! Whether or not the current specifier is a special "date" specifier (i.e. one that requires a date_t object to
59926
- //! generate)
59927
- vector<bool> is_date_specifier;
59928
-
59929
- protected:
59930
- void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
59931
- static idx_t GetSpecifierLength(StrTimeSpecifier specifier, date_t date, dtime_t time);
59932
- char *WriteString(char *target, const string_t &str);
59933
- char *Write2(char *target, uint8_t value);
59934
- char *WritePadded2(char *target, int32_t value);
59935
- char *WritePadded3(char *target, uint32_t value);
59936
- char *WritePadded(char *target, int32_t value, int32_t padding);
59937
- bool IsDateSpecifier(StrTimeSpecifier specifier);
59938
- char *WriteDateSpecifier(StrTimeSpecifier specifier, date_t date, char *target);
59939
- char *WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], char *target);
59940
- };
59941
-
59942
- struct StrpTimeFormat : public StrTimeFormat {
59943
- public:
59944
- //! Type-safe parsing argument
59945
- struct ParseResult {
59946
- int32_t data[7];
59947
- string error_message;
59948
- idx_t error_position = DConstants::INVALID_INDEX;
59949
-
59950
- date_t ToDate();
59951
- timestamp_t ToTimestamp();
59952
- string FormatError(string_t input, const string &format_specifier);
59953
- };
59954
- //! The full format specifier, for error messages
59955
- string format_specifier;
59956
-
59957
- bool Parse(string_t str, ParseResult &result);
59958
-
59959
- bool TryParseDate(string_t str, date_t &result, string &error_message);
59960
- bool TryParseTimestamp(string_t str, timestamp_t &result, string &error_message);
59961
-
59962
- date_t ParseDate(string_t str);
59963
- timestamp_t ParseTimestamp(string_t str);
59964
-
59965
- protected:
59966
- static string FormatStrpTimeError(const string &input, idx_t position);
59967
- void AddFormatSpecifier(string preceding_literal, StrTimeSpecifier specifier) override;
59968
- int NumericSpecifierWidth(StrTimeSpecifier specifier);
59969
- int32_t TryParseCollection(const char *data, idx_t &pos, idx_t size, const string_t collection[],
59970
- idx_t collection_count);
59971
- };
59972
-
59973
- } // namespace duckdb
59974
-
59975
-
59976
-
59977
-
59978
-
59979
- #include <sstream>
59980
- #include <queue>
59981
-
59982
- namespace duckdb {
59983
- struct CopyInfo;
59984
- struct FileHandle;
59985
- struct StrpTimeFormat;
59986
-
59987
- class FileOpener;
59988
- class FileSystem;
59989
-
59990
- //! The shifts array allows for linear searching of multi-byte values. For each position, it determines the next
59991
- //! position given that we encounter a byte with the given value.
59992
- /*! For example, if we have a string "ABAC", the shifts array will have the following values:
59993
- * [0] --> ['A'] = 1, all others = 0
59994
- * [1] --> ['B'] = 2, ['A'] = 1, all others = 0
59995
- * [2] --> ['A'] = 3, all others = 0
59996
- * [3] --> ['C'] = 4 (match), 'B' = 2, 'A' = 1, all others = 0
59997
- * Suppose we then search in the following string "ABABAC", our progression will be as follows:
59998
- * 'A' -> [1], 'B' -> [2], 'A' -> [3], 'B' -> [2], 'A' -> [3], 'C' -> [4] (match!)
59999
- */
60000
- struct TextSearchShiftArray {
60001
- TextSearchShiftArray();
60002
- explicit TextSearchShiftArray(string search_term);
60003
-
60004
- inline bool Match(uint8_t &position, uint8_t byte_value) {
60005
- if (position >= length) {
60006
- return false;
60007
- }
60008
- position = shifts[position * 255 + byte_value];
60009
- return position == length;
60010
- }
60011
-
60012
- idx_t length;
60013
- unique_ptr<uint8_t[]> shifts;
60014
- };
60015
-
60016
- struct BufferedCSVReaderOptions {
60017
- //! The file path of the CSV file to read
60018
- string file_path;
60019
- //! Whether file is compressed or not, and if so which compression type
60020
- //! AUTO_DETECT (default; infer from file extension)
60021
- FileCompressionType compression = FileCompressionType::AUTO_DETECT;
60022
- //! Whether or not to automatically detect dialect and datatypes
60023
- bool auto_detect = false;
60024
- //! Whether or not a delimiter was defined by the user
60025
- bool has_delimiter = false;
60026
- //! Delimiter to separate columns within each line
60027
- string delimiter = ",";
60028
- //! Whether or not a quote sign was defined by the user
60029
- bool has_quote = false;
60030
- //! Quote used for columns that contain reserved characters, e.g., delimiter
60031
- string quote = "\"";
60032
- //! Whether or not an escape character was defined by the user
60033
- bool has_escape = false;
60034
- //! Escape character to escape quote character
60035
- string escape;
60036
- //! Whether or not a header information was given by the user
60037
- bool has_header = false;
60038
- //! Whether or not the file has a header line
60039
- bool header = false;
60040
- //! Whether or not header names shall be normalized
60041
- bool normalize_names = false;
60042
- //! How many leading rows to skip
60043
- idx_t skip_rows = 0;
60044
- //! Expected number of columns
60045
- idx_t num_cols = 0;
60046
- //! Specifies the string that represents a null value
60047
- string null_str;
60048
- //! True, if column with that index must skip null check
60049
- vector<bool> force_not_null;
60050
- //! Size of sample chunk used for dialect and type detection
60051
- idx_t sample_chunk_size = STANDARD_VECTOR_SIZE;
60052
- //! Number of sample chunks used for type detection
60053
- idx_t sample_chunks = 10;
60054
- //! Number of samples to buffer
60055
- idx_t buffer_size = STANDARD_VECTOR_SIZE * 100;
60056
- //! Consider all columns to be of type varchar
60057
- bool all_varchar = false;
60058
- //! The date format to use (if any is specified)
60059
- std::map<LogicalTypeId, StrpTimeFormat> date_format = {{LogicalTypeId::DATE, {}}, {LogicalTypeId::TIMESTAMP, {}}};
60060
- //! Whether or not a type format is specified
60061
- std::map<LogicalTypeId, bool> has_format = {{LogicalTypeId::DATE, false}, {LogicalTypeId::TIMESTAMP, false}};
60062
-
60063
- void SetDelimiter(const string &delimiter);
60064
-
60065
- std::string ToString() const;
60066
- };
60067
-
60068
- enum class ParserMode : uint8_t { PARSING = 0, SNIFFING_DIALECT = 1, SNIFFING_DATATYPES = 2, PARSING_HEADER = 3 };
60069
-
60070
- //! Buffered CSV reader is a class that reads values from a stream and parses them as a CSV file
60071
- class BufferedCSVReader {
60072
- //! Initial buffer read size; can be extended for long lines
60073
- static constexpr idx_t INITIAL_BUFFER_SIZE = 16384;
60074
- //! Maximum CSV line size: specified because if we reach this amount, we likely have the wrong delimiters
60075
- static constexpr idx_t MAXIMUM_CSV_LINE_SIZE = 1048576;
60076
- ParserMode mode;
60077
-
60078
- public:
60079
- BufferedCSVReader(ClientContext &context, BufferedCSVReaderOptions options,
60080
- const vector<LogicalType> &requested_types = vector<LogicalType>());
60081
-
60082
- BufferedCSVReader(FileSystem &fs, FileOpener *opener, BufferedCSVReaderOptions options,
60083
- const vector<LogicalType> &requested_types = vector<LogicalType>());
60084
-
60085
- FileSystem &fs;
60086
- FileOpener *opener;
60087
- BufferedCSVReaderOptions options;
60088
- vector<LogicalType> sql_types;
60089
- vector<string> col_names;
60090
- unique_ptr<FileHandle> file_handle;
60091
- bool plain_file_source = false;
60092
- idx_t file_size = 0;
60093
-
60094
- unique_ptr<char[]> buffer;
60095
- idx_t buffer_size;
60096
- idx_t position;
60097
- idx_t start = 0;
60098
-
60099
- idx_t linenr = 0;
60100
- bool linenr_estimated = false;
60101
-
60102
- vector<idx_t> sniffed_column_counts;
60103
- bool row_empty = false;
60104
- idx_t sample_chunk_idx = 0;
60105
- bool jumping_samples = false;
60106
- bool end_of_file_reached = false;
60107
- bool bom_checked = false;
60108
-
60109
- idx_t bytes_in_chunk = 0;
60110
- double bytes_per_line_avg = 0;
60111
-
60112
- vector<unique_ptr<char[]>> cached_buffers;
60113
-
60114
- TextSearchShiftArray delimiter_search, escape_search, quote_search;
60115
-
60116
- DataChunk parse_chunk;
60117
-
60118
- std::queue<unique_ptr<DataChunk>> cached_chunks;
60119
-
60120
- public:
60121
- //! Extract a single DataChunk from the CSV file and stores it in insert_chunk
60122
- void ParseCSV(DataChunk &insert_chunk);
60123
-
60124
- private:
60125
- //! Initialize Parser
60126
- void Initialize(const vector<LogicalType> &requested_types);
60127
- //! Initializes the parse_chunk with varchar columns and aligns info with new number of cols
60128
- void InitParseChunk(idx_t num_cols);
60129
- //! Initializes the TextSearchShiftArrays for complex parser
60130
- void PrepareComplexParser();
60131
- //! Try to parse a single datachunk from the file. Throws an exception if anything goes wrong.
60132
- void ParseCSV(ParserMode mode);
60133
- //! Try to parse a single datachunk from the file. Returns whether or not the parsing is successful
60134
- bool TryParseCSV(ParserMode mode);
60135
- //! Extract a single DataChunk from the CSV file and stores it in insert_chunk
60136
- bool TryParseCSV(ParserMode mode, DataChunk &insert_chunk, string &error_message);
60137
- //! Sniffs CSV dialect and determines skip rows, header row, column types and column names
60138
- vector<LogicalType> SniffCSV(const vector<LogicalType> &requested_types);
60139
- //! Change the date format for the type to the string
60140
- void SetDateFormat(const string &format_specifier, const LogicalTypeId &sql_type);
60141
- //! Try to cast a string value to the specified sql type
60142
- bool TryCastValue(const Value &value, const LogicalType &sql_type);
60143
- //! Try to cast a vector of values to the specified sql type
60144
- bool TryCastVector(Vector &parse_chunk_col, idx_t size, const LogicalType &sql_type);
60145
- //! Skips skip_rows, reads header row from input stream
60146
- void SkipRowsAndReadHeader(idx_t skip_rows, bool skip_header);
60147
- //! Jumps back to the beginning of input stream and resets necessary internal states
60148
- void JumpToBeginning(idx_t skip_rows, bool skip_header);
60149
- //! Jumps back to the beginning of input stream and resets necessary internal states
60150
- bool JumpToNextSample();
60151
- //! Resets the buffer
60152
- void ResetBuffer();
60153
- //! Resets the steam
60154
- void ResetStream();
60155
-
60156
- //! Parses a CSV file with a one-byte delimiter, escape and quote character
60157
- bool TryParseSimpleCSV(DataChunk &insert_chunk, string &error_message);
60158
- //! Parses more complex CSV files with multi-byte delimiters, escapes or quotes
60159
- bool TryParseComplexCSV(DataChunk &insert_chunk, string &error_message);
60160
-
60161
- //! Adds a value to the current row
60162
- void AddValue(char *str_val, idx_t length, idx_t &column, vector<idx_t> &escape_positions);
60163
- //! Adds a row to the insert_chunk, returns true if the chunk is filled as a result of this row being added
60164
- bool AddRow(DataChunk &insert_chunk, idx_t &column);
60165
- //! Finalizes a chunk, parsing all values that have been added so far and adding them to the insert_chunk
60166
- void Flush(DataChunk &insert_chunk);
60167
- //! Reads a new buffer from the CSV file if the current one has been exhausted
60168
- bool ReadBuffer(idx_t &start);
60169
-
60170
- unique_ptr<FileHandle> OpenCSV(const BufferedCSVReaderOptions &options);
60171
-
60172
- //! First phase of auto detection: detect CSV dialect (i.e. delimiter, quote rules, etc)
60173
- void DetectDialect(const vector<LogicalType> &requested_types, BufferedCSVReaderOptions &original_options,
60174
- vector<BufferedCSVReaderOptions> &info_candidates, idx_t &best_num_cols);
60175
- //! Second phase of auto detection: detect candidate types for each column
60176
- void DetectCandidateTypes(const vector<LogicalType> &type_candidates,
60177
- const map<LogicalTypeId, vector<const char *>> &format_template_candidates,
60178
- const vector<BufferedCSVReaderOptions> &info_candidates,
60179
- BufferedCSVReaderOptions &original_options, idx_t best_num_cols,
60180
- vector<vector<LogicalType>> &best_sql_types_candidates,
60181
- std::map<LogicalTypeId, vector<string>> &best_format_candidates,
60182
- DataChunk &best_header_row);
60183
- //! Third phase of auto detection: detect header of CSV file
60184
- void DetectHeader(const vector<vector<LogicalType>> &best_sql_types_candidates, const DataChunk &best_header_row);
60185
- //! Fourth phase of auto detection: refine the types of each column and select which types to use for each column
60186
- vector<LogicalType> RefineTypeDetection(const vector<LogicalType> &type_candidates,
60187
- const vector<LogicalType> &requested_types,
60188
- vector<vector<LogicalType>> &best_sql_types_candidates,
60189
- map<LogicalTypeId, vector<string>> &best_format_candidates);
60190
- };
60191
-
60192
- } // namespace duckdb
60193
56580
 
60194
56581
 
60195
56582
 
@@ -62110,37 +58497,6 @@ void PhysicalDelete::GetData(ExecutionContext &context, DataChunk &chunk, Global
62110
58497
 
62111
58498
 
62112
58499
 
62113
- //===----------------------------------------------------------------------===//
62114
- // DuckDB
62115
- //
62116
- // duckdb/parser/parsed_data/export_table_data.hpp
62117
- //
62118
- //
62119
- //===----------------------------------------------------------------------===//
62120
-
62121
-
62122
-
62123
-
62124
-
62125
-
62126
- namespace duckdb {
62127
-
62128
- struct ExportedTableData {
62129
- //! Name of the exported table
62130
- string table_name;
62131
-
62132
- //! Name of the schema
62133
- string schema_name;
62134
-
62135
- //! Path to be exported
62136
- string file_path;
62137
- };
62138
-
62139
- struct BoundExportData : public ParseInfo {
62140
- unordered_map<TableCatalogEntry *, ExportedTableData> data;
62141
- };
62142
-
62143
- } // namespace duckdb
62144
58500
 
62145
58501
 
62146
58502
  namespace duckdb {
@@ -67594,10 +63950,7 @@ namespace duckdb {
67594
63950
  //! LogicalLimit represents a LIMIT clause
67595
63951
  class LogicalLimit : public LogicalOperator {
67596
63952
  public:
67597
- LogicalLimit(int64_t limit_val, int64_t offset_val, unique_ptr<Expression> limit, unique_ptr<Expression> offset)
67598
- : LogicalOperator(LogicalOperatorType::LOGICAL_LIMIT), limit_val(limit_val), offset_val(offset_val),
67599
- limit(move(limit)), offset(move(offset)) {
67600
- }
63953
+ LogicalLimit(int64_t limit_val, int64_t offset_val, unique_ptr<Expression> limit, unique_ptr<Expression> offset);
67601
63954
 
67602
63955
  //! Limit and offset values in case they are constants, used in optimizations.
67603
63956
  int64_t limit_val;
@@ -67608,14 +63961,12 @@ public:
67608
63961
  unique_ptr<Expression> offset;
67609
63962
 
67610
63963
  public:
67611
- vector<ColumnBinding> GetColumnBindings() override {
67612
- return children[0]->GetColumnBindings();
67613
- }
63964
+ vector<ColumnBinding> GetColumnBindings() override;
63965
+
63966
+ idx_t EstimateCardinality(ClientContext &context) override;
67614
63967
 
67615
63968
  protected:
67616
- void ResolveTypes() override {
67617
- types = children[0]->types;
67618
- }
63969
+ void ResolveTypes() override;
67619
63970
  };
67620
63971
  } // namespace duckdb
67621
63972
 
@@ -68038,23 +64389,18 @@ namespace duckdb {
68038
64389
  //! LogicalSample represents a SAMPLE clause
68039
64390
  class LogicalSample : public LogicalOperator {
68040
64391
  public:
68041
- LogicalSample(unique_ptr<SampleOptions> sample_options_p, unique_ptr<LogicalOperator> child)
68042
- : LogicalOperator(LogicalOperatorType::LOGICAL_SAMPLE), sample_options(move(sample_options_p)) {
68043
- children.push_back(move(child));
68044
- }
64392
+ LogicalSample(unique_ptr<SampleOptions> sample_options_p, unique_ptr<LogicalOperator> child);
68045
64393
 
68046
64394
  //! The sample options
68047
64395
  unique_ptr<SampleOptions> sample_options;
68048
64396
 
68049
64397
  public:
68050
- vector<ColumnBinding> GetColumnBindings() override {
68051
- return children[0]->GetColumnBindings();
68052
- }
64398
+ vector<ColumnBinding> GetColumnBindings() override;
64399
+
64400
+ idx_t EstimateCardinality(ClientContext &context) override;
68053
64401
 
68054
64402
  protected:
68055
- void ResolveTypes() override {
68056
- types = children[0]->types;
68057
- }
64403
+ void ResolveTypes() override;
68058
64404
  };
68059
64405
 
68060
64406
  } // namespace duckdb
@@ -68224,42 +64570,6 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalSetOperati
68224
64570
  } // namespace duckdb
68225
64571
 
68226
64572
 
68227
- //===----------------------------------------------------------------------===//
68228
- // DuckDB
68229
- //
68230
- // duckdb/parser/parsed_data/show_select_info.hpp
68231
- //
68232
- //
68233
- //===----------------------------------------------------------------------===//
68234
-
68235
-
68236
-
68237
-
68238
-
68239
-
68240
- namespace duckdb {
68241
-
68242
- struct ShowSelectInfo : public ParseInfo {
68243
- //! Types of projected columns
68244
- vector<LogicalType> types;
68245
- //! The QueryNode of select query
68246
- unique_ptr<QueryNode> query;
68247
- //! Aliases of projected columns
68248
- vector<string> aliases;
68249
- //! Whether or not we are requesting a summary or a describe
68250
- bool is_summary;
68251
-
68252
- unique_ptr<ShowSelectInfo> Copy() {
68253
- auto result = make_unique<ShowSelectInfo>();
68254
- result->types = types;
68255
- result->query = query->Copy();
68256
- result->aliases = aliases;
68257
- result->is_summary = is_summary;
68258
- return result;
68259
- }
68260
- };
68261
-
68262
- } // namespace duckdb
68263
64573
 
68264
64574
  //===----------------------------------------------------------------------===//
68265
64575
  // DuckDB
@@ -95053,47 +91363,6 @@ void BuiltinFunctions::RegisterTableFunctions() {
95053
91363
 
95054
91364
 
95055
91365
 
95056
- //===----------------------------------------------------------------------===//
95057
- // DuckDB
95058
- //
95059
- // duckdb/parser/tableref/table_function_ref.hpp
95060
- //
95061
- //
95062
- //===----------------------------------------------------------------------===//
95063
-
95064
-
95065
-
95066
-
95067
-
95068
-
95069
-
95070
-
95071
- namespace duckdb {
95072
- //! Represents a Table producing function
95073
- class TableFunctionRef : public TableRef {
95074
- public:
95075
- TableFunctionRef() : TableRef(TableReferenceType::TABLE_FUNCTION) {
95076
- }
95077
-
95078
- unique_ptr<ParsedExpression> function;
95079
- vector<string> column_name_alias;
95080
-
95081
- // if the function takes a subquery as argument its in here
95082
- unique_ptr<SelectStatement> subquery;
95083
-
95084
- public:
95085
- string ToString() const override;
95086
-
95087
- bool Equals(const TableRef *other_p) const override;
95088
-
95089
- unique_ptr<TableRef> Copy() override;
95090
-
95091
- //! Serializes a blob into a BaseTableRef
95092
- void Serialize(Serializer &serializer) override;
95093
- //! Deserializes a blob back into a BaseTableRef
95094
- static unique_ptr<TableRef> Deserialize(Deserializer &source);
95095
- };
95096
- } // namespace duckdb
95097
91366
 
95098
91367
 
95099
91368
 
@@ -98355,44 +94624,6 @@ public:
98355
94624
  };
98356
94625
  } // namespace duckdb
98357
94626
 
98358
- //===----------------------------------------------------------------------===//
98359
- // DuckDB
98360
- //
98361
- // duckdb/parser/expression/star_expression.hpp
98362
- //
98363
- //
98364
- //===----------------------------------------------------------------------===//
98365
-
98366
-
98367
-
98368
-
98369
-
98370
-
98371
- namespace duckdb {
98372
-
98373
- //! Represents a * expression in the SELECT clause
98374
- class StarExpression : public ParsedExpression {
98375
- public:
98376
- StarExpression(string relation_name = string());
98377
-
98378
- //! The relation name in case of tbl.*, or empty if this is a normal *
98379
- string relation_name;
98380
- //! List of columns to exclude from the STAR expression
98381
- case_insensitive_set_t exclude_list;
98382
- //! List of columns to replace with another expression
98383
- case_insensitive_map_t<unique_ptr<ParsedExpression>> replace_list;
98384
-
98385
- public:
98386
- string ToString() const override;
98387
-
98388
- static bool Equals(const StarExpression *a, const StarExpression *b);
98389
-
98390
- unique_ptr<ParsedExpression> Copy() const override;
98391
-
98392
- void Serialize(Serializer &serializer) override;
98393
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
98394
- };
98395
- } // namespace duckdb
98396
94627
 
98397
94628
 
98398
94629
 
@@ -103276,59 +99507,6 @@ bool Connection::IsAutoCommit() {
103276
99507
 
103277
99508
 
103278
99509
 
103279
- //===----------------------------------------------------------------------===//
103280
- // DuckDB
103281
- //
103282
- // duckdb/storage/object_cache.hpp
103283
- //
103284
- //
103285
- //===----------------------------------------------------------------------===//
103286
-
103287
-
103288
-
103289
-
103290
-
103291
-
103292
-
103293
-
103294
-
103295
-
103296
- namespace duckdb {
103297
- class ClientContext;
103298
-
103299
- //! ObjectCache is the base class for objects caches in DuckDB
103300
- class ObjectCacheEntry {
103301
- public:
103302
- virtual ~ObjectCacheEntry() {
103303
- }
103304
- };
103305
-
103306
- class ObjectCache {
103307
- public:
103308
- shared_ptr<ObjectCacheEntry> Get(string key) {
103309
- lock_guard<mutex> glock(lock);
103310
- auto entry = cache.find(key);
103311
- if (entry == cache.end()) {
103312
- return nullptr;
103313
- }
103314
- return entry->second;
103315
- }
103316
-
103317
- void Put(string key, shared_ptr<ObjectCacheEntry> value) {
103318
- lock_guard<mutex> glock(lock);
103319
- cache[key] = move(value);
103320
- }
103321
-
103322
- static ObjectCache &GetObjectCache(ClientContext &context);
103323
- static bool ObjectCacheEnabled(ClientContext &context);
103324
-
103325
- private:
103326
- //! Object Cache
103327
- unordered_map<string, shared_ptr<ObjectCacheEntry>> cache;
103328
- mutex lock;
103329
- };
103330
-
103331
- } // namespace duckdb
103332
99510
 
103333
99511
 
103334
99512
 
@@ -112689,41 +108867,6 @@ public:
112689
108867
 
112690
108868
 
112691
108869
 
112692
- //===----------------------------------------------------------------------===//
112693
- // DuckDB
112694
- //
112695
- // duckdb/parser/tableref/subqueryref.hpp
112696
- //
112697
- //
112698
- //===----------------------------------------------------------------------===//
112699
-
112700
-
112701
-
112702
-
112703
-
112704
-
112705
- namespace duckdb {
112706
- //! Represents a subquery
112707
- class SubqueryRef : public TableRef {
112708
- public:
112709
- explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
112710
-
112711
- //! The subquery
112712
- unique_ptr<SelectStatement> subquery;
112713
- //! Aliases for the column names
112714
- vector<string> column_name_alias;
112715
-
112716
- public:
112717
- bool Equals(const TableRef *other_p) const override;
112718
-
112719
- unique_ptr<TableRef> Copy() override;
112720
-
112721
- //! Serializes a blob into a SubqueryRef
112722
- void Serialize(Serializer &serializer) override;
112723
- //! Deserializes a blob back into a SubqueryRef
112724
- static unique_ptr<TableRef> Deserialize(Deserializer &source);
112725
- };
112726
- } // namespace duckdb
112727
108870
 
112728
108871
 
112729
108872
  namespace duckdb {
@@ -113315,43 +109458,6 @@ public:
113315
109458
 
113316
109459
  } // namespace duckdb
113317
109460
 
113318
- //===----------------------------------------------------------------------===//
113319
- // DuckDB
113320
- //
113321
- // duckdb/parser/expression/conjunction_expression.hpp
113322
- //
113323
- //
113324
- //===----------------------------------------------------------------------===//
113325
-
113326
-
113327
-
113328
-
113329
-
113330
-
113331
- namespace duckdb {
113332
-
113333
- //! Represents a conjunction (AND/OR)
113334
- class ConjunctionExpression : public ParsedExpression {
113335
- public:
113336
- explicit ConjunctionExpression(ExpressionType type);
113337
- ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
113338
- ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left, unique_ptr<ParsedExpression> right);
113339
-
113340
- vector<unique_ptr<ParsedExpression>> children;
113341
-
113342
- public:
113343
- void AddExpression(unique_ptr<ParsedExpression> expr);
113344
-
113345
- string ToString() const override;
113346
-
113347
- static bool Equals(const ConjunctionExpression *a, const ConjunctionExpression *b);
113348
-
113349
- unique_ptr<ParsedExpression> Copy() const override;
113350
-
113351
- void Serialize(Serializer &serializer) override;
113352
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
113353
- };
113354
- } // namespace duckdb
113355
109461
 
113356
109462
 
113357
109463
 
@@ -113547,53 +109653,6 @@ public:
113547
109653
 
113548
109654
 
113549
109655
 
113550
- //===----------------------------------------------------------------------===//
113551
- // DuckDB
113552
- //
113553
- // duckdb/parser/tableref/joinref.hpp
113554
- //
113555
- //
113556
- //===----------------------------------------------------------------------===//
113557
-
113558
-
113559
-
113560
-
113561
-
113562
-
113563
-
113564
-
113565
-
113566
- namespace duckdb {
113567
- //! Represents a JOIN between two expressions
113568
- class JoinRef : public TableRef {
113569
- public:
113570
- JoinRef() : TableRef(TableReferenceType::JOIN), is_natural(false) {
113571
- }
113572
-
113573
- //! The left hand side of the join
113574
- unique_ptr<TableRef> left;
113575
- //! The right hand side of the join
113576
- unique_ptr<TableRef> right;
113577
- //! The join condition
113578
- unique_ptr<ParsedExpression> condition;
113579
- //! The join type
113580
- JoinType type;
113581
- //! Natural join
113582
- bool is_natural;
113583
- //! The set of USING columns (if any)
113584
- vector<string> using_columns;
113585
-
113586
- public:
113587
- bool Equals(const TableRef *other_p) const override;
113588
-
113589
- unique_ptr<TableRef> Copy() override;
113590
-
113591
- //! Serializes a blob into a JoinRef
113592
- void Serialize(Serializer &serializer) override;
113593
- //! Deserializes a blob back into a JoinRef
113594
- static unique_ptr<TableRef> Deserialize(Deserializer &source);
113595
- };
113596
- } // namespace duckdb
113597
109656
 
113598
109657
 
113599
109658
  namespace duckdb {
@@ -114189,55 +110248,6 @@ string SubqueryRelation::ToString(idx_t depth) {
114189
110248
 
114190
110249
 
114191
110250
 
114192
- //===----------------------------------------------------------------------===//
114193
- // DuckDB
114194
- //
114195
- // duckdb/parser/expression/subquery_expression.hpp
114196
- //
114197
- //
114198
- //===----------------------------------------------------------------------===//
114199
-
114200
-
114201
-
114202
-
114203
-
114204
-
114205
-
114206
- namespace duckdb {
114207
-
114208
- //! Represents a subquery
114209
- class SubqueryExpression : public ParsedExpression {
114210
- public:
114211
- SubqueryExpression();
114212
-
114213
- //! The actual subquery
114214
- unique_ptr<SelectStatement> subquery;
114215
- //! The subquery type
114216
- SubqueryType subquery_type;
114217
- //! the child expression to compare with (in case of IN, ANY, ALL operators, empty for EXISTS queries and scalar
114218
- //! subquery)
114219
- unique_ptr<ParsedExpression> child;
114220
- //! The comparison type of the child expression with the subquery (in case of ANY, ALL operators), empty otherwise
114221
- ExpressionType comparison_type;
114222
-
114223
- public:
114224
- bool HasSubquery() const override {
114225
- return true;
114226
- }
114227
- bool IsScalar() const override {
114228
- return false;
114229
- }
114230
-
114231
- string ToString() const override;
114232
-
114233
- static bool Equals(const SubqueryExpression *a, const SubqueryExpression *b);
114234
-
114235
- unique_ptr<ParsedExpression> Copy() const override;
114236
-
114237
- void Serialize(Serializer &serializer) override;
114238
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
114239
- };
114240
- } // namespace duckdb
114241
110251
 
114242
110252
 
114243
110253
 
@@ -114507,46 +110517,6 @@ string UpdateRelation::ToString(idx_t depth) {
114507
110517
 
114508
110518
 
114509
110519
 
114510
- //===----------------------------------------------------------------------===//
114511
- // DuckDB
114512
- //
114513
- // duckdb/parser/tableref/expressionlistref.hpp
114514
- //
114515
- //
114516
- //===----------------------------------------------------------------------===//
114517
-
114518
-
114519
-
114520
-
114521
-
114522
-
114523
-
114524
-
114525
- namespace duckdb {
114526
- //! Represents an expression list as generated by a VALUES statement
114527
- class ExpressionListRef : public TableRef {
114528
- public:
114529
- ExpressionListRef() : TableRef(TableReferenceType::EXPRESSION_LIST) {
114530
- }
114531
-
114532
- //! Value list, only used for VALUES statement
114533
- vector<vector<unique_ptr<ParsedExpression>>> values;
114534
- //! Expected SQL types
114535
- vector<LogicalType> expected_types;
114536
- //! The set of expected names
114537
- vector<string> expected_names;
114538
-
114539
- public:
114540
- bool Equals(const TableRef *other_p) const override;
114541
-
114542
- unique_ptr<TableRef> Copy() override;
114543
-
114544
- //! Serializes a blob into a ExpressionListRef
114545
- void Serialize(Serializer &serializer) override;
114546
- //! Deserializes a blob back into a ExpressionListRef
114547
- static unique_ptr<TableRef> Deserialize(Deserializer &source);
114548
- };
114549
- } // namespace duckdb
114550
110520
 
114551
110521
 
114552
110522
 
@@ -116917,76 +112887,11 @@ private:
116917
112887
 
116918
112888
 
116919
112889
 
116920
- //===----------------------------------------------------------------------===//
116921
- // DuckDB
116922
- //
116923
- // duckdb/planner/filter/constant_filter.hpp
116924
- //
116925
- //
116926
- //===----------------------------------------------------------------------===//
116927
-
116928
-
116929
112890
 
116930
112891
 
116931
112892
 
116932
112893
 
116933
112894
 
116934
- namespace duckdb {
116935
-
116936
- class ConstantFilter : public TableFilter {
116937
- public:
116938
- ConstantFilter(ExpressionType comparison_type, Value constant);
116939
-
116940
- //! The comparison type (e.g. COMPARE_EQUAL, COMPARE_GREATERTHAN, COMPARE_LESSTHAN, ...)
116941
- ExpressionType comparison_type;
116942
- //! The constant value to filter on
116943
- Value constant;
116944
-
116945
- public:
116946
- FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
116947
- string ToString(const string &column_name) override;
116948
- bool Equals(const TableFilter &other) const override;
116949
- };
116950
-
116951
- } // namespace duckdb
116952
-
116953
- //===----------------------------------------------------------------------===//
116954
- // DuckDB
116955
- //
116956
- // duckdb/planner/filter/null_filter.hpp
116957
- //
116958
- //
116959
- //===----------------------------------------------------------------------===//
116960
-
116961
-
116962
-
116963
-
116964
-
116965
- namespace duckdb {
116966
-
116967
- class IsNullFilter : public TableFilter {
116968
- public:
116969
- IsNullFilter();
116970
-
116971
- public:
116972
- FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
116973
- string ToString(const string &column_name) override;
116974
- };
116975
-
116976
- class IsNotNullFilter : public TableFilter {
116977
- public:
116978
- IsNotNullFilter();
116979
-
116980
- public:
116981
- FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
116982
- string ToString(const string &column_name) override;
116983
- };
116984
-
116985
- } // namespace duckdb
116986
-
116987
-
116988
-
116989
-
116990
112895
  namespace duckdb {
116991
112896
 
116992
112897
  using ExpressionValueInformation = FilterCombiner::ExpressionValueInformation;
@@ -123689,48 +119594,6 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalFilt
123689
119594
 
123690
119595
  } // namespace duckdb
123691
119596
 
123692
- //===----------------------------------------------------------------------===//
123693
- // DuckDB
123694
- //
123695
- // duckdb/planner/filter/conjunction_filter.hpp
123696
- //
123697
- //
123698
- //===----------------------------------------------------------------------===//
123699
-
123700
-
123701
-
123702
-
123703
-
123704
-
123705
- namespace duckdb {
123706
-
123707
- class ConjunctionOrFilter : public TableFilter {
123708
- public:
123709
- ConjunctionOrFilter();
123710
-
123711
- //! The filters to OR together
123712
- vector<unique_ptr<TableFilter>> child_filters;
123713
-
123714
- public:
123715
- FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
123716
- string ToString(const string &column_name) override;
123717
- bool Equals(const TableFilter &other) const override;
123718
- };
123719
-
123720
- class ConjunctionAndFilter : public TableFilter {
123721
- public:
123722
- ConjunctionAndFilter();
123723
-
123724
- //! The filters to OR together
123725
- vector<unique_ptr<TableFilter>> child_filters;
123726
-
123727
- public:
123728
- FilterPropagateResult CheckStatistics(BaseStatistics &stats) override;
123729
- string ToString(const string &column_name) override;
123730
- bool Equals(const TableFilter &other) const override;
123731
- };
123732
-
123733
- } // namespace duckdb
123734
119597
 
123735
119598
 
123736
119599
 
@@ -130489,40 +126352,6 @@ unique_ptr<Constraint> UniqueConstraint::Deserialize(Deserializer &source) {
130489
126352
  }
130490
126353
 
130491
126354
  } // namespace duckdb
130492
- //===----------------------------------------------------------------------===//
130493
- // DuckDB
130494
- //
130495
- // duckdb/parser/expression/between_expression.hpp
130496
- //
130497
- //
130498
- //===----------------------------------------------------------------------===//
130499
-
130500
-
130501
-
130502
-
130503
-
130504
- namespace duckdb {
130505
-
130506
- class BetweenExpression : public ParsedExpression {
130507
- public:
130508
- BetweenExpression(unique_ptr<ParsedExpression> input, unique_ptr<ParsedExpression> lower,
130509
- unique_ptr<ParsedExpression> upper);
130510
-
130511
- unique_ptr<ParsedExpression> input;
130512
- unique_ptr<ParsedExpression> lower;
130513
- unique_ptr<ParsedExpression> upper;
130514
-
130515
- public:
130516
- string ToString() const override;
130517
-
130518
- static bool Equals(const BetweenExpression *a, const BetweenExpression *b);
130519
-
130520
- unique_ptr<ParsedExpression> Copy() const override;
130521
-
130522
- void Serialize(Serializer &serializer) override;
130523
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
130524
- };
130525
- } // namespace duckdb
130526
126355
 
130527
126356
 
130528
126357
  namespace duckdb {
@@ -130570,50 +126399,11 @@ unique_ptr<ParsedExpression> BetweenExpression::Deserialize(ExpressionType type,
130570
126399
  return make_unique<BetweenExpression>(move(input), move(lower), move(upper));
130571
126400
  }
130572
126401
 
130573
- } // namespace duckdb//===----------------------------------------------------------------------===//
130574
- // DuckDB
130575
- //
130576
- // duckdb/parser/expression/case_expression.hpp
130577
- //
130578
- //
130579
- //===----------------------------------------------------------------------===//
130580
-
130581
-
130582
-
130583
-
130584
-
130585
-
130586
- namespace duckdb {
130587
-
130588
- struct CaseCheck {
130589
- unique_ptr<ParsedExpression> when_expr;
130590
- unique_ptr<ParsedExpression> then_expr;
130591
- };
130592
-
130593
- //! The CaseExpression represents a CASE expression in the query
130594
- class CaseExpression : public ParsedExpression {
130595
- public:
130596
- CaseExpression();
130597
-
130598
- vector<CaseCheck> case_checks;
130599
- unique_ptr<ParsedExpression> else_expr;
130600
-
130601
- public:
130602
- string ToString() const override;
130603
-
130604
- static bool Equals(const CaseExpression *a, const CaseExpression *b);
130605
-
130606
- unique_ptr<ParsedExpression> Copy() const override;
130607
-
130608
- void Serialize(Serializer &serializer) override;
130609
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
130610
- };
130611
126402
  } // namespace duckdb
130612
126403
 
130613
126404
 
130614
126405
 
130615
126406
 
130616
-
130617
126407
  namespace duckdb {
130618
126408
 
130619
126409
  CaseExpression::CaseExpression() : ParsedExpression(ExpressionType::CASE_EXPR, ExpressionClass::CASE) {
@@ -130684,44 +126474,6 @@ unique_ptr<ParsedExpression> CaseExpression::Deserialize(ExpressionType type, De
130684
126474
  }
130685
126475
 
130686
126476
  } // namespace duckdb
130687
- //===----------------------------------------------------------------------===//
130688
- // DuckDB
130689
- //
130690
- // duckdb/parser/expression/cast_expression.hpp
130691
- //
130692
- //
130693
- //===----------------------------------------------------------------------===//
130694
-
130695
-
130696
-
130697
-
130698
-
130699
-
130700
- namespace duckdb {
130701
-
130702
- //! CastExpression represents a type cast from one SQL type to another SQL type
130703
- class CastExpression : public ParsedExpression {
130704
- public:
130705
- CastExpression(LogicalType target, unique_ptr<ParsedExpression> child, bool try_cast = false);
130706
-
130707
- //! The child of the cast expression
130708
- unique_ptr<ParsedExpression> child;
130709
- //! The type to cast to
130710
- LogicalType cast_type;
130711
- //! Whether or not this is a try_cast expression
130712
- bool try_cast;
130713
-
130714
- public:
130715
- string ToString() const override;
130716
-
130717
- static bool Equals(const CastExpression *a, const CastExpression *b);
130718
-
130719
- unique_ptr<ParsedExpression> Copy() const override;
130720
-
130721
- void Serialize(Serializer &serializer) override;
130722
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
130723
- };
130724
- } // namespace duckdb
130725
126477
 
130726
126478
 
130727
126479
 
@@ -130774,41 +126526,6 @@ unique_ptr<ParsedExpression> CastExpression::Deserialize(ExpressionType type, De
130774
126526
  }
130775
126527
 
130776
126528
  } // namespace duckdb
130777
- //===----------------------------------------------------------------------===//
130778
- // DuckDB
130779
- //
130780
- // duckdb/parser/expression/collate_expression.hpp
130781
- //
130782
- //
130783
- //===----------------------------------------------------------------------===//
130784
-
130785
-
130786
-
130787
-
130788
-
130789
- namespace duckdb {
130790
-
130791
- //! CollateExpression represents a COLLATE statement
130792
- class CollateExpression : public ParsedExpression {
130793
- public:
130794
- CollateExpression(string collation, unique_ptr<ParsedExpression> child);
130795
-
130796
- //! The child of the cast expression
130797
- unique_ptr<ParsedExpression> child;
130798
- //! The collation clause
130799
- string collation;
130800
-
130801
- public:
130802
- string ToString() const override;
130803
-
130804
- static bool Equals(const CollateExpression *a, const CollateExpression *b);
130805
-
130806
- unique_ptr<ParsedExpression> Copy() const override;
130807
-
130808
- void Serialize(Serializer &serializer) override;
130809
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
130810
- };
130811
- } // namespace duckdb
130812
126529
 
130813
126530
 
130814
126531
 
@@ -131141,36 +126858,6 @@ unique_ptr<ParsedExpression> ConstantExpression::Deserialize(ExpressionType type
131141
126858
  }
131142
126859
 
131143
126860
  } // namespace duckdb
131144
- //===----------------------------------------------------------------------===//
131145
- // DuckDB
131146
- //
131147
- // duckdb/parser/expression/default_expression.hpp
131148
- //
131149
- //
131150
- //===----------------------------------------------------------------------===//
131151
-
131152
-
131153
-
131154
-
131155
-
131156
- namespace duckdb {
131157
- //! Represents the default value of a column
131158
- class DefaultExpression : public ParsedExpression {
131159
- public:
131160
- DefaultExpression();
131161
-
131162
- public:
131163
- bool IsScalar() const override {
131164
- return false;
131165
- }
131166
-
131167
- string ToString() const override;
131168
-
131169
- unique_ptr<ParsedExpression> Copy() const override;
131170
-
131171
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
131172
- };
131173
- } // namespace duckdb
131174
126861
 
131175
126862
 
131176
126863
 
@@ -131332,43 +127019,6 @@ unique_ptr<ParsedExpression> FunctionExpression::Deserialize(ExpressionType type
131332
127019
  }
131333
127020
 
131334
127021
  } // namespace duckdb
131335
- //===----------------------------------------------------------------------===//
131336
- // DuckDB
131337
- //
131338
- // duckdb/parser/expression/lambda_expression.hpp
131339
- //
131340
- //
131341
- //===----------------------------------------------------------------------===//
131342
-
131343
-
131344
-
131345
-
131346
-
131347
-
131348
- namespace duckdb {
131349
-
131350
- //! LambdaExpression represents a lambda operator that can be used for e.g. mapping an expression to a list
131351
- //! Lambda expressions are written in the form of "capture -> expr", e.g. "x -> x + 1"
131352
- class LambdaExpression : public ParsedExpression {
131353
- public:
131354
- LambdaExpression(vector<string> parameters, unique_ptr<ParsedExpression> expression);
131355
-
131356
- vector<string> parameters;
131357
- unique_ptr<ParsedExpression> expression;
131358
-
131359
- public:
131360
- string ToString() const override;
131361
-
131362
- static bool Equals(const LambdaExpression *a, const LambdaExpression *b);
131363
- hash_t Hash() const override;
131364
-
131365
- unique_ptr<ParsedExpression> Copy() const override;
131366
-
131367
- void Serialize(Serializer &serializer) override;
131368
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
131369
- };
131370
-
131371
- } // namespace duckdb
131372
127022
 
131373
127023
 
131374
127024
 
@@ -131442,40 +127092,6 @@ unique_ptr<ParsedExpression> LambdaExpression::Deserialize(ExpressionType type,
131442
127092
  }
131443
127093
 
131444
127094
  } // namespace duckdb
131445
- //===----------------------------------------------------------------------===//
131446
- // DuckDB
131447
- //
131448
- // duckdb/parser/expression/operator_expression.hpp
131449
- //
131450
- //
131451
- //===----------------------------------------------------------------------===//
131452
-
131453
-
131454
-
131455
-
131456
-
131457
-
131458
- namespace duckdb {
131459
- //! Represents a built-in operator expression
131460
- class OperatorExpression : public ParsedExpression {
131461
- public:
131462
- explicit OperatorExpression(ExpressionType type, unique_ptr<ParsedExpression> left = nullptr,
131463
- unique_ptr<ParsedExpression> right = nullptr);
131464
- OperatorExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
131465
-
131466
- vector<unique_ptr<ParsedExpression>> children;
131467
-
131468
- public:
131469
- string ToString() const override;
131470
-
131471
- static bool Equals(const OperatorExpression *a, const OperatorExpression *b);
131472
-
131473
- unique_ptr<ParsedExpression> Copy() const override;
131474
-
131475
- void Serialize(Serializer &serializer) override;
131476
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
131477
- };
131478
- } // namespace duckdb
131479
127095
 
131480
127096
 
131481
127097
 
@@ -131550,42 +127166,6 @@ unique_ptr<ParsedExpression> OperatorExpression::Deserialize(ExpressionType type
131550
127166
  }
131551
127167
 
131552
127168
  } // namespace duckdb
131553
- //===----------------------------------------------------------------------===//
131554
- // DuckDB
131555
- //
131556
- // duckdb/parser/expression/parameter_expression.hpp
131557
- //
131558
- //
131559
- //===----------------------------------------------------------------------===//
131560
-
131561
-
131562
-
131563
-
131564
-
131565
- namespace duckdb {
131566
- class ParameterExpression : public ParsedExpression {
131567
- public:
131568
- ParameterExpression();
131569
-
131570
- idx_t parameter_nr;
131571
-
131572
- public:
131573
- bool IsScalar() const override {
131574
- return true;
131575
- }
131576
- bool HasParameter() const override {
131577
- return true;
131578
- }
131579
-
131580
- string ToString() const override;
131581
-
131582
- unique_ptr<ParsedExpression> Copy() const override;
131583
- hash_t Hash() const override;
131584
-
131585
- void Serialize(Serializer &serializer) override;
131586
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
131587
- };
131588
- } // namespace duckdb
131589
127169
 
131590
127170
 
131591
127171
 
@@ -131627,40 +127207,6 @@ unique_ptr<ParsedExpression> ParameterExpression::Deserialize(ExpressionType typ
131627
127207
  }
131628
127208
 
131629
127209
  } // namespace duckdb
131630
- //===----------------------------------------------------------------------===//
131631
- // DuckDB
131632
- //
131633
- // duckdb/parser/expression/positional_reference_expression.hpp
131634
- //
131635
- //
131636
- //===----------------------------------------------------------------------===//
131637
-
131638
-
131639
-
131640
-
131641
-
131642
- namespace duckdb {
131643
- class PositionalReferenceExpression : public ParsedExpression {
131644
- public:
131645
- PositionalReferenceExpression(idx_t index);
131646
-
131647
- idx_t index;
131648
-
131649
- public:
131650
- bool IsScalar() const override {
131651
- return false;
131652
- }
131653
-
131654
- string ToString() const override;
131655
-
131656
- static bool Equals(const PositionalReferenceExpression *a, const PositionalReferenceExpression *b);
131657
- unique_ptr<ParsedExpression> Copy() const override;
131658
- hash_t Hash() const override;
131659
-
131660
- void Serialize(Serializer &serializer) override;
131661
- static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, Deserializer &source);
131662
- };
131663
- } // namespace duckdb
131664
127210
 
131665
127211
 
131666
127212
 
@@ -132524,24 +128070,6 @@ bool SampleOptions::Equals(SampleOptions *a, SampleOptions *b) {
132524
128070
 
132525
128071
 
132526
128072
 
132527
-
132528
-
132529
-
132530
-
132531
-
132532
-
132533
-
132534
-
132535
-
132536
-
132537
-
132538
-
132539
-
132540
-
132541
-
132542
-
132543
-
132544
-
132545
128073
 
132546
128074
 
132547
128075
 
@@ -132762,78 +128290,6 @@ public:
132762
128290
 
132763
128291
 
132764
128292
 
132765
- //===----------------------------------------------------------------------===//
132766
- // DuckDB
132767
- //
132768
- // duckdb/parser/tableref/crossproductref.hpp
132769
- //
132770
- //
132771
- //===----------------------------------------------------------------------===//
132772
-
132773
-
132774
-
132775
-
132776
-
132777
- namespace duckdb {
132778
- //! Represents a cross product
132779
- class CrossProductRef : public TableRef {
132780
- public:
132781
- CrossProductRef() : TableRef(TableReferenceType::CROSS_PRODUCT) {
132782
- }
132783
-
132784
- //! The left hand side of the cross product
132785
- unique_ptr<TableRef> left;
132786
- //! The right hand side of the cross product
132787
- unique_ptr<TableRef> right;
132788
-
132789
- public:
132790
- bool Equals(const TableRef *other_p) const override;
132791
-
132792
- unique_ptr<TableRef> Copy() override;
132793
-
132794
- //! Serializes a blob into a CrossProductRef
132795
- void Serialize(Serializer &serializer) override;
132796
- //! Deserializes a blob back into a CrossProductRef
132797
- static unique_ptr<TableRef> Deserialize(Deserializer &source);
132798
- };
132799
- } // namespace duckdb
132800
-
132801
- //===----------------------------------------------------------------------===//
132802
- // DuckDB
132803
- //
132804
- // duckdb/parser/tableref/emptytableref.hpp
132805
- //
132806
- //
132807
- //===----------------------------------------------------------------------===//
132808
-
132809
-
132810
-
132811
-
132812
-
132813
- namespace duckdb {
132814
- //! Represents a cross product
132815
- class EmptyTableRef : public TableRef {
132816
- public:
132817
- EmptyTableRef() : TableRef(TableReferenceType::EMPTY) {
132818
- }
132819
-
132820
- public:
132821
- bool Equals(const TableRef *other_p) const override;
132822
-
132823
- unique_ptr<TableRef> Copy() override;
132824
-
132825
- //! Serializes a blob into a DummyTableRef
132826
- void Serialize(Serializer &serializer) override;
132827
- //! Deserializes a blob back into a DummyTableRef
132828
- static unique_ptr<TableRef> Deserialize(Deserializer &source);
132829
- };
132830
- } // namespace duckdb
132831
-
132832
-
132833
-
132834
-
132835
-
132836
-
132837
128293
 
132838
128294
  namespace duckdb {
132839
128295
 
@@ -155330,6 +150786,33 @@ void LogicalJoin::GetExpressionBindings(Expression &expr, unordered_set<idx_t> &
155330
150786
  } // namespace duckdb
155331
150787
 
155332
150788
 
150789
+ namespace duckdb {
150790
+
150791
+ LogicalLimit::LogicalLimit(int64_t limit_val, int64_t offset_val, unique_ptr<Expression> limit,
150792
+ unique_ptr<Expression> offset)
150793
+ : LogicalOperator(LogicalOperatorType::LOGICAL_LIMIT), limit_val(limit_val), offset_val(offset_val),
150794
+ limit(move(limit)), offset(move(offset)) {
150795
+ }
150796
+
150797
+ vector<ColumnBinding> LogicalLimit::GetColumnBindings() {
150798
+ return children[0]->GetColumnBindings();
150799
+ }
150800
+
150801
+ idx_t LogicalLimit::EstimateCardinality(ClientContext &context) {
150802
+ auto child_cardinality = children[0]->EstimateCardinality(context);
150803
+ if (limit_val >= 0 && idx_t(limit_val) < child_cardinality) {
150804
+ child_cardinality = limit_val;
150805
+ }
150806
+ return child_cardinality;
150807
+ }
150808
+
150809
+ void LogicalLimit::ResolveTypes() {
150810
+ types = children[0]->types;
150811
+ }
150812
+
150813
+ } // namespace duckdb
150814
+
150815
+
155333
150816
  namespace duckdb {
155334
150817
 
155335
150818
  LogicalProjection::LogicalProjection(idx_t table_index, vector<unique_ptr<Expression>> select_list)
@@ -155349,6 +150832,37 @@ void LogicalProjection::ResolveTypes() {
155349
150832
  } // namespace duckdb
155350
150833
 
155351
150834
 
150835
+ namespace duckdb {
150836
+
150837
+ LogicalSample::LogicalSample(unique_ptr<SampleOptions> sample_options_p, unique_ptr<LogicalOperator> child)
150838
+ : LogicalOperator(LogicalOperatorType::LOGICAL_SAMPLE), sample_options(move(sample_options_p)) {
150839
+ children.push_back(move(child));
150840
+ }
150841
+
150842
+ vector<ColumnBinding> LogicalSample::GetColumnBindings() {
150843
+ return children[0]->GetColumnBindings();
150844
+ }
150845
+
150846
+ idx_t LogicalSample::EstimateCardinality(ClientContext &context) {
150847
+ auto child_cardinality = children[0]->EstimateCardinality(context);
150848
+ if (sample_options->is_percentage) {
150849
+ return idx_t(child_cardinality * sample_options->sample_size.GetValue<double>());
150850
+ } else {
150851
+ auto sample_size = sample_options->sample_size.GetValue<uint64_t>();
150852
+ if (sample_size < child_cardinality) {
150853
+ return sample_size;
150854
+ }
150855
+ }
150856
+ return child_cardinality;
150857
+ }
150858
+
150859
+ void LogicalSample::ResolveTypes() {
150860
+ types = children[0]->types;
150861
+ }
150862
+
150863
+ } // namespace duckdb
150864
+
150865
+
155352
150866
  namespace duckdb {
155353
150867
 
155354
150868
  vector<ColumnBinding> LogicalUnnest::GetColumnBindings() {