duckdb 0.3.1-dev8.0 → 0.3.2-dev121.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/package.json +1 -1
- package/src/duckdb.cpp +28611 -21552
- package/src/duckdb.hpp +742 -290
package/src/duckdb.hpp
CHANGED
|
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
10
10
|
|
|
11
11
|
#pragma once
|
|
12
12
|
#define DUCKDB_AMALGAMATION 1
|
|
13
|
-
#define DUCKDB_SOURCE_ID "
|
|
14
|
-
#define DUCKDB_VERSION "0.3.
|
|
13
|
+
#define DUCKDB_SOURCE_ID "3c9727ac2"
|
|
14
|
+
#define DUCKDB_VERSION "0.3.2-dev121"
|
|
15
15
|
//===----------------------------------------------------------------------===//
|
|
16
16
|
// DuckDB
|
|
17
17
|
//
|
|
@@ -567,11 +567,13 @@ using std::vector;
|
|
|
567
567
|
#endif
|
|
568
568
|
|
|
569
569
|
|
|
570
|
+
|
|
570
571
|
namespace duckdb {
|
|
571
572
|
|
|
572
573
|
class Serializer;
|
|
573
574
|
class Deserializer;
|
|
574
|
-
|
|
575
|
+
class Value;
|
|
576
|
+
class TypeCatalogEntry;
|
|
575
577
|
//! Type used to represent dates (days since 1970-01-01)
|
|
576
578
|
struct date_t {
|
|
577
579
|
int32_t days;
|
|
@@ -861,12 +863,12 @@ enum class PhysicalType : uint8_t {
|
|
|
861
863
|
/// Like LIST, but with 64-bit offsets
|
|
862
864
|
LARGE_LIST = 33,
|
|
863
865
|
|
|
864
|
-
|
|
866
|
+
/// DuckDB Extensions
|
|
865
867
|
VARCHAR = 200, // our own string representation, different from STRING and LARGE_STRING above
|
|
866
868
|
INT128 = 204, // 128-bit integers
|
|
867
|
-
|
|
869
|
+
UNKNOWN = 205, // Unknown physical type of user defined types
|
|
868
870
|
/// Boolean as 1 bit, LSB bit-packed ordering
|
|
869
|
-
BIT =
|
|
871
|
+
BIT = 206,
|
|
870
872
|
|
|
871
873
|
INVALID = 255
|
|
872
874
|
};
|
|
@@ -879,7 +881,7 @@ enum class LogicalTypeId : uint8_t {
|
|
|
879
881
|
SQLNULL = 1, /* NULL type, used for constant NULL */
|
|
880
882
|
UNKNOWN = 2, /* unknown type, used for parameter expressions */
|
|
881
883
|
ANY = 3, /* ANY type, used for functions that accept any type as parameter */
|
|
882
|
-
|
|
884
|
+
USER = 4, /* A User Defined Type (e.g., ENUMs before the binder) */
|
|
883
885
|
BOOLEAN = 10,
|
|
884
886
|
TINYINT = 11,
|
|
885
887
|
SMALLINT = 12,
|
|
@@ -913,7 +915,8 @@ enum class LogicalTypeId : uint8_t {
|
|
|
913
915
|
STRUCT = 100,
|
|
914
916
|
LIST = 101,
|
|
915
917
|
MAP = 102,
|
|
916
|
-
TABLE = 103
|
|
918
|
+
TABLE = 103,
|
|
919
|
+
ENUM = 104
|
|
917
920
|
};
|
|
918
921
|
|
|
919
922
|
struct ExtraTypeInfo;
|
|
@@ -922,6 +925,7 @@ struct LogicalType {
|
|
|
922
925
|
DUCKDB_API LogicalType();
|
|
923
926
|
DUCKDB_API LogicalType(LogicalTypeId id); // NOLINT: Allow implicit conversion from `LogicalTypeId`
|
|
924
927
|
DUCKDB_API LogicalType(LogicalTypeId id, shared_ptr<ExtraTypeInfo> type_info);
|
|
928
|
+
|
|
925
929
|
DUCKDB_API LogicalType(const LogicalType &other) :
|
|
926
930
|
id_(other.id_), physical_type_(other.physical_type_), type_info_(other.type_info_) {}
|
|
927
931
|
|
|
@@ -1018,10 +1022,11 @@ public:
|
|
|
1018
1022
|
// explicitly allowing these functions to be capitalized to be in-line with the remaining functions
|
|
1019
1023
|
DUCKDB_API static LogicalType DECIMAL(int width, int scale); // NOLINT
|
|
1020
1024
|
DUCKDB_API static LogicalType VARCHAR_COLLATION(string collation); // NOLINT
|
|
1021
|
-
DUCKDB_API static LogicalType LIST(LogicalType child); // NOLINT
|
|
1022
|
-
DUCKDB_API static LogicalType STRUCT(child_list_t<LogicalType> children); // NOLINT
|
|
1023
|
-
DUCKDB_API static LogicalType MAP(child_list_t<LogicalType> children); // NOLINT
|
|
1024
|
-
|
|
1025
|
+
DUCKDB_API static LogicalType LIST( LogicalType child); // NOLINT
|
|
1026
|
+
DUCKDB_API static LogicalType STRUCT( child_list_t<LogicalType> children); // NOLINT
|
|
1027
|
+
DUCKDB_API static LogicalType MAP( child_list_t<LogicalType> children); // NOLINT
|
|
1028
|
+
DUCKDB_API static LogicalType ENUM(const string &enum_name, const vector<string> &ordered_data); // NOLINT
|
|
1029
|
+
DUCKDB_API static LogicalType USER(const string &user_type_name); // NOLINT
|
|
1025
1030
|
//! A list of all NUMERIC types (integral and floating point types)
|
|
1026
1031
|
DUCKDB_API static const vector<LogicalType> NUMERIC;
|
|
1027
1032
|
//! A list of all INTEGRAL types
|
|
@@ -1043,6 +1048,21 @@ struct ListType {
|
|
|
1043
1048
|
DUCKDB_API static const LogicalType &GetChildType(const LogicalType &type);
|
|
1044
1049
|
};
|
|
1045
1050
|
|
|
1051
|
+
struct UserType{
|
|
1052
|
+
DUCKDB_API static const string &GetTypeName(const LogicalType &type);
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1055
|
+
struct EnumType{
|
|
1056
|
+
DUCKDB_API static const string &GetTypeName(const LogicalType &type);
|
|
1057
|
+
DUCKDB_API static int64_t GetPos(const LogicalType &type, const string& key);
|
|
1058
|
+
DUCKDB_API static const vector<string> &GetValuesInsertOrder(const LogicalType &type);
|
|
1059
|
+
DUCKDB_API static idx_t GetSize(const LogicalType &type);
|
|
1060
|
+
DUCKDB_API static const string& GetValue(const Value &val);
|
|
1061
|
+
DUCKDB_API static void SetCatalog(LogicalType &type, TypeCatalogEntry* catalog_entry);
|
|
1062
|
+
DUCKDB_API static TypeCatalogEntry* GetCatalog(const LogicalType &type);
|
|
1063
|
+
DUCKDB_API static PhysicalType GetPhysicalType(idx_t size);
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1046
1066
|
struct StructType {
|
|
1047
1067
|
DUCKDB_API static const child_list_t<LogicalType> &GetChildTypes(const LogicalType &type);
|
|
1048
1068
|
DUCKDB_API static const LogicalType &GetChildType(const LogicalType &type, idx_t index);
|
|
@@ -1497,7 +1517,7 @@ public:
|
|
|
1497
1517
|
//! Write a string with a length prefix
|
|
1498
1518
|
void WriteString(const string &val) {
|
|
1499
1519
|
Write<uint32_t>((uint32_t)val.size());
|
|
1500
|
-
if (val.
|
|
1520
|
+
if (!val.empty()) {
|
|
1501
1521
|
WriteData((const_data_ptr_t)val.c_str(), val.size());
|
|
1502
1522
|
}
|
|
1503
1523
|
}
|
|
@@ -1903,6 +1923,7 @@ public:
|
|
|
1903
1923
|
FileOpener *opener = nullptr);
|
|
1904
1924
|
|
|
1905
1925
|
FileSystem &fs;
|
|
1926
|
+
string path;
|
|
1906
1927
|
unique_ptr<data_t[]> data;
|
|
1907
1928
|
idx_t offset;
|
|
1908
1929
|
idx_t total_written;
|
|
@@ -2113,6 +2134,9 @@ public:
|
|
|
2113
2134
|
sel_t *data() {
|
|
2114
2135
|
return sel_vector;
|
|
2115
2136
|
}
|
|
2137
|
+
const sel_t *data() const {
|
|
2138
|
+
return sel_vector;
|
|
2139
|
+
}
|
|
2116
2140
|
buffer_ptr<SelectionData> sel_data() {
|
|
2117
2141
|
return selection_data;
|
|
2118
2142
|
}
|
|
@@ -2568,6 +2592,9 @@ public:
|
|
|
2568
2592
|
DUCKDB_API static Value INTERVAL(int32_t months, int32_t days, int64_t micros);
|
|
2569
2593
|
DUCKDB_API static Value INTERVAL(interval_t interval);
|
|
2570
2594
|
|
|
2595
|
+
// Create a enum Value from a specified uint value
|
|
2596
|
+
DUCKDB_API static Value ENUM(uint64_t value, const LogicalType &original_type);
|
|
2597
|
+
|
|
2571
2598
|
// Decimal values
|
|
2572
2599
|
DUCKDB_API static Value DECIMAL(int16_t value, uint8_t width, uint8_t scale);
|
|
2573
2600
|
DUCKDB_API static Value DECIMAL(int32_t value, uint8_t width, uint8_t scale);
|
|
@@ -3293,6 +3320,9 @@ public:
|
|
|
3293
3320
|
//! Without changing the type of this vector
|
|
3294
3321
|
void Reinterpret(Vector &other);
|
|
3295
3322
|
|
|
3323
|
+
//! Causes this vector to reference the data held by the other vector, changes the type if required.
|
|
3324
|
+
void ReferenceAndSetType(Vector &other);
|
|
3325
|
+
|
|
3296
3326
|
//! Resets a vector from a vector cache.
|
|
3297
3327
|
//! This turns the vector back into an empty FlatVector with STANDARD_VECTOR_SIZE entries.
|
|
3298
3328
|
//! The VectorCache is used so this can be done without requiring any allocations.
|
|
@@ -3631,12 +3661,15 @@ public:
|
|
|
3631
3661
|
return data.size();
|
|
3632
3662
|
}
|
|
3633
3663
|
void SetCardinality(idx_t count_p) {
|
|
3634
|
-
D_ASSERT(
|
|
3664
|
+
D_ASSERT(count_p <= capacity);
|
|
3635
3665
|
this->count = count_p;
|
|
3636
3666
|
}
|
|
3637
3667
|
void SetCardinality(const DataChunk &other) {
|
|
3638
3668
|
this->count = other.size();
|
|
3639
3669
|
}
|
|
3670
|
+
void SetCapacity(const DataChunk &other) {
|
|
3671
|
+
this->capacity = other.capacity;
|
|
3672
|
+
}
|
|
3640
3673
|
|
|
3641
3674
|
DUCKDB_API Value GetValue(idx_t col_idx, idx_t index) const;
|
|
3642
3675
|
DUCKDB_API void SetValue(idx_t col_idx, idx_t index, const Value &val);
|
|
@@ -3655,10 +3688,10 @@ public:
|
|
|
3655
3688
|
void InitializeEmpty(const vector<LogicalType> &types);
|
|
3656
3689
|
//! Append the other DataChunk to this one. The column count and types of
|
|
3657
3690
|
//! the two DataChunks have to match exactly. Throws an exception if there
|
|
3658
|
-
//! is not enough space in the chunk.
|
|
3659
|
-
DUCKDB_API void Append(const DataChunk &other
|
|
3660
|
-
|
|
3661
|
-
|
|
3691
|
+
//! is not enough space in the chunk and resize is not allowed.
|
|
3692
|
+
DUCKDB_API void Append(const DataChunk &other, bool resize = false, SelectionVector *sel = nullptr,
|
|
3693
|
+
idx_t count = 0);
|
|
3694
|
+
|
|
3662
3695
|
//! Destroy all data and columns owned by this DataChunk
|
|
3663
3696
|
DUCKDB_API void Destroy();
|
|
3664
3697
|
|
|
@@ -3710,6 +3743,8 @@ public:
|
|
|
3710
3743
|
private:
|
|
3711
3744
|
//! The amount of tuples stored in the data chunk
|
|
3712
3745
|
idx_t count;
|
|
3746
|
+
//! The amount of tuples that can be stored in the data chunk
|
|
3747
|
+
idx_t capacity;
|
|
3713
3748
|
//! Vector caches, used to store data when ::Initialize is called
|
|
3714
3749
|
vector<VectorCache> vector_caches;
|
|
3715
3750
|
};
|
|
@@ -5164,6 +5199,7 @@ enum class ExpressionType : uint8_t {
|
|
|
5164
5199
|
// -----------------------------
|
|
5165
5200
|
AGGREGATE = 100,
|
|
5166
5201
|
BOUND_AGGREGATE = 101,
|
|
5202
|
+
GROUPING_FUNCTION = 102,
|
|
5167
5203
|
|
|
5168
5204
|
// -----------------------------
|
|
5169
5205
|
// Window Functions
|
|
@@ -5420,6 +5456,36 @@ protected:
|
|
|
5420
5456
|
|
|
5421
5457
|
} // namespace duckdb
|
|
5422
5458
|
|
|
5459
|
+
//===----------------------------------------------------------------------===//
|
|
5460
|
+
// DuckDB
|
|
5461
|
+
//
|
|
5462
|
+
// duckdb/common/enums/compression_type.hpp
|
|
5463
|
+
//
|
|
5464
|
+
//
|
|
5465
|
+
//===----------------------------------------------------------------------===//
|
|
5466
|
+
|
|
5467
|
+
|
|
5468
|
+
|
|
5469
|
+
|
|
5470
|
+
|
|
5471
|
+
namespace duckdb {
|
|
5472
|
+
|
|
5473
|
+
enum class CompressionType : uint8_t {
|
|
5474
|
+
COMPRESSION_AUTO = 0,
|
|
5475
|
+
COMPRESSION_UNCOMPRESSED = 1,
|
|
5476
|
+
COMPRESSION_CONSTANT = 2,
|
|
5477
|
+
COMPRESSION_RLE = 3,
|
|
5478
|
+
COMPRESSION_DICTIONARY = 4,
|
|
5479
|
+
COMPRESSION_PFOR_DELTA = 5,
|
|
5480
|
+
COMPRESSION_BITPACKING = 6,
|
|
5481
|
+
COMPRESSION_FSST = 7
|
|
5482
|
+
};
|
|
5483
|
+
|
|
5484
|
+
CompressionType CompressionTypeFromString(const string &str);
|
|
5485
|
+
string CompressionTypeToString(CompressionType type);
|
|
5486
|
+
|
|
5487
|
+
} // namespace duckdb
|
|
5488
|
+
|
|
5423
5489
|
|
|
5424
5490
|
namespace duckdb {
|
|
5425
5491
|
|
|
@@ -5440,6 +5506,8 @@ public:
|
|
|
5440
5506
|
LogicalType type;
|
|
5441
5507
|
//! The default value of the column (if any)
|
|
5442
5508
|
unique_ptr<ParsedExpression> default_value;
|
|
5509
|
+
//! Compression Type used for this column
|
|
5510
|
+
CompressionType compression_type = CompressionType::COMPRESSION_AUTO;
|
|
5443
5511
|
|
|
5444
5512
|
public:
|
|
5445
5513
|
ColumnDefinition Copy() const;
|
|
@@ -5895,6 +5963,8 @@ template <>
|
|
|
5895
5963
|
bool Hugeint::TryCast(hugeint_t input, float &result);
|
|
5896
5964
|
template <>
|
|
5897
5965
|
bool Hugeint::TryCast(hugeint_t input, double &result);
|
|
5966
|
+
template <>
|
|
5967
|
+
bool Hugeint::TryCast(hugeint_t input, long double &result);
|
|
5898
5968
|
|
|
5899
5969
|
template <>
|
|
5900
5970
|
bool Hugeint::TryConvert(int8_t value, hugeint_t &result);
|
|
@@ -5916,6 +5986,8 @@ template <>
|
|
|
5916
5986
|
bool Hugeint::TryConvert(float value, hugeint_t &result);
|
|
5917
5987
|
template <>
|
|
5918
5988
|
bool Hugeint::TryConvert(double value, hugeint_t &result);
|
|
5989
|
+
template <>
|
|
5990
|
+
bool Hugeint::TryConvert(long double value, hugeint_t &result);
|
|
5919
5991
|
|
|
5920
5992
|
} // namespace duckdb
|
|
5921
5993
|
|
|
@@ -5943,8 +6015,9 @@ public:
|
|
|
5943
6015
|
static constexpr const int32_t MONTHS_PER_YEAR = 12;
|
|
5944
6016
|
static constexpr const int32_t MONTHS_PER_QUARTER = 3;
|
|
5945
6017
|
static constexpr const int32_t DAYS_PER_WEEK = 7;
|
|
5946
|
-
|
|
5947
|
-
|
|
6018
|
+
//! only used for interval comparison/ordering purposes, in which case a month counts as 30 days
|
|
6019
|
+
static constexpr const int64_t DAYS_PER_MONTH = 30;
|
|
6020
|
+
static constexpr const int64_t DAYS_PER_YEAR = 365;
|
|
5948
6021
|
static constexpr const int64_t MSECS_PER_SEC = 1000;
|
|
5949
6022
|
static constexpr const int32_t SECS_PER_MINUTE = 60;
|
|
5950
6023
|
static constexpr const int32_t MINS_PER_HOUR = 60;
|
|
@@ -5975,13 +6048,19 @@ public:
|
|
|
5975
6048
|
//! Convert a string to an interval object
|
|
5976
6049
|
static bool FromCString(const char *str, idx_t len, interval_t &result, string *error_message, bool strict);
|
|
5977
6050
|
//! Convert an interval object to a string
|
|
5978
|
-
static string ToString(interval_t
|
|
6051
|
+
static string ToString(const interval_t &val);
|
|
6052
|
+
|
|
6053
|
+
//! Convert milliseconds to a normalised interval
|
|
6054
|
+
static interval_t FromMicro(int64_t micros);
|
|
5979
6055
|
|
|
5980
6056
|
//! Get Interval in milliseconds
|
|
5981
|
-
static int64_t GetMilli(interval_t val);
|
|
6057
|
+
static int64_t GetMilli(const interval_t &val);
|
|
6058
|
+
|
|
6059
|
+
//! Get Interval in microseconds
|
|
6060
|
+
static int64_t GetMicro(const interval_t &val);
|
|
5982
6061
|
|
|
5983
6062
|
//! Get Interval in Nanoseconds
|
|
5984
|
-
static int64_t GetNanoseconds(interval_t val);
|
|
6063
|
+
static int64_t GetNanoseconds(const interval_t &val);
|
|
5985
6064
|
|
|
5986
6065
|
//! Returns the age between two timestamps (including 30 day months)
|
|
5987
6066
|
static interval_t GetAge(timestamp_t timestamp_1, timestamp_t timestamp_2);
|
|
@@ -5989,6 +6068,12 @@ public:
|
|
|
5989
6068
|
//! Returns the exact difference between two timestamps (days and seconds)
|
|
5990
6069
|
static interval_t GetDifference(timestamp_t timestamp_1, timestamp_t timestamp_2);
|
|
5991
6070
|
|
|
6071
|
+
//! Add an interval to a date
|
|
6072
|
+
static date_t Add(date_t left, interval_t right);
|
|
6073
|
+
//! Add an interval to a time. In case the time overflows or underflows, modify the date by the overflow.
|
|
6074
|
+
//! For example if we go from 23:00 to 02:00, we add a day to the date
|
|
6075
|
+
static dtime_t Add(dtime_t left, interval_t right, date_t &date);
|
|
6076
|
+
|
|
5992
6077
|
//! Comparison operators
|
|
5993
6078
|
static bool Equals(interval_t left, interval_t right);
|
|
5994
6079
|
static bool GreaterThan(interval_t left, interval_t right);
|
|
@@ -7134,6 +7219,7 @@ enum class CatalogType : uint8_t {
|
|
|
7134
7219
|
PREPARED_STATEMENT = 5,
|
|
7135
7220
|
SEQUENCE_ENTRY = 6,
|
|
7136
7221
|
COLLATION_ENTRY = 7,
|
|
7222
|
+
TYPE_ENTRY = 8,
|
|
7137
7223
|
|
|
7138
7224
|
// functions
|
|
7139
7225
|
TABLE_FUNCTION_ENTRY = 25,
|
|
@@ -7302,6 +7388,7 @@ struct CreateFunctionInfo;
|
|
|
7302
7388
|
struct CreateViewInfo;
|
|
7303
7389
|
struct CreateSequenceInfo;
|
|
7304
7390
|
struct CreateCollationInfo;
|
|
7391
|
+
struct CreateTypeInfo;
|
|
7305
7392
|
|
|
7306
7393
|
class ClientContext;
|
|
7307
7394
|
class Transaction;
|
|
@@ -7390,6 +7477,8 @@ public:
|
|
|
7390
7477
|
CatalogEntry *CreateView(ClientContext &context, CreateViewInfo *info);
|
|
7391
7478
|
//! Creates a table in the catalog.
|
|
7392
7479
|
CatalogEntry *CreateSequence(ClientContext &context, CreateSequenceInfo *info);
|
|
7480
|
+
//! Creates a Enum in the catalog.
|
|
7481
|
+
CatalogEntry *CreateType(ClientContext &context, CreateTypeInfo *info);
|
|
7393
7482
|
//! Creates a collation in the catalog
|
|
7394
7483
|
CatalogEntry *CreateCollation(ClientContext &context, CreateCollationInfo *info);
|
|
7395
7484
|
|
|
@@ -7409,6 +7498,8 @@ public:
|
|
|
7409
7498
|
CatalogEntry *CreateView(ClientContext &context, SchemaCatalogEntry *schema, CreateViewInfo *info);
|
|
7410
7499
|
//! Creates a table in the catalog.
|
|
7411
7500
|
CatalogEntry *CreateSequence(ClientContext &context, SchemaCatalogEntry *schema, CreateSequenceInfo *info);
|
|
7501
|
+
//! Creates a enum in the catalog.
|
|
7502
|
+
CatalogEntry *CreateType(ClientContext &context, SchemaCatalogEntry *schema, CreateTypeInfo *info);
|
|
7412
7503
|
//! Creates a collation in the catalog
|
|
7413
7504
|
CatalogEntry *CreateCollation(ClientContext &context, SchemaCatalogEntry *schema, CreateCollationInfo *info);
|
|
7414
7505
|
|
|
@@ -7555,6 +7646,7 @@ enum class LogicalOperatorType : uint8_t {
|
|
|
7555
7646
|
LOGICAL_DROP = 132,
|
|
7556
7647
|
LOGICAL_PRAGMA = 133,
|
|
7557
7648
|
LOGICAL_TRANSACTION = 134,
|
|
7649
|
+
LOGICAL_CREATE_TYPE = 135,
|
|
7558
7650
|
|
|
7559
7651
|
// -----------------------------
|
|
7560
7652
|
// Explain
|
|
@@ -8044,20 +8136,19 @@ public:
|
|
|
8044
8136
|
aggregate_combine_t combine, aggregate_finalize_t finalize,
|
|
8045
8137
|
aggregate_simple_update_t simple_update = nullptr, bind_aggregate_function_t bind = nullptr,
|
|
8046
8138
|
aggregate_destructor_t destructor = nullptr, aggregate_statistics_t statistics = nullptr,
|
|
8047
|
-
aggregate_window_t window = nullptr
|
|
8139
|
+
aggregate_window_t window = nullptr)
|
|
8048
8140
|
: BaseScalarFunction(name, arguments, return_type, false), state_size(state_size), initialize(initialize),
|
|
8049
8141
|
update(update), combine(combine), finalize(finalize), simple_update(simple_update), window(window),
|
|
8050
|
-
|
|
8142
|
+
bind(bind), destructor(destructor), statistics(statistics) {
|
|
8051
8143
|
}
|
|
8052
8144
|
|
|
8053
8145
|
AggregateFunction(const vector<LogicalType> &arguments, const LogicalType &return_type, aggregate_size_t state_size,
|
|
8054
8146
|
aggregate_initialize_t initialize, aggregate_update_t update, aggregate_combine_t combine,
|
|
8055
8147
|
aggregate_finalize_t finalize, aggregate_simple_update_t simple_update = nullptr,
|
|
8056
8148
|
bind_aggregate_function_t bind = nullptr, aggregate_destructor_t destructor = nullptr,
|
|
8057
|
-
aggregate_statistics_t statistics = nullptr, aggregate_window_t window = nullptr
|
|
8058
|
-
bool order_sensitive = false)
|
|
8149
|
+
aggregate_statistics_t statistics = nullptr, aggregate_window_t window = nullptr)
|
|
8059
8150
|
: AggregateFunction(string(), arguments, return_type, state_size, initialize, update, combine, finalize,
|
|
8060
|
-
simple_update, bind, destructor, statistics, window
|
|
8151
|
+
simple_update, bind, destructor, statistics, window) {
|
|
8061
8152
|
}
|
|
8062
8153
|
|
|
8063
8154
|
//! The hashed aggregate state sizing function
|
|
@@ -8074,8 +8165,6 @@ public:
|
|
|
8074
8165
|
aggregate_simple_update_t simple_update;
|
|
8075
8166
|
//! The windowed aggregate frame update function (may be null)
|
|
8076
8167
|
aggregate_window_t window;
|
|
8077
|
-
//! True if the aggregate is order-sensitive
|
|
8078
|
-
bool order_sensitive;
|
|
8079
8168
|
|
|
8080
8169
|
//! The bind function (may be null)
|
|
8081
8170
|
bind_aggregate_function_t bind;
|
|
@@ -8830,9 +8919,10 @@ public:
|
|
|
8830
8919
|
//! Fetches a DataChunk of normalized (flat) vectors from the query result.
|
|
8831
8920
|
//! Returns nullptr if there are no more results to fetch.
|
|
8832
8921
|
DUCKDB_API virtual unique_ptr<DataChunk> Fetch();
|
|
8833
|
-
//! Fetches a DataChunk from the query result. The vector types
|
|
8922
|
+
//! Fetches a DataChunk from the query result. The vectors are not normalized and hence any vector types can be
|
|
8923
|
+
//! returned.
|
|
8834
8924
|
DUCKDB_API virtual unique_ptr<DataChunk> FetchRaw() = 0;
|
|
8835
|
-
|
|
8925
|
+
//! Converts the QueryResult to a string
|
|
8836
8926
|
DUCKDB_API virtual string ToString() = 0;
|
|
8837
8927
|
//! Prints the QueryResult to the console
|
|
8838
8928
|
DUCKDB_API void Print();
|
|
@@ -9146,6 +9236,7 @@ string RelationTypeToString(RelationType type);
|
|
|
9146
9236
|
|
|
9147
9237
|
|
|
9148
9238
|
|
|
9239
|
+
|
|
9149
9240
|
#include <memory>
|
|
9150
9241
|
|
|
9151
9242
|
namespace duckdb {
|
|
@@ -9249,7 +9340,10 @@ public:
|
|
|
9249
9340
|
//! Delete from a table, can only be used on a TableRelation
|
|
9250
9341
|
DUCKDB_API virtual void Delete(const string &condition = string());
|
|
9251
9342
|
//! Create a relation from calling a table in/out function on the input relation
|
|
9252
|
-
|
|
9343
|
+
//! Create a relation from calling a table in/out function on the input relation
|
|
9344
|
+
DUCKDB_API shared_ptr<Relation> TableFunction(const std::string &fname, const vector<Value> &values);
|
|
9345
|
+
DUCKDB_API shared_ptr<Relation> TableFunction(const std::string &fname, const vector<Value> &values,
|
|
9346
|
+
const unordered_map<string, Value> &named_parameters);
|
|
9253
9347
|
|
|
9254
9348
|
public:
|
|
9255
9349
|
//! Whether or not the relation inherits column bindings from its child or not, only relevant for binding
|
|
@@ -9492,6 +9586,8 @@ public:
|
|
|
9492
9586
|
DUCKDB_API shared_ptr<Relation> View(const string &schema_name, const string &table_name);
|
|
9493
9587
|
//! Returns a relation that calls a specified table function
|
|
9494
9588
|
DUCKDB_API shared_ptr<Relation> TableFunction(const string &tname);
|
|
9589
|
+
DUCKDB_API shared_ptr<Relation> TableFunction(const string &tname, const vector<Value> &values,
|
|
9590
|
+
const unordered_map<string, Value> &named_parameters);
|
|
9495
9591
|
DUCKDB_API shared_ptr<Relation> TableFunction(const string &tname, const vector<Value> &values);
|
|
9496
9592
|
//! Returns a relation that produces values
|
|
9497
9593
|
DUCKDB_API shared_ptr<Relation> Values(const vector<vector<Value>> &values);
|
|
@@ -9504,7 +9600,7 @@ public:
|
|
|
9504
9600
|
DUCKDB_API shared_ptr<Relation> ReadCSV(const string &csv_file);
|
|
9505
9601
|
DUCKDB_API shared_ptr<Relation> ReadCSV(const string &csv_file, const vector<string> &columns);
|
|
9506
9602
|
//! Returns a relation from a query
|
|
9507
|
-
DUCKDB_API shared_ptr<Relation> RelationFromQuery(string query, string alias = "queryrelation");
|
|
9603
|
+
DUCKDB_API shared_ptr<Relation> RelationFromQuery(const string &query, const string &alias = "queryrelation");
|
|
9508
9604
|
|
|
9509
9605
|
DUCKDB_API void BeginTransaction();
|
|
9510
9606
|
DUCKDB_API void Commit();
|
|
@@ -9911,35 +10007,6 @@ namespace duckdb {
|
|
|
9911
10007
|
using std::set;
|
|
9912
10008
|
}
|
|
9913
10009
|
|
|
9914
|
-
//===----------------------------------------------------------------------===//
|
|
9915
|
-
// DuckDB
|
|
9916
|
-
//
|
|
9917
|
-
// duckdb/common/enums/compression_type.hpp
|
|
9918
|
-
//
|
|
9919
|
-
//
|
|
9920
|
-
//===----------------------------------------------------------------------===//
|
|
9921
|
-
|
|
9922
|
-
|
|
9923
|
-
|
|
9924
|
-
|
|
9925
|
-
|
|
9926
|
-
namespace duckdb {
|
|
9927
|
-
|
|
9928
|
-
enum class CompressionType : uint8_t {
|
|
9929
|
-
COMPRESSION_INVALID = 0,
|
|
9930
|
-
COMPRESSION_UNCOMPRESSED = 1,
|
|
9931
|
-
COMPRESSION_CONSTANT = 2,
|
|
9932
|
-
COMPRESSION_RLE = 3,
|
|
9933
|
-
COMPRESSION_DICTIONARY = 4,
|
|
9934
|
-
COMPRESSION_PFOR_DELTA = 5,
|
|
9935
|
-
COMPRESSION_BITPACKING = 6,
|
|
9936
|
-
COMPRESSION_FSST = 7
|
|
9937
|
-
};
|
|
9938
|
-
|
|
9939
|
-
CompressionType CompressionTypeFromString(const string &str);
|
|
9940
|
-
string CompressionTypeToString(CompressionType type);
|
|
9941
|
-
|
|
9942
|
-
} // namespace duckdb
|
|
9943
10010
|
|
|
9944
10011
|
//===----------------------------------------------------------------------===//
|
|
9945
10012
|
// DuckDB
|
|
@@ -9977,6 +10044,54 @@ string OptimizerTypeToString(OptimizerType type);
|
|
|
9977
10044
|
|
|
9978
10045
|
} // namespace duckdb
|
|
9979
10046
|
|
|
10047
|
+
//===----------------------------------------------------------------------===//
|
|
10048
|
+
// DuckDB
|
|
10049
|
+
//
|
|
10050
|
+
// duckdb/common/enums/window_aggregation_mode.hpp
|
|
10051
|
+
//
|
|
10052
|
+
//
|
|
10053
|
+
//===----------------------------------------------------------------------===//
|
|
10054
|
+
|
|
10055
|
+
|
|
10056
|
+
|
|
10057
|
+
|
|
10058
|
+
|
|
10059
|
+
namespace duckdb {
|
|
10060
|
+
|
|
10061
|
+
enum class WindowAggregationMode : uint32_t {
|
|
10062
|
+
//! Use the window aggregate API if available
|
|
10063
|
+
WINDOW = 0,
|
|
10064
|
+
//! Don't use window, but use combine if available
|
|
10065
|
+
COMBINE,
|
|
10066
|
+
//! Don't use combine or window (compute each frame separately)
|
|
10067
|
+
SEPARATE
|
|
10068
|
+
};
|
|
10069
|
+
|
|
10070
|
+
} // namespace duckdb
|
|
10071
|
+
|
|
10072
|
+
//===----------------------------------------------------------------------===//
|
|
10073
|
+
// DuckDB
|
|
10074
|
+
//
|
|
10075
|
+
// duckdb/common/enums/set_scope.hpp
|
|
10076
|
+
//
|
|
10077
|
+
//
|
|
10078
|
+
//===----------------------------------------------------------------------===//
|
|
10079
|
+
|
|
10080
|
+
|
|
10081
|
+
|
|
10082
|
+
|
|
10083
|
+
|
|
10084
|
+
namespace duckdb {
|
|
10085
|
+
|
|
10086
|
+
enum class SetScope : uint8_t {
|
|
10087
|
+
AUTOMATIC = 0,
|
|
10088
|
+
LOCAL = 1, /* unused */
|
|
10089
|
+
SESSION = 2,
|
|
10090
|
+
GLOBAL = 3
|
|
10091
|
+
};
|
|
10092
|
+
|
|
10093
|
+
} // namespace duckdb
|
|
10094
|
+
|
|
9980
10095
|
|
|
9981
10096
|
namespace duckdb {
|
|
9982
10097
|
class ClientContext;
|
|
@@ -9984,6 +10099,7 @@ class TableFunctionRef;
|
|
|
9984
10099
|
class CompressionFunction;
|
|
9985
10100
|
|
|
9986
10101
|
struct CompressionFunctionSet;
|
|
10102
|
+
struct DBConfig;
|
|
9987
10103
|
|
|
9988
10104
|
enum class AccessMode : uint8_t { UNDEFINED = 0, AUTOMATIC = 1, READ_ONLY = 2, READ_WRITE = 3 };
|
|
9989
10105
|
|
|
@@ -9994,25 +10110,31 @@ enum class CheckpointAbort : uint8_t {
|
|
|
9994
10110
|
DEBUG_ABORT_AFTER_FREE_LIST_WRITE = 3
|
|
9995
10111
|
};
|
|
9996
10112
|
|
|
9997
|
-
|
|
9998
|
-
|
|
9999
|
-
|
|
10000
|
-
DEFAULT_ORDER_TYPE,
|
|
10001
|
-
DEFAULT_NULL_ORDER,
|
|
10002
|
-
ENABLE_EXTERNAL_ACCESS,
|
|
10003
|
-
ENABLE_OBJECT_CACHE,
|
|
10004
|
-
MAXIMUM_MEMORY,
|
|
10005
|
-
THREADS
|
|
10006
|
-
};
|
|
10113
|
+
typedef void (*set_global_function_t)(DatabaseInstance *db, DBConfig &config, const Value ¶meter);
|
|
10114
|
+
typedef void (*set_local_function_t)(ClientContext &context, const Value ¶meter);
|
|
10115
|
+
typedef Value (*get_setting_function_t)(ClientContext &context);
|
|
10007
10116
|
|
|
10008
10117
|
struct ConfigurationOption {
|
|
10009
|
-
ConfigurationOptionType type;
|
|
10010
10118
|
const char *name;
|
|
10011
10119
|
const char *description;
|
|
10012
10120
|
LogicalTypeId parameter_type;
|
|
10121
|
+
set_global_function_t set_global;
|
|
10122
|
+
set_local_function_t set_local;
|
|
10123
|
+
get_setting_function_t get_setting;
|
|
10124
|
+
};
|
|
10125
|
+
|
|
10126
|
+
typedef void (*set_option_callback_t)(ClientContext &context, SetScope scope, Value ¶meter);
|
|
10127
|
+
|
|
10128
|
+
struct ExtensionOption {
|
|
10129
|
+
ExtensionOption(string description_p, LogicalType type_p, set_option_callback_t set_function_p)
|
|
10130
|
+
: description(move(description_p)), type(move(type_p)), set_function(set_function_p) {
|
|
10131
|
+
}
|
|
10132
|
+
|
|
10133
|
+
string description;
|
|
10134
|
+
LogicalType type;
|
|
10135
|
+
set_option_callback_t set_function;
|
|
10013
10136
|
};
|
|
10014
10137
|
|
|
10015
|
-
// this is optional and only used in tests at the moment
|
|
10016
10138
|
struct DBConfig {
|
|
10017
10139
|
friend class DatabaseInstance;
|
|
10018
10140
|
friend class StorageManager;
|
|
@@ -10029,6 +10151,8 @@ public:
|
|
|
10029
10151
|
idx_t checkpoint_wal_size = 1 << 24;
|
|
10030
10152
|
//! Whether or not to use Direct IO, bypassing operating system buffers
|
|
10031
10153
|
bool use_direct_io = false;
|
|
10154
|
+
//! Whether extensions should be loaded on start-up
|
|
10155
|
+
bool load_extensions = true;
|
|
10032
10156
|
//! The FileSystem to use, can be overwritten to allow for injecting custom file systems for testing purposes (e.g.
|
|
10033
10157
|
//! RamFS or something similar)
|
|
10034
10158
|
unique_ptr<FileSystem> file_system;
|
|
@@ -10050,8 +10174,6 @@ public:
|
|
|
10050
10174
|
bool enable_external_access = true;
|
|
10051
10175
|
//! Whether or not object cache is used
|
|
10052
10176
|
bool object_cache_enable = false;
|
|
10053
|
-
//! Database configuration variables as controlled by SET
|
|
10054
|
-
case_insensitive_map_t<Value> set_variables;
|
|
10055
10177
|
//! Force checkpoint when CHECKPOINT is called or on shutdown, even if no changes have been made
|
|
10056
10178
|
bool force_checkpoint = false;
|
|
10057
10179
|
//! Run a checkpoint on successful shutdown and delete the WAL, to leave only a single database file behind
|
|
@@ -10066,9 +10188,22 @@ public:
|
|
|
10066
10188
|
//! The set of disabled optimizers (default empty)
|
|
10067
10189
|
set<OptimizerType> disabled_optimizers;
|
|
10068
10190
|
//! Force a specific compression method to be used when checkpointing (if available)
|
|
10069
|
-
CompressionType force_compression = CompressionType::
|
|
10191
|
+
CompressionType force_compression = CompressionType::COMPRESSION_AUTO;
|
|
10070
10192
|
//! Debug flag that adds additional (unnecessary) free_list blocks to the storage
|
|
10071
10193
|
bool debug_many_free_list_blocks = false;
|
|
10194
|
+
//! Debug setting for window aggregation mode: (window, combine, separate)
|
|
10195
|
+
WindowAggregationMode window_mode = WindowAggregationMode::WINDOW;
|
|
10196
|
+
|
|
10197
|
+
//! Extra parameters that can be SET for loaded extensions
|
|
10198
|
+
case_insensitive_map_t<ExtensionOption> extension_parameters;
|
|
10199
|
+
//! Database configuration variables as controlled by SET
|
|
10200
|
+
case_insensitive_map_t<Value> set_variables;
|
|
10201
|
+
|
|
10202
|
+
void AddExtensionOption(string name, string description, LogicalType parameter,
|
|
10203
|
+
set_option_callback_t function = nullptr) {
|
|
10204
|
+
extension_parameters.insert(
|
|
10205
|
+
make_pair(move(name), ExtensionOption(move(description), move(parameter), function)));
|
|
10206
|
+
}
|
|
10072
10207
|
|
|
10073
10208
|
public:
|
|
10074
10209
|
DUCKDB_API static DBConfig &GetConfig(ClientContext &context);
|
|
@@ -12015,6 +12150,194 @@ using std::pair;
|
|
|
12015
12150
|
|
|
12016
12151
|
|
|
12017
12152
|
|
|
12153
|
+
//===----------------------------------------------------------------------===//
|
|
12154
|
+
// DuckDB
|
|
12155
|
+
//
|
|
12156
|
+
// duckdb/catalog/catalog_entry/table_catalog_entry.hpp
|
|
12157
|
+
//
|
|
12158
|
+
//
|
|
12159
|
+
//===----------------------------------------------------------------------===//
|
|
12160
|
+
|
|
12161
|
+
|
|
12162
|
+
|
|
12163
|
+
//===----------------------------------------------------------------------===//
|
|
12164
|
+
// DuckDB
|
|
12165
|
+
//
|
|
12166
|
+
// duckdb/catalog/standard_entry.hpp
|
|
12167
|
+
//
|
|
12168
|
+
//
|
|
12169
|
+
//===----------------------------------------------------------------------===//
|
|
12170
|
+
|
|
12171
|
+
|
|
12172
|
+
|
|
12173
|
+
|
|
12174
|
+
|
|
12175
|
+
namespace duckdb {
|
|
12176
|
+
class SchemaCatalogEntry;
|
|
12177
|
+
|
|
12178
|
+
//! A StandardEntry is a catalog entry that is a member of a schema
|
|
12179
|
+
class StandardEntry : public CatalogEntry {
|
|
12180
|
+
public:
|
|
12181
|
+
StandardEntry(CatalogType type, SchemaCatalogEntry *schema, Catalog *catalog, string name)
|
|
12182
|
+
: CatalogEntry(type, catalog, name), schema(schema) {
|
|
12183
|
+
}
|
|
12184
|
+
~StandardEntry() override {
|
|
12185
|
+
}
|
|
12186
|
+
|
|
12187
|
+
//! The schema the entry belongs to
|
|
12188
|
+
SchemaCatalogEntry *schema;
|
|
12189
|
+
};
|
|
12190
|
+
} // namespace duckdb
|
|
12191
|
+
|
|
12192
|
+
|
|
12193
|
+
|
|
12194
|
+
//===----------------------------------------------------------------------===//
|
|
12195
|
+
// DuckDB
|
|
12196
|
+
//
|
|
12197
|
+
// duckdb/parser/constraint.hpp
|
|
12198
|
+
//
|
|
12199
|
+
//
|
|
12200
|
+
//===----------------------------------------------------------------------===//
|
|
12201
|
+
|
|
12202
|
+
|
|
12203
|
+
|
|
12204
|
+
|
|
12205
|
+
|
|
12206
|
+
namespace duckdb {
|
|
12207
|
+
|
|
12208
|
+
class Serializer;
|
|
12209
|
+
class Deserializer;
|
|
12210
|
+
|
|
12211
|
+
//===--------------------------------------------------------------------===//
|
|
12212
|
+
// Constraint Types
|
|
12213
|
+
//===--------------------------------------------------------------------===//
|
|
12214
|
+
enum class ConstraintType : uint8_t {
|
|
12215
|
+
INVALID = 0, // invalid constraint type
|
|
12216
|
+
NOT_NULL = 1, // NOT NULL constraint
|
|
12217
|
+
CHECK = 2, // CHECK constraint
|
|
12218
|
+
UNIQUE = 3, // UNIQUE constraint
|
|
12219
|
+
FOREIGN_KEY = 4 // FOREIGN KEY constraint
|
|
12220
|
+
};
|
|
12221
|
+
|
|
12222
|
+
//! Constraint is the base class of any type of table constraint.
|
|
12223
|
+
class Constraint {
|
|
12224
|
+
public:
|
|
12225
|
+
explicit Constraint(ConstraintType type) : type(type) {};
|
|
12226
|
+
virtual ~Constraint() {
|
|
12227
|
+
}
|
|
12228
|
+
|
|
12229
|
+
ConstraintType type;
|
|
12230
|
+
|
|
12231
|
+
public:
|
|
12232
|
+
virtual string ToString() const = 0;
|
|
12233
|
+
void Print();
|
|
12234
|
+
|
|
12235
|
+
virtual unique_ptr<Constraint> Copy() = 0;
|
|
12236
|
+
//! Serializes a Constraint to a stand-alone binary blob
|
|
12237
|
+
virtual void Serialize(Serializer &serializer);
|
|
12238
|
+
//! Deserializes a blob back into a Constraint, returns NULL if
|
|
12239
|
+
//! deserialization is not possible
|
|
12240
|
+
static unique_ptr<Constraint> Deserialize(Deserializer &source);
|
|
12241
|
+
};
|
|
12242
|
+
} // namespace duckdb
|
|
12243
|
+
|
|
12244
|
+
//===----------------------------------------------------------------------===//
|
|
12245
|
+
// DuckDB
|
|
12246
|
+
//
|
|
12247
|
+
// duckdb/planner/bound_constraint.hpp
|
|
12248
|
+
//
|
|
12249
|
+
//
|
|
12250
|
+
//===----------------------------------------------------------------------===//
|
|
12251
|
+
|
|
12252
|
+
|
|
12253
|
+
|
|
12254
|
+
|
|
12255
|
+
|
|
12256
|
+
|
|
12257
|
+
namespace duckdb {
|
|
12258
|
+
//! Bound equivalent of Constraint
|
|
12259
|
+
class BoundConstraint {
|
|
12260
|
+
public:
|
|
12261
|
+
explicit BoundConstraint(ConstraintType type) : type(type) {};
|
|
12262
|
+
virtual ~BoundConstraint() {
|
|
12263
|
+
}
|
|
12264
|
+
|
|
12265
|
+
ConstraintType type;
|
|
12266
|
+
};
|
|
12267
|
+
} // namespace duckdb
|
|
12268
|
+
|
|
12269
|
+
|
|
12270
|
+
|
|
12271
|
+
|
|
12272
|
+
namespace duckdb {
|
|
12273
|
+
|
|
12274
|
+
class ColumnStatistics;
|
|
12275
|
+
class DataTable;
|
|
12276
|
+
struct CreateTableInfo;
|
|
12277
|
+
struct BoundCreateTableInfo;
|
|
12278
|
+
|
|
12279
|
+
struct RenameColumnInfo;
|
|
12280
|
+
struct AddColumnInfo;
|
|
12281
|
+
struct RemoveColumnInfo;
|
|
12282
|
+
struct SetDefaultInfo;
|
|
12283
|
+
struct ChangeColumnTypeInfo;
|
|
12284
|
+
|
|
12285
|
+
//! A table catalog entry
|
|
12286
|
+
class TableCatalogEntry : public StandardEntry {
|
|
12287
|
+
public:
|
|
12288
|
+
//! Create a real TableCatalogEntry and initialize storage for it
|
|
12289
|
+
TableCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, BoundCreateTableInfo *info,
|
|
12290
|
+
std::shared_ptr<DataTable> inherited_storage = nullptr);
|
|
12291
|
+
|
|
12292
|
+
//! A reference to the underlying storage unit used for this table
|
|
12293
|
+
std::shared_ptr<DataTable> storage;
|
|
12294
|
+
//! A list of columns that are part of this table
|
|
12295
|
+
vector<ColumnDefinition> columns;
|
|
12296
|
+
//! A list of constraints that are part of this table
|
|
12297
|
+
vector<unique_ptr<Constraint>> constraints;
|
|
12298
|
+
//! A list of constraints that are part of this table
|
|
12299
|
+
vector<unique_ptr<BoundConstraint>> bound_constraints;
|
|
12300
|
+
//! A map of column name to column index
|
|
12301
|
+
case_insensitive_map_t<column_t> name_map;
|
|
12302
|
+
|
|
12303
|
+
public:
|
|
12304
|
+
unique_ptr<CatalogEntry> AlterEntry(ClientContext &context, AlterInfo *info) override;
|
|
12305
|
+
//! Returns whether or not a column with the given name exists
|
|
12306
|
+
bool ColumnExists(const string &name);
|
|
12307
|
+
//! Returns a reference to the column of the specified name. Throws an
|
|
12308
|
+
//! exception if the column does not exist.
|
|
12309
|
+
ColumnDefinition &GetColumn(const string &name);
|
|
12310
|
+
//! Returns a list of types of the table
|
|
12311
|
+
vector<LogicalType> GetTypes();
|
|
12312
|
+
string ToSQL() override;
|
|
12313
|
+
|
|
12314
|
+
//! Serialize the meta information of the TableCatalogEntry a serializer
|
|
12315
|
+
virtual void Serialize(Serializer &serializer);
|
|
12316
|
+
//! Deserializes to a CreateTableInfo
|
|
12317
|
+
static unique_ptr<CreateTableInfo> Deserialize(Deserializer &source);
|
|
12318
|
+
|
|
12319
|
+
unique_ptr<CatalogEntry> Copy(ClientContext &context) override;
|
|
12320
|
+
|
|
12321
|
+
void SetAsRoot() override;
|
|
12322
|
+
|
|
12323
|
+
void CommitAlter(AlterInfo &info);
|
|
12324
|
+
void CommitDrop();
|
|
12325
|
+
|
|
12326
|
+
//! Returns the column index of the specified column name.
|
|
12327
|
+
//! If the column does not exist:
|
|
12328
|
+
//! If if_exists is true, returns INVALID_INDEX
|
|
12329
|
+
//! If if_exists is false, throws an exception
|
|
12330
|
+
idx_t GetColumnIndex(string &name, bool if_exists = false);
|
|
12331
|
+
|
|
12332
|
+
private:
|
|
12333
|
+
unique_ptr<CatalogEntry> RenameColumn(ClientContext &context, RenameColumnInfo &info);
|
|
12334
|
+
unique_ptr<CatalogEntry> AddColumn(ClientContext &context, AddColumnInfo &info);
|
|
12335
|
+
unique_ptr<CatalogEntry> RemoveColumn(ClientContext &context, RemoveColumnInfo &info);
|
|
12336
|
+
unique_ptr<CatalogEntry> SetDefault(ClientContext &context, SetDefaultInfo &info);
|
|
12337
|
+
unique_ptr<CatalogEntry> ChangeColumnType(ClientContext &context, ChangeColumnTypeInfo &info);
|
|
12338
|
+
};
|
|
12339
|
+
} // namespace duckdb
|
|
12340
|
+
|
|
12018
12341
|
#include <functional>
|
|
12019
12342
|
#include <memory>
|
|
12020
12343
|
|
|
@@ -12084,6 +12407,12 @@ public:
|
|
|
12084
12407
|
void UpdateTimestamp(CatalogEntry *entry, transaction_t timestamp);
|
|
12085
12408
|
|
|
12086
12409
|
private:
|
|
12410
|
+
//! Adjusts table dependencies on the event of an UNDO
|
|
12411
|
+
void AdjustTableDependencies(CatalogEntry *entry);
|
|
12412
|
+
//! Adjust one dependency
|
|
12413
|
+
void AdjustDependency(CatalogEntry *entry, TableCatalogEntry *table, ColumnDefinition &column, bool remove);
|
|
12414
|
+
//! Adjust Enum dependency
|
|
12415
|
+
void AdjustEnumDependency(CatalogEntry *entry, ColumnDefinition &column, bool remove);
|
|
12087
12416
|
//! Given a root entry, gets the entry valid for this transaction
|
|
12088
12417
|
CatalogEntry *GetEntryForTransaction(ClientContext &context, CatalogEntry *current);
|
|
12089
12418
|
CatalogEntry *GetCommittedEntry(CatalogEntry *current);
|
|
@@ -12138,6 +12467,7 @@ struct CreateSequenceInfo;
|
|
|
12138
12467
|
struct CreateSchemaInfo;
|
|
12139
12468
|
struct CreateTableFunctionInfo;
|
|
12140
12469
|
struct CreateCopyFunctionInfo;
|
|
12470
|
+
struct CreateTypeInfo;
|
|
12141
12471
|
|
|
12142
12472
|
struct DropInfo;
|
|
12143
12473
|
|
|
@@ -12165,6 +12495,8 @@ private:
|
|
|
12165
12495
|
CatalogSet sequences;
|
|
12166
12496
|
//! The catalog set holding the collations
|
|
12167
12497
|
CatalogSet collations;
|
|
12498
|
+
//! The catalog set holding the types
|
|
12499
|
+
CatalogSet types;
|
|
12168
12500
|
|
|
12169
12501
|
public:
|
|
12170
12502
|
//! Scan the specified catalog set, invoking the callback method for every entry
|
|
@@ -12199,6 +12531,8 @@ private:
|
|
|
12199
12531
|
CatalogEntry *CreatePragmaFunction(ClientContext &context, CreatePragmaFunctionInfo *info);
|
|
12200
12532
|
//! Create a collation within the given schema
|
|
12201
12533
|
CatalogEntry *CreateCollation(ClientContext &context, CreateCollationInfo *info);
|
|
12534
|
+
//! Create a enum within the given schema
|
|
12535
|
+
CatalogEntry *CreateType(ClientContext &context, CreateTypeInfo *info);
|
|
12202
12536
|
|
|
12203
12537
|
//! Drops an entry from the schema
|
|
12204
12538
|
void DropEntry(ClientContext &context, DropInfo *info);
|
|
@@ -12218,7 +12552,6 @@ private:
|
|
|
12218
12552
|
} // namespace duckdb
|
|
12219
12553
|
|
|
12220
12554
|
|
|
12221
|
-
|
|
12222
12555
|
//===----------------------------------------------------------------------===//
|
|
12223
12556
|
// DuckDB
|
|
12224
12557
|
//
|
|
@@ -12234,24 +12567,6 @@ private:
|
|
|
12234
12567
|
namespace duckdb {
|
|
12235
12568
|
using std::deque;
|
|
12236
12569
|
}
|
|
12237
|
-
//===----------------------------------------------------------------------===//
|
|
12238
|
-
// DuckDB
|
|
12239
|
-
//
|
|
12240
|
-
// duckdb/common/enums/output_type.hpp
|
|
12241
|
-
//
|
|
12242
|
-
//
|
|
12243
|
-
//===----------------------------------------------------------------------===//
|
|
12244
|
-
|
|
12245
|
-
|
|
12246
|
-
|
|
12247
|
-
|
|
12248
|
-
|
|
12249
|
-
namespace duckdb {
|
|
12250
|
-
|
|
12251
|
-
enum class ExplainOutputType : uint8_t { ALL = 0, OPTIMIZED_ONLY = 1, PHYSICAL_ONLY = 2 };
|
|
12252
|
-
|
|
12253
|
-
} // namespace duckdb
|
|
12254
|
-
|
|
12255
12570
|
|
|
12256
12571
|
//===----------------------------------------------------------------------===//
|
|
12257
12572
|
// DuckDB
|
|
@@ -12307,16 +12622,6 @@ using std::thread;
|
|
|
12307
12622
|
|
|
12308
12623
|
|
|
12309
12624
|
|
|
12310
|
-
//===----------------------------------------------------------------------===//
|
|
12311
|
-
// DuckDB
|
|
12312
|
-
//
|
|
12313
|
-
// duckdb/execution/physical_sink.hpp
|
|
12314
|
-
//
|
|
12315
|
-
//
|
|
12316
|
-
//===----------------------------------------------------------------------===//
|
|
12317
|
-
|
|
12318
|
-
|
|
12319
|
-
|
|
12320
12625
|
//===----------------------------------------------------------------------===//
|
|
12321
12626
|
// DuckDB
|
|
12322
12627
|
//
|
|
@@ -12407,11 +12712,13 @@ enum class PhysicalOperatorType : uint8_t {
|
|
|
12407
12712
|
DROP,
|
|
12408
12713
|
PRAGMA,
|
|
12409
12714
|
TRANSACTION,
|
|
12715
|
+
CREATE_TYPE,
|
|
12410
12716
|
|
|
12411
12717
|
// -----------------------------
|
|
12412
12718
|
// Helpers
|
|
12413
12719
|
// -----------------------------
|
|
12414
12720
|
EXPLAIN,
|
|
12721
|
+
EXPLAIN_ANALYZE,
|
|
12415
12722
|
EMPTY_RESULT,
|
|
12416
12723
|
EXECUTE,
|
|
12417
12724
|
PREPARE,
|
|
@@ -12442,60 +12749,110 @@ string PhysicalOperatorToString(PhysicalOperatorType type);
|
|
|
12442
12749
|
namespace duckdb {
|
|
12443
12750
|
class ClientContext;
|
|
12444
12751
|
class ThreadContext;
|
|
12445
|
-
class TaskContext;
|
|
12446
12752
|
|
|
12447
12753
|
class ExecutionContext {
|
|
12448
12754
|
public:
|
|
12449
|
-
ExecutionContext(ClientContext &client_p, ThreadContext &thread_p,
|
|
12450
|
-
: client(client_p), thread(thread_p), task(task_p) {
|
|
12755
|
+
ExecutionContext(ClientContext &client_p, ThreadContext &thread_p) : client(client_p), thread(thread_p) {
|
|
12451
12756
|
}
|
|
12452
12757
|
|
|
12453
12758
|
//! The client-global context; caution needs to be taken when used in parallel situations
|
|
12454
12759
|
ClientContext &client;
|
|
12455
12760
|
//! The thread-local context for this execution
|
|
12456
12761
|
ThreadContext &thread;
|
|
12457
|
-
//! The task context for this execution
|
|
12458
|
-
TaskContext &task;
|
|
12459
12762
|
};
|
|
12460
12763
|
|
|
12461
12764
|
} // namespace duckdb
|
|
12462
12765
|
|
|
12766
|
+
//===----------------------------------------------------------------------===//
|
|
12767
|
+
// DuckDB
|
|
12768
|
+
//
|
|
12769
|
+
// duckdb/common/enums/operator_result_type.hpp
|
|
12770
|
+
//
|
|
12771
|
+
//
|
|
12772
|
+
//===----------------------------------------------------------------------===//
|
|
12773
|
+
|
|
12774
|
+
|
|
12463
12775
|
|
|
12464
12776
|
|
|
12465
|
-
#include <functional>
|
|
12466
|
-
#include <utility>
|
|
12467
12777
|
|
|
12468
12778
|
namespace duckdb {
|
|
12469
|
-
|
|
12779
|
+
|
|
12780
|
+
//! The OperatorResultType is used to indicate how data should flow around a regular (i.e. non-sink and non-source)
|
|
12781
|
+
//! physical operator
|
|
12782
|
+
//! There are three possible results:
|
|
12783
|
+
//! NEED_MORE_INPUT means the operator is done with the current input and can consume more input if available
|
|
12784
|
+
//! If there is more input the operator will be called with more input, otherwise the operator will not be called again.
|
|
12785
|
+
//! HAVE_MORE_OUTPUT means the operator is not finished yet with the current input.
|
|
12786
|
+
//! The operator will be called again with the same input.
|
|
12787
|
+
//! FINISHED means the operator has finished the entire pipeline and no more processing is necessary.
|
|
12788
|
+
//! The operator will not be called again, and neither will any other operators in this pipeline.
|
|
12789
|
+
enum class OperatorResultType : uint8_t { NEED_MORE_INPUT, HAVE_MORE_OUTPUT, FINISHED };
|
|
12790
|
+
|
|
12791
|
+
//! The SinkResultType is used to indicate the result of data flowing into a sink
|
|
12792
|
+
//! There are two possible results:
|
|
12793
|
+
//! NEED_MORE_INPUT means the sink needs more input
|
|
12794
|
+
//! FINISHED means the sink is finished executing, and more input will not change the result any further
|
|
12795
|
+
enum class SinkResultType : uint8_t { NEED_MORE_INPUT, FINISHED };
|
|
12796
|
+
|
|
12797
|
+
//! The SinkFinalizeType is used to indicate the result of a Finalize call on a sink
|
|
12798
|
+
//! There are two possible results:
|
|
12799
|
+
//! READY means the sink is ready for further processing
|
|
12800
|
+
//! NO_OUTPUT_POSSIBLE means the sink will never provide output, and any pipelines involving the sink can be skipped
|
|
12801
|
+
enum class SinkFinalizeType : uint8_t { READY, NO_OUTPUT_POSSIBLE };
|
|
12802
|
+
|
|
12803
|
+
} // namespace duckdb
|
|
12804
|
+
|
|
12805
|
+
|
|
12806
|
+
namespace duckdb {
|
|
12807
|
+
class Event;
|
|
12470
12808
|
class PhysicalOperator;
|
|
12809
|
+
class Pipeline;
|
|
12471
12810
|
|
|
12472
|
-
|
|
12473
|
-
|
|
12474
|
-
//! call the GetChunk function and get new batches of data everytime until the
|
|
12475
|
-
//! data source is exhausted.
|
|
12476
|
-
class PhysicalOperatorState {
|
|
12811
|
+
// LCOV_EXCL_START
|
|
12812
|
+
class OperatorState {
|
|
12477
12813
|
public:
|
|
12478
|
-
|
|
12479
|
-
|
|
12814
|
+
virtual ~OperatorState() {
|
|
12815
|
+
}
|
|
12480
12816
|
|
|
12481
|
-
|
|
12482
|
-
|
|
12483
|
-
bool finished;
|
|
12484
|
-
//! DataChunk that stores data from the child of this operator
|
|
12485
|
-
DataChunk child_chunk;
|
|
12486
|
-
//! State of the child of this operator
|
|
12487
|
-
unique_ptr<PhysicalOperatorState> child_state;
|
|
12817
|
+
virtual void Finalize(PhysicalOperator *op, ExecutionContext &context) {
|
|
12818
|
+
}
|
|
12488
12819
|
};
|
|
12489
12820
|
|
|
12821
|
+
class GlobalSinkState {
|
|
12822
|
+
public:
|
|
12823
|
+
GlobalSinkState() : state(SinkFinalizeType::READY) {
|
|
12824
|
+
}
|
|
12825
|
+
virtual ~GlobalSinkState() {
|
|
12826
|
+
}
|
|
12827
|
+
|
|
12828
|
+
SinkFinalizeType state;
|
|
12829
|
+
};
|
|
12830
|
+
|
|
12831
|
+
class LocalSinkState {
|
|
12832
|
+
public:
|
|
12833
|
+
virtual ~LocalSinkState() {
|
|
12834
|
+
}
|
|
12835
|
+
};
|
|
12836
|
+
|
|
12837
|
+
class GlobalSourceState {
|
|
12838
|
+
public:
|
|
12839
|
+
virtual ~GlobalSourceState() {
|
|
12840
|
+
}
|
|
12841
|
+
|
|
12842
|
+
virtual idx_t MaxThreads() {
|
|
12843
|
+
return 1;
|
|
12844
|
+
}
|
|
12845
|
+
};
|
|
12846
|
+
|
|
12847
|
+
class LocalSourceState {
|
|
12848
|
+
public:
|
|
12849
|
+
virtual ~LocalSourceState() {
|
|
12850
|
+
}
|
|
12851
|
+
};
|
|
12852
|
+
// LCOV_EXCL_STOP
|
|
12853
|
+
|
|
12490
12854
|
//! PhysicalOperator is the base class of the physical operators present in the
|
|
12491
12855
|
//! execution plan
|
|
12492
|
-
/*!
|
|
12493
|
-
The execution model is a pull-based execution model. GetChunk is called on
|
|
12494
|
-
the root node, which causes the root node to be executed, and presumably call
|
|
12495
|
-
GetChunk again on its child nodes. Every node in the operator chain has a
|
|
12496
|
-
state that is updated as GetChunk is called: PhysicalOperatorState (different
|
|
12497
|
-
operators subclass this state and add different properties).
|
|
12498
|
-
*/
|
|
12499
12856
|
class PhysicalOperator {
|
|
12500
12857
|
public:
|
|
12501
12858
|
PhysicalOperator(PhysicalOperatorType type, vector<LogicalType> types, idx_t estimated_cardinality)
|
|
@@ -12512,6 +12869,8 @@ public:
|
|
|
12512
12869
|
vector<LogicalType> types;
|
|
12513
12870
|
//! The extimated cardinality of this physical operator
|
|
12514
12871
|
idx_t estimated_cardinality;
|
|
12872
|
+
//! The global sink state of this operator
|
|
12873
|
+
unique_ptr<GlobalSinkState> sink_state;
|
|
12515
12874
|
|
|
12516
12875
|
public:
|
|
12517
12876
|
virtual string GetName() const;
|
|
@@ -12519,97 +12878,78 @@ public:
|
|
|
12519
12878
|
return "";
|
|
12520
12879
|
}
|
|
12521
12880
|
virtual string ToString() const;
|
|
12522
|
-
void Print();
|
|
12881
|
+
void Print() const;
|
|
12523
12882
|
|
|
12524
12883
|
//! Return a vector of the types that will be returned by this operator
|
|
12525
|
-
vector<LogicalType> &GetTypes() {
|
|
12884
|
+
const vector<LogicalType> &GetTypes() const {
|
|
12526
12885
|
return types;
|
|
12527
12886
|
}
|
|
12528
|
-
//! Initialize a given chunk to the types that will be returned by this
|
|
12529
|
-
//! operator, this will prepare chunk for a call to GetChunk. This method
|
|
12530
|
-
//! only has to be called once for any amount of calls to GetChunk.
|
|
12531
|
-
virtual void InitializeChunk(DataChunk &chunk) {
|
|
12532
|
-
auto &types = GetTypes();
|
|
12533
|
-
chunk.Initialize(types);
|
|
12534
|
-
}
|
|
12535
|
-
//! Retrieves a chunk from this operator and stores it in the chunk
|
|
12536
|
-
//! variable.
|
|
12537
|
-
virtual void GetChunkInternal(ExecutionContext &context, DataChunk &chunk, PhysicalOperatorState *state) const = 0;
|
|
12538
12887
|
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
//! Create a new empty instance of the operator state
|
|
12542
|
-
virtual unique_ptr<PhysicalOperatorState> GetOperatorState() {
|
|
12543
|
-
return make_unique<PhysicalOperatorState>(*this, children.size() == 0 ? nullptr : children[0].get());
|
|
12888
|
+
virtual bool Equals(const PhysicalOperator &other) const {
|
|
12889
|
+
return false;
|
|
12544
12890
|
}
|
|
12545
12891
|
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12892
|
+
public:
|
|
12893
|
+
// Operator interface
|
|
12894
|
+
virtual unique_ptr<OperatorState> GetOperatorState(ClientContext &context) const;
|
|
12895
|
+
virtual OperatorResultType Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
|
|
12896
|
+
OperatorState &state) const;
|
|
12551
12897
|
|
|
12552
|
-
virtual bool
|
|
12898
|
+
virtual bool ParallelOperator() const {
|
|
12553
12899
|
return false;
|
|
12554
12900
|
}
|
|
12555
|
-
};
|
|
12556
|
-
|
|
12557
|
-
} // namespace duckdb
|
|
12558
|
-
|
|
12559
12901
|
|
|
12560
|
-
|
|
12561
|
-
|
|
12562
|
-
class Pipeline;
|
|
12563
|
-
|
|
12564
|
-
class GlobalOperatorState {
|
|
12565
|
-
public:
|
|
12566
|
-
virtual ~GlobalOperatorState() {
|
|
12902
|
+
virtual bool RequiresCache() const {
|
|
12903
|
+
return false;
|
|
12567
12904
|
}
|
|
12568
|
-
};
|
|
12569
12905
|
|
|
12570
|
-
class LocalSinkState {
|
|
12571
12906
|
public:
|
|
12572
|
-
|
|
12573
|
-
|
|
12574
|
-
|
|
12907
|
+
// Source interface
|
|
12908
|
+
virtual unique_ptr<LocalSourceState> GetLocalSourceState(ExecutionContext &context,
|
|
12909
|
+
GlobalSourceState &gstate) const;
|
|
12910
|
+
virtual unique_ptr<GlobalSourceState> GetGlobalSourceState(ClientContext &context) const;
|
|
12911
|
+
virtual void GetData(ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate,
|
|
12912
|
+
LocalSourceState &lstate) const;
|
|
12575
12913
|
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
PhysicalSink(PhysicalOperatorType type, vector<LogicalType> types, idx_t estimated_cardinality)
|
|
12579
|
-
: PhysicalOperator(type, move(types), estimated_cardinality) {
|
|
12914
|
+
virtual bool IsSource() const {
|
|
12915
|
+
return false;
|
|
12580
12916
|
}
|
|
12581
12917
|
|
|
12582
|
-
|
|
12918
|
+
virtual bool ParallelSource() const {
|
|
12919
|
+
return false;
|
|
12920
|
+
}
|
|
12583
12921
|
|
|
12584
12922
|
public:
|
|
12923
|
+
// Sink interface
|
|
12924
|
+
|
|
12585
12925
|
//! The sink method is called constantly with new input, as long as new input is available. Note that this method
|
|
12586
|
-
//! CAN be called in parallel, proper locking is needed when accessing data inside the
|
|
12587
|
-
virtual
|
|
12588
|
-
|
|
12926
|
+
//! CAN be called in parallel, proper locking is needed when accessing data inside the GlobalSinkState.
|
|
12927
|
+
virtual SinkResultType Sink(ExecutionContext &context, GlobalSinkState &gstate, LocalSinkState &lstate,
|
|
12928
|
+
DataChunk &input) const;
|
|
12589
12929
|
// The combine is called when a single thread has completed execution of its part of the pipeline, it is the final
|
|
12590
12930
|
// time that a specific LocalSinkState is accessible. This method can be called in parallel while other Sink() or
|
|
12591
|
-
// Combine() calls are active on the same
|
|
12592
|
-
virtual void Combine(ExecutionContext &context,
|
|
12593
|
-
}
|
|
12931
|
+
// Combine() calls are active on the same GlobalSinkState.
|
|
12932
|
+
virtual void Combine(ExecutionContext &context, GlobalSinkState &gstate, LocalSinkState &lstate) const;
|
|
12594
12933
|
//! The finalize is called when ALL threads are finished execution. It is called only once per pipeline, and is
|
|
12595
12934
|
//! entirely single threaded.
|
|
12596
|
-
|
|
12597
|
-
|
|
12598
|
-
|
|
12599
|
-
}
|
|
12935
|
+
//! If Finalize returns SinkResultType::FINISHED, the sink is marked as finished
|
|
12936
|
+
virtual SinkFinalizeType Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
|
|
12937
|
+
GlobalSinkState &gstate) const;
|
|
12600
12938
|
|
|
12601
|
-
virtual unique_ptr<LocalSinkState> GetLocalSinkState(ExecutionContext &context)
|
|
12602
|
-
|
|
12603
|
-
|
|
12604
|
-
virtual
|
|
12605
|
-
return
|
|
12939
|
+
virtual unique_ptr<LocalSinkState> GetLocalSinkState(ExecutionContext &context) const;
|
|
12940
|
+
virtual unique_ptr<GlobalSinkState> GetGlobalSinkState(ClientContext &context) const;
|
|
12941
|
+
|
|
12942
|
+
virtual bool IsSink() const {
|
|
12943
|
+
return false;
|
|
12606
12944
|
}
|
|
12607
12945
|
|
|
12608
|
-
bool
|
|
12609
|
-
return
|
|
12946
|
+
virtual bool ParallelSink() const {
|
|
12947
|
+
return false;
|
|
12610
12948
|
}
|
|
12611
12949
|
|
|
12612
|
-
|
|
12950
|
+
virtual bool SinkOrderMatters() const {
|
|
12951
|
+
return false;
|
|
12952
|
+
}
|
|
12613
12953
|
};
|
|
12614
12954
|
|
|
12615
12955
|
} // namespace duckdb
|
|
@@ -12668,7 +13008,9 @@ typedef void (*table_function_cleanup_t)(ClientContext &context, const FunctionD
|
|
|
12668
13008
|
FunctionOperatorData *operator_state);
|
|
12669
13009
|
typedef idx_t (*table_function_max_threads_t)(ClientContext &context, const FunctionData *bind_data);
|
|
12670
13010
|
typedef unique_ptr<ParallelState> (*table_function_init_parallel_state_t)(ClientContext &context,
|
|
12671
|
-
const FunctionData *bind_data
|
|
13011
|
+
const FunctionData *bind_data,
|
|
13012
|
+
const vector<column_t> &column_ids,
|
|
13013
|
+
TableFilterCollection *filters);
|
|
12672
13014
|
typedef unique_ptr<FunctionOperatorData> (*table_function_init_parallel_t)(ClientContext &context,
|
|
12673
13015
|
const FunctionData *bind_data,
|
|
12674
13016
|
ParallelState *state,
|
|
@@ -12820,7 +13162,10 @@ struct ParallelState {
|
|
|
12820
13162
|
|
|
12821
13163
|
|
|
12822
13164
|
namespace duckdb {
|
|
13165
|
+
class ClientContext;
|
|
13166
|
+
class Executor;
|
|
12823
13167
|
|
|
13168
|
+
//! Generic parallel task
|
|
12824
13169
|
class Task {
|
|
12825
13170
|
public:
|
|
12826
13171
|
virtual ~Task() {
|
|
@@ -12830,6 +13175,21 @@ public:
|
|
|
12830
13175
|
virtual void Execute() = 0;
|
|
12831
13176
|
};
|
|
12832
13177
|
|
|
13178
|
+
//! Execute a task within an executor, including exception handling
|
|
13179
|
+
//! This should be used within queries
|
|
13180
|
+
class ExecutorTask : public Task {
|
|
13181
|
+
public:
|
|
13182
|
+
ExecutorTask(Executor &executor);
|
|
13183
|
+
ExecutorTask(ClientContext &context);
|
|
13184
|
+
virtual ~ExecutorTask();
|
|
13185
|
+
|
|
13186
|
+
Executor &executor;
|
|
13187
|
+
|
|
13188
|
+
public:
|
|
13189
|
+
virtual void ExecuteTask() = 0;
|
|
13190
|
+
void Execute() override;
|
|
13191
|
+
};
|
|
13192
|
+
|
|
12833
13193
|
} // namespace duckdb
|
|
12834
13194
|
|
|
12835
13195
|
|
|
@@ -12839,6 +13199,7 @@ namespace duckdb {
|
|
|
12839
13199
|
struct ConcurrentQueue;
|
|
12840
13200
|
struct QueueProducerToken;
|
|
12841
13201
|
class ClientContext;
|
|
13202
|
+
class DatabaseInstance;
|
|
12842
13203
|
class TaskScheduler;
|
|
12843
13204
|
|
|
12844
13205
|
struct SchedulerThread;
|
|
@@ -12862,6 +13223,7 @@ public:
|
|
|
12862
13223
|
~TaskScheduler();
|
|
12863
13224
|
|
|
12864
13225
|
static TaskScheduler &GetScheduler(ClientContext &context);
|
|
13226
|
+
static TaskScheduler &GetScheduler(DatabaseInstance &db);
|
|
12865
13227
|
|
|
12866
13228
|
unique_ptr<ProducerToken> CreateProducer();
|
|
12867
13229
|
//! Schedule a task to be executed by the task scheduler
|
|
@@ -12894,111 +13256,91 @@ private:
|
|
|
12894
13256
|
|
|
12895
13257
|
namespace duckdb {
|
|
12896
13258
|
class Executor;
|
|
12897
|
-
class
|
|
13259
|
+
class Event;
|
|
12898
13260
|
|
|
12899
13261
|
//! The Pipeline class represents an execution pipeline
|
|
12900
13262
|
class Pipeline : public std::enable_shared_from_this<Pipeline> {
|
|
12901
13263
|
friend class Executor;
|
|
13264
|
+
friend class PipelineExecutor;
|
|
13265
|
+
friend class PipelineEvent;
|
|
13266
|
+
friend class PipelineFinishEvent;
|
|
12902
13267
|
|
|
12903
13268
|
public:
|
|
12904
|
-
Pipeline(Executor &execution_context
|
|
13269
|
+
Pipeline(Executor &execution_context);
|
|
12905
13270
|
|
|
12906
13271
|
Executor &executor;
|
|
12907
|
-
ProducerToken &token;
|
|
12908
13272
|
|
|
12909
13273
|
public:
|
|
12910
|
-
|
|
12911
|
-
void Execute(TaskContext &task);
|
|
13274
|
+
ClientContext &GetClientContext();
|
|
12912
13275
|
|
|
12913
13276
|
void AddDependency(shared_ptr<Pipeline> &pipeline);
|
|
12914
|
-
void CompleteDependency();
|
|
12915
|
-
bool HasDependencies() {
|
|
12916
|
-
return !dependencies.empty();
|
|
12917
|
-
}
|
|
12918
13277
|
|
|
12919
|
-
void
|
|
12920
|
-
void
|
|
13278
|
+
void Ready();
|
|
13279
|
+
void Reset();
|
|
13280
|
+
void ResetSource();
|
|
13281
|
+
void Schedule(shared_ptr<Event> &event);
|
|
12921
13282
|
|
|
12922
|
-
//!
|
|
12923
|
-
void
|
|
12924
|
-
//! Finish executing this pipeline
|
|
12925
|
-
void Finish();
|
|
13283
|
+
//! Finalize this pipeline
|
|
13284
|
+
void Finalize(Event &event);
|
|
12926
13285
|
|
|
12927
13286
|
string ToString() const;
|
|
12928
13287
|
void Print() const;
|
|
12929
13288
|
|
|
12930
|
-
void SetRecursiveCTE(PhysicalOperator *op) {
|
|
12931
|
-
this->recursive_cte = op;
|
|
12932
|
-
}
|
|
12933
|
-
PhysicalOperator *GetRecursiveCTE() {
|
|
12934
|
-
return recursive_cte;
|
|
12935
|
-
}
|
|
12936
|
-
void ClearParents();
|
|
12937
|
-
|
|
12938
|
-
void IncrementTasks(idx_t amount) {
|
|
12939
|
-
this->total_tasks += amount;
|
|
12940
|
-
}
|
|
12941
|
-
|
|
12942
|
-
bool IsFinished() {
|
|
12943
|
-
return finished;
|
|
12944
|
-
}
|
|
12945
13289
|
//! Returns query progress
|
|
12946
13290
|
bool GetProgress(int ¤t_percentage);
|
|
12947
13291
|
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
12952
|
-
|
|
13292
|
+
//! Returns a list of all operators (including source and sink) involved in this pipeline
|
|
13293
|
+
vector<PhysicalOperator *> GetOperators() const;
|
|
13294
|
+
|
|
13295
|
+
PhysicalOperator *GetSink() {
|
|
13296
|
+
return sink;
|
|
13297
|
+
}
|
|
12953
13298
|
|
|
12954
13299
|
private:
|
|
12955
|
-
//!
|
|
12956
|
-
|
|
12957
|
-
//! The
|
|
12958
|
-
|
|
13300
|
+
//! Whether or not the pipeline has been readied
|
|
13301
|
+
bool ready;
|
|
13302
|
+
//! The source of this pipeline
|
|
13303
|
+
PhysicalOperator *source;
|
|
13304
|
+
//! The chain of intermediate operators
|
|
13305
|
+
vector<PhysicalOperator *> operators;
|
|
12959
13306
|
//! The sink (i.e. destination) for data; this is e.g. a hash table to-be-built
|
|
12960
|
-
|
|
13307
|
+
PhysicalOperator *sink;
|
|
13308
|
+
|
|
13309
|
+
//! The global source state
|
|
13310
|
+
unique_ptr<GlobalSourceState> source_state;
|
|
13311
|
+
|
|
12961
13312
|
//! The parent pipelines (i.e. pipelines that are dependent on this pipeline to finish)
|
|
12962
|
-
|
|
13313
|
+
vector<weak_ptr<Pipeline>> parents;
|
|
12963
13314
|
//! The dependencies of this pipeline
|
|
12964
|
-
|
|
12965
|
-
//! The amount of completed dependencies (the pipeline can only be started after the dependencies have finished
|
|
12966
|
-
//! executing)
|
|
12967
|
-
atomic<idx_t> finished_dependencies;
|
|
12968
|
-
|
|
12969
|
-
//! The parallel operator (if any)
|
|
12970
|
-
PhysicalOperator *parallel_node;
|
|
12971
|
-
//! The parallel state (if any)
|
|
12972
|
-
unique_ptr<ParallelState> parallel_state;
|
|
12973
|
-
|
|
12974
|
-
//! Whether or not the pipeline is finished executing
|
|
12975
|
-
bool finished;
|
|
12976
|
-
//! The recursive CTE node that this pipeline belongs to, and may be executed multiple times
|
|
12977
|
-
PhysicalOperator *recursive_cte;
|
|
13315
|
+
vector<weak_ptr<Pipeline>> dependencies;
|
|
12978
13316
|
|
|
12979
13317
|
private:
|
|
12980
|
-
bool
|
|
12981
|
-
void ScheduleSequentialTask();
|
|
12982
|
-
bool LaunchScanTasks(
|
|
12983
|
-
|
|
13318
|
+
bool GetProgressInternal(ClientContext &context, PhysicalOperator *op, int ¤t_percentage);
|
|
13319
|
+
void ScheduleSequentialTask(shared_ptr<Event> &event);
|
|
13320
|
+
bool LaunchScanTasks(shared_ptr<Event> &event, idx_t max_threads);
|
|
13321
|
+
|
|
13322
|
+
bool ScheduleParallel(shared_ptr<Event> &event);
|
|
12984
13323
|
};
|
|
12985
13324
|
|
|
12986
13325
|
} // namespace duckdb
|
|
12987
13326
|
|
|
12988
13327
|
|
|
12989
13328
|
|
|
12990
|
-
#include <queue>
|
|
12991
13329
|
|
|
12992
13330
|
namespace duckdb {
|
|
12993
13331
|
class ClientContext;
|
|
12994
13332
|
class DataChunk;
|
|
12995
13333
|
class PhysicalOperator;
|
|
12996
|
-
class
|
|
13334
|
+
class PipelineExecutor;
|
|
13335
|
+
class OperatorState;
|
|
12997
13336
|
class ThreadContext;
|
|
12998
13337
|
class Task;
|
|
12999
13338
|
|
|
13339
|
+
struct PipelineEventStack;
|
|
13000
13340
|
struct ProducerToken;
|
|
13001
13341
|
|
|
13342
|
+
using event_map_t = unordered_map<const Pipeline *, PipelineEventStack>;
|
|
13343
|
+
|
|
13002
13344
|
class Executor {
|
|
13003
13345
|
friend class Pipeline;
|
|
13004
13346
|
friend class PipelineTask;
|
|
@@ -13010,8 +13352,10 @@ public:
|
|
|
13010
13352
|
ClientContext &context;
|
|
13011
13353
|
|
|
13012
13354
|
public:
|
|
13355
|
+
static Executor &Get(ClientContext &context);
|
|
13356
|
+
|
|
13013
13357
|
void Initialize(PhysicalOperator *physical_plan);
|
|
13014
|
-
void BuildPipelines(PhysicalOperator *op, Pipeline *
|
|
13358
|
+
void BuildPipelines(PhysicalOperator *op, Pipeline *current);
|
|
13015
13359
|
|
|
13016
13360
|
void Reset();
|
|
13017
13361
|
|
|
@@ -13020,8 +13364,15 @@ public:
|
|
|
13020
13364
|
unique_ptr<DataChunk> FetchChunk();
|
|
13021
13365
|
|
|
13022
13366
|
//! Push a new error
|
|
13023
|
-
void PushError(const string &exception);
|
|
13024
|
-
|
|
13367
|
+
void PushError(ExceptionType type, const string &exception);
|
|
13368
|
+
//! True if an error has been thrown
|
|
13369
|
+
bool HasError();
|
|
13370
|
+
//! Throw the exception that was pushed using PushError.
|
|
13371
|
+
//! Should only be called if HasError returns true
|
|
13372
|
+
void ThrowException();
|
|
13373
|
+
|
|
13374
|
+
//! Work on tasks for this specific executor, until there are no tasks remaining
|
|
13375
|
+
void WorkOnTasks();
|
|
13025
13376
|
|
|
13026
13377
|
//! Flush a thread context into the client context
|
|
13027
13378
|
void Flush(ThreadContext &context);
|
|
@@ -13029,24 +13380,76 @@ public:
|
|
|
13029
13380
|
//! Returns the progress of the pipelines
|
|
13030
13381
|
bool GetPipelinesProgress(int ¤t_progress);
|
|
13031
13382
|
|
|
13383
|
+
void CompletePipeline() {
|
|
13384
|
+
completed_pipelines++;
|
|
13385
|
+
}
|
|
13386
|
+
ProducerToken &GetToken() {
|
|
13387
|
+
return *producer;
|
|
13388
|
+
}
|
|
13389
|
+
void AddEvent(shared_ptr<Event> event);
|
|
13390
|
+
|
|
13391
|
+
void ReschedulePipelines(const vector<shared_ptr<Pipeline>> &pipelines, vector<shared_ptr<Event>> &events);
|
|
13392
|
+
|
|
13393
|
+
private:
|
|
13394
|
+
void ScheduleEvents();
|
|
13395
|
+
void ScheduleEventsInternal(const vector<shared_ptr<Pipeline>> &pipelines,
|
|
13396
|
+
unordered_map<Pipeline *, vector<shared_ptr<Pipeline>>> &child_pipelines,
|
|
13397
|
+
vector<shared_ptr<Event>> &events, bool main_schedule = true);
|
|
13398
|
+
|
|
13399
|
+
void SchedulePipeline(const shared_ptr<Pipeline> &pipeline, event_map_t &event_map,
|
|
13400
|
+
vector<shared_ptr<Event>> &events, bool complete_pipeline);
|
|
13401
|
+
Pipeline *ScheduleUnionPipeline(const shared_ptr<Pipeline> &pipeline, const Pipeline *parent,
|
|
13402
|
+
event_map_t &event_map, vector<shared_ptr<Event>> &events);
|
|
13403
|
+
void ScheduleChildPipeline(Pipeline *parent, const shared_ptr<Pipeline> &pipeline, event_map_t &event_map,
|
|
13404
|
+
vector<shared_ptr<Event>> &events);
|
|
13405
|
+
void ExtractPipelines(shared_ptr<Pipeline> &pipeline, vector<shared_ptr<Pipeline>> &result);
|
|
13406
|
+
bool NextExecutor();
|
|
13407
|
+
|
|
13408
|
+
void AddChildPipeline(Pipeline *current);
|
|
13409
|
+
|
|
13410
|
+
void VerifyPipeline(Pipeline &pipeline);
|
|
13411
|
+
void VerifyPipelines();
|
|
13412
|
+
void ThrowExceptionInternal();
|
|
13413
|
+
|
|
13032
13414
|
private:
|
|
13033
13415
|
PhysicalOperator *physical_plan;
|
|
13034
|
-
unique_ptr<PhysicalOperatorState> physical_state;
|
|
13035
13416
|
|
|
13036
13417
|
mutex executor_lock;
|
|
13037
13418
|
//! The pipelines of the current query
|
|
13038
13419
|
vector<shared_ptr<Pipeline>> pipelines;
|
|
13420
|
+
//! The root pipeline of the query
|
|
13421
|
+
vector<shared_ptr<Pipeline>> root_pipelines;
|
|
13422
|
+
//! The pipeline executor for the root pipeline
|
|
13423
|
+
unique_ptr<PipelineExecutor> root_executor;
|
|
13424
|
+
//! The current root pipeline index
|
|
13425
|
+
idx_t root_pipeline_idx;
|
|
13039
13426
|
//! The producer of this query
|
|
13040
13427
|
unique_ptr<ProducerToken> producer;
|
|
13041
13428
|
//! Exceptions that occurred during the execution of the current query
|
|
13042
|
-
vector<string
|
|
13429
|
+
vector<pair<ExceptionType, string>> exceptions;
|
|
13430
|
+
//! List of events
|
|
13431
|
+
vector<shared_ptr<Event>> events;
|
|
13043
13432
|
|
|
13044
13433
|
//! The amount of completed pipelines of the query
|
|
13045
13434
|
atomic<idx_t> completed_pipelines;
|
|
13046
13435
|
//! The total amount of pipelines in the query
|
|
13047
13436
|
idx_t total_pipelines;
|
|
13048
13437
|
|
|
13438
|
+
//! The adjacent union pipelines of each pipeline
|
|
13439
|
+
//! Union pipelines have the same sink, but can be run concurrently along with this pipeline
|
|
13440
|
+
unordered_map<Pipeline *, vector<shared_ptr<Pipeline>>> union_pipelines;
|
|
13441
|
+
//! Child pipelines of this pipeline
|
|
13442
|
+
//! Like union pipelines, child pipelines share the same sink
|
|
13443
|
+
//! Unlike union pipelines, child pipelines should be run AFTER their dependencies are completed
|
|
13444
|
+
//! i.e. they should be run after the dependencies are completed, but before finalize is called on the sink
|
|
13445
|
+
unordered_map<Pipeline *, vector<shared_ptr<Pipeline>>> child_pipelines;
|
|
13446
|
+
//! Dependencies of child pipelines
|
|
13447
|
+
unordered_map<Pipeline *, vector<Pipeline *>> child_dependencies;
|
|
13448
|
+
|
|
13449
|
+
//! Duplicate eliminated join scan dependencies
|
|
13049
13450
|
unordered_map<PhysicalOperator *, Pipeline *> delim_join_dependencies;
|
|
13451
|
+
|
|
13452
|
+
//! Active recursive CTE node (if any)
|
|
13050
13453
|
PhysicalOperator *recursive_cte;
|
|
13051
13454
|
};
|
|
13052
13455
|
} // namespace duckdb
|
|
@@ -13065,7 +13468,7 @@ public:
|
|
|
13065
13468
|
//! Starts the thread
|
|
13066
13469
|
void Start();
|
|
13067
13470
|
//! Stops the thread
|
|
13068
|
-
void Stop();
|
|
13471
|
+
void Stop(bool success = true);
|
|
13069
13472
|
//! Gets current percentage
|
|
13070
13473
|
int GetCurrentPercentage();
|
|
13071
13474
|
|
|
@@ -13082,7 +13485,7 @@ private:
|
|
|
13082
13485
|
std::condition_variable c;
|
|
13083
13486
|
mutex m;
|
|
13084
13487
|
#endif
|
|
13085
|
-
idx_t show_progress_after;
|
|
13488
|
+
atomic<idx_t> show_progress_after;
|
|
13086
13489
|
idx_t time_update_bar;
|
|
13087
13490
|
atomic<int> current_percentage;
|
|
13088
13491
|
atomic<bool> stop;
|
|
@@ -13168,6 +13571,75 @@ private:
|
|
|
13168
13571
|
|
|
13169
13572
|
#include <random>
|
|
13170
13573
|
|
|
13574
|
+
//===----------------------------------------------------------------------===//
|
|
13575
|
+
// DuckDB
|
|
13576
|
+
//
|
|
13577
|
+
// duckdb/main/client_config.hpp
|
|
13578
|
+
//
|
|
13579
|
+
//
|
|
13580
|
+
//===----------------------------------------------------------------------===//
|
|
13581
|
+
|
|
13582
|
+
|
|
13583
|
+
|
|
13584
|
+
|
|
13585
|
+
|
|
13586
|
+
//===----------------------------------------------------------------------===//
|
|
13587
|
+
// DuckDB
|
|
13588
|
+
//
|
|
13589
|
+
// duckdb/common/enums/output_type.hpp
|
|
13590
|
+
//
|
|
13591
|
+
//
|
|
13592
|
+
//===----------------------------------------------------------------------===//
|
|
13593
|
+
|
|
13594
|
+
|
|
13595
|
+
|
|
13596
|
+
|
|
13597
|
+
|
|
13598
|
+
namespace duckdb {
|
|
13599
|
+
|
|
13600
|
+
enum class ExplainOutputType : uint8_t { ALL = 0, OPTIMIZED_ONLY = 1, PHYSICAL_ONLY = 2 };
|
|
13601
|
+
|
|
13602
|
+
} // namespace duckdb
|
|
13603
|
+
|
|
13604
|
+
|
|
13605
|
+
|
|
13606
|
+
namespace duckdb {
|
|
13607
|
+
class ClientContext;
|
|
13608
|
+
|
|
13609
|
+
struct ClientConfig {
|
|
13610
|
+
//! If the progress bar is enabled or not.
|
|
13611
|
+
bool enable_progress_bar = false;
|
|
13612
|
+
//! If the print of the progress bar is enabled
|
|
13613
|
+
bool print_progress_bar = true;
|
|
13614
|
+
//! The wait time before showing the progress bar
|
|
13615
|
+
int wait_time = 2000;
|
|
13616
|
+
|
|
13617
|
+
// Whether or not aggressive query verification is enabled
|
|
13618
|
+
bool query_verification_enabled = false;
|
|
13619
|
+
//! Enable the running of optimizers
|
|
13620
|
+
bool enable_optimizer = true;
|
|
13621
|
+
//! Force parallelism of small tables, used for testing
|
|
13622
|
+
bool verify_parallelism = false;
|
|
13623
|
+
//! Force index join independent of table cardinality, used for testing
|
|
13624
|
+
bool force_index_join = false;
|
|
13625
|
+
//! Force out-of-core computation for operators that support it, used for testing
|
|
13626
|
+
bool force_external = false;
|
|
13627
|
+
//! Maximum bits allowed for using a perfect hash table (i.e. the perfect HT can hold up to 2^perfect_ht_threshold
|
|
13628
|
+
//! elements)
|
|
13629
|
+
idx_t perfect_ht_threshold = 12;
|
|
13630
|
+
|
|
13631
|
+
//! The explain output type used when none is specified (default: PHYSICAL_ONLY)
|
|
13632
|
+
ExplainOutputType explain_output_type = ExplainOutputType::PHYSICAL_ONLY;
|
|
13633
|
+
|
|
13634
|
+
//! Generic options
|
|
13635
|
+
case_insensitive_map_t<Value> set_variables;
|
|
13636
|
+
|
|
13637
|
+
public:
|
|
13638
|
+
static ClientConfig &GetConfig(ClientContext &context);
|
|
13639
|
+
};
|
|
13640
|
+
|
|
13641
|
+
} // namespace duckdb
|
|
13642
|
+
|
|
13171
13643
|
|
|
13172
13644
|
namespace duckdb {
|
|
13173
13645
|
class Appender;
|
|
@@ -13212,35 +13684,12 @@ public:
|
|
|
13212
13684
|
|
|
13213
13685
|
//! The Progress Bar
|
|
13214
13686
|
unique_ptr<ProgressBar> progress_bar;
|
|
13215
|
-
//! If the progress bar is enabled or not.
|
|
13216
|
-
bool enable_progress_bar = false;
|
|
13217
|
-
//! If the print of the progress bar is enabled
|
|
13218
|
-
bool print_progress_bar = true;
|
|
13219
|
-
//! The wait time before showing the progress bar
|
|
13220
|
-
int wait_time = 2000;
|
|
13221
13687
|
|
|
13222
13688
|
unique_ptr<SchemaCatalogEntry> temporary_objects;
|
|
13223
13689
|
unordered_map<string, shared_ptr<PreparedStatementData>> prepared_statements;
|
|
13224
13690
|
|
|
13225
|
-
case_insensitive_map_t<Value> set_variables;
|
|
13226
|
-
|
|
13227
|
-
// Whether or not aggressive query verification is enabled
|
|
13228
|
-
bool query_verification_enabled = false;
|
|
13229
|
-
//! Enable the running of optimizers
|
|
13230
|
-
bool enable_optimizer = true;
|
|
13231
|
-
//! Force parallelism of small tables, used for testing
|
|
13232
|
-
bool verify_parallelism = false;
|
|
13233
|
-
//! Force index join independent of table cardinality, used for testing
|
|
13234
|
-
bool force_index_join = false;
|
|
13235
|
-
//! Force out-of-core computation for operators that support it, used for testing
|
|
13236
|
-
bool force_external = false;
|
|
13237
|
-
//! Maximum bits allowed for using a perfect hash table (i.e. the perfect HT can hold up to 2^perfect_ht_threshold
|
|
13238
|
-
//! elements)
|
|
13239
|
-
idx_t perfect_ht_threshold = 12;
|
|
13240
13691
|
//! The writer used to log queries (if logging is enabled)
|
|
13241
13692
|
unique_ptr<BufferedFileWriter> log_query_writer;
|
|
13242
|
-
//! The explain output type used when none is specified (default: PHYSICAL_ONLY)
|
|
13243
|
-
ExplainOutputType explain_output_type = ExplainOutputType::PHYSICAL_ONLY;
|
|
13244
13693
|
//! The random generator used by random(). Its seed value can be set by setseed().
|
|
13245
13694
|
std::mt19937 random_engine;
|
|
13246
13695
|
|
|
@@ -13248,6 +13697,9 @@ public:
|
|
|
13248
13697
|
|
|
13249
13698
|
unique_ptr<FileOpener> file_opener;
|
|
13250
13699
|
|
|
13700
|
+
//! The client configuration
|
|
13701
|
+
ClientConfig config;
|
|
13702
|
+
|
|
13251
13703
|
public:
|
|
13252
13704
|
DUCKDB_API Transaction &ActiveTransaction() {
|
|
13253
13705
|
return transaction.ActiveTransaction();
|