Skip to content

Commit 1f6bcda

Browse files
duckdblabs-botgithub-actions[bot]
authored andcommitted
Update vendored DuckDB sources to 73c0d0db15
1 parent 05ac6e5 commit 1f6bcda

File tree

26 files changed

+414
-115
lines changed

26 files changed

+414
-115
lines changed

src/duckdb/src/common/enum_util.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#include "duckdb/execution/index/art/art_scanner.hpp"
101101
#include "duckdb/execution/index/art/node.hpp"
102102
#include "duckdb/execution/index/bound_index.hpp"
103+
#include "duckdb/execution/index/unbound_index.hpp"
103104
#include "duckdb/execution/operator/csv_scanner/csv_option.hpp"
104105
#include "duckdb/execution/operator/csv_scanner/csv_state.hpp"
105106
#include "duckdb/execution/reservoir_sample.hpp"
@@ -707,6 +708,24 @@ BlockState EnumUtil::FromString<BlockState>(const char *value) {
707708
return static_cast<BlockState>(StringUtil::StringToEnum(GetBlockStateValues(), 2, "BlockState", value));
708709
}
709710

711+
const StringUtil::EnumStringLiteral *GetBufferedIndexReplayValues() {
712+
static constexpr StringUtil::EnumStringLiteral values[] {
713+
{ static_cast<uint32_t>(BufferedIndexReplay::INSERT_ENTRY), "INSERT_ENTRY" },
714+
{ static_cast<uint32_t>(BufferedIndexReplay::DEL_ENTRY), "DEL_ENTRY" }
715+
};
716+
return values;
717+
}
718+
719+
template<>
720+
const char* EnumUtil::ToChars<BufferedIndexReplay>(BufferedIndexReplay value) {
721+
return StringUtil::EnumToString(GetBufferedIndexReplayValues(), 2, "BufferedIndexReplay", static_cast<uint32_t>(value));
722+
}
723+
724+
template<>
725+
BufferedIndexReplay EnumUtil::FromString<BufferedIndexReplay>(const char *value) {
726+
return static_cast<BufferedIndexReplay>(StringUtil::StringToEnum(GetBufferedIndexReplayValues(), 2, "BufferedIndexReplay", value));
727+
}
728+
710729
const StringUtil::EnumStringLiteral *GetCAPIResultSetTypeValues() {
711730
static constexpr StringUtil::EnumStringLiteral values[] {
712731
{ static_cast<uint32_t>(CAPIResultSetType::CAPI_RESULT_TYPE_NONE), "CAPI_RESULT_TYPE_NONE" },

src/duckdb/src/common/enums/compression_type.cpp

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,60 @@ vector<string> ListCompressionTypes(void) {
1717
return compression_types;
1818
}
1919

20-
bool CompressionTypeIsDeprecated(CompressionType compression_type, optional_ptr<StorageManager> storage_manager) {
21-
vector<CompressionType> types({CompressionType::COMPRESSION_PATAS, CompressionType::COMPRESSION_CHIMP});
22-
if (storage_manager) {
23-
if (storage_manager->GetStorageVersion() >= 5) {
24-
//! NOTE: storage_manager is an optional_ptr because it's called from ForceCompressionSetting, which doesn't
25-
//! have guaranteed access to a StorageManager The introduction of DICT_FSST deprecates Dictionary and FSST
26-
//! compression methods
27-
types.emplace_back(CompressionType::COMPRESSION_DICTIONARY);
28-
types.emplace_back(CompressionType::COMPRESSION_FSST);
29-
} else {
30-
types.emplace_back(CompressionType::COMPRESSION_DICT_FSST);
31-
}
20+
namespace {
21+
struct CompressionMethodRequirements {
22+
CompressionType type;
23+
optional_idx minimum_storage_version;
24+
optional_idx maximum_storage_version;
25+
};
26+
} // namespace
27+
28+
CompressionAvailabilityResult CompressionTypeIsAvailable(CompressionType compression_type,
29+
optional_ptr<StorageManager> storage_manager) {
30+
//! Max storage compatibility
31+
vector<CompressionMethodRequirements> candidates({{CompressionType::COMPRESSION_PATAS, optional_idx(), 0},
32+
{CompressionType::COMPRESSION_CHIMP, optional_idx(), 0},
33+
{CompressionType::COMPRESSION_DICTIONARY, 0, 4},
34+
{CompressionType::COMPRESSION_FSST, 0, 4},
35+
{CompressionType::COMPRESSION_DICT_FSST, 5, optional_idx()}});
36+
37+
optional_idx current_storage_version;
38+
if (storage_manager && storage_manager->HasStorageVersion()) {
39+
current_storage_version = storage_manager->GetStorageVersion();
3240
}
33-
for (auto &type : types) {
34-
if (type == compression_type) {
35-
return true;
41+
for (auto &candidate : candidates) {
42+
auto &type = candidate.type;
43+
if (type != compression_type) {
44+
continue;
45+
}
46+
auto &min = candidate.minimum_storage_version;
47+
auto &max = candidate.maximum_storage_version;
48+
49+
if (!min.IsValid()) {
50+
//! Used to signal: always deprecated
51+
return CompressionAvailabilityResult::Deprecated();
52+
}
53+
54+
if (!current_storage_version.IsValid()) {
55+
//! Can't determine in this call whether it's available or not, default to available
56+
return CompressionAvailabilityResult();
57+
}
58+
59+
auto current_version = current_storage_version.GetIndex();
60+
D_ASSERT(min.IsValid());
61+
if (min.GetIndex() > current_version) {
62+
//! Minimum required storage version is higher than the current storage version, this method isn't available
63+
//! yet
64+
return CompressionAvailabilityResult::NotAvailableYet();
65+
}
66+
if (max.IsValid() && max.GetIndex() < current_version) {
67+
//! Maximum supported storage version is lower than the current storage version, this method is no longer
68+
//! available
69+
return CompressionAvailabilityResult::Deprecated();
3670
}
71+
return CompressionAvailabilityResult();
3772
}
38-
return false;
73+
return CompressionAvailabilityResult();
3974
}
4075

4176
CompressionType CompressionTypeFromString(const string &str) {

src/duckdb/src/common/exception/binder_exception.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ BinderException BinderException::ColumnNotFound(const string &name, const vector
1818
extra_info["name"] = name;
1919
if (!similar_bindings.empty()) {
2020
extra_info["candidates"] = StringUtil::Join(similar_bindings, ",");
21+
return BinderException(
22+
StringUtil::Format("Referenced column \"%s\" not found in FROM clause!%s", name, candidate_str),
23+
extra_info);
24+
} else {
25+
return BinderException(
26+
StringUtil::Format("Referenced column \"%s\" was not found because the FROM clause is missing", name),
27+
extra_info);
2128
}
22-
return BinderException(
23-
StringUtil::Format("Referenced column \"%s\" not found in FROM clause!%s", name, candidate_str), extra_info);
2429
}
2530

2631
BinderException BinderException::NoMatchingFunction(const string &catalog_name, const string &schema_name,

src/duckdb/src/execution/index/art/art.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,9 @@ ErrorData ART::Insert(IndexLock &l, DataChunk &chunk, Vector &row_ids, IndexAppe
522522
if (keys[i].Empty()) {
523523
continue;
524524
}
525-
D_ASSERT(ARTOperator::Lookup(*this, tree, keys[i], 0));
525+
auto leaf = ARTOperator::Lookup(*this, tree, keys[i], 0);
526+
D_ASSERT(leaf);
527+
D_ASSERT(ARTOperator::LookupInLeaf(*this, *leaf, row_id_keys[i]));
526528
}
527529
#endif
528530
return ErrorData();
@@ -602,8 +604,9 @@ void ART::Delete(IndexLock &state, DataChunk &input, Vector &row_ids) {
602604
continue;
603605
}
604606
auto leaf = ARTOperator::Lookup(*this, tree, keys[i], 0);
605-
if (leaf && leaf->GetType() == NType::LEAF_INLINED) {
606-
D_ASSERT(leaf->GetRowId() != row_id_keys[i].GetRowId());
607+
if (leaf) {
608+
auto contains_row_id = ARTOperator::LookupInLeaf(*this, *leaf, row_id_keys[i]);
609+
D_ASSERT(!contains_row_id);
607610
}
608611
}
609612
#endif

src/duckdb/src/execution/index/bound_index.cpp

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -154,28 +154,39 @@ string BoundIndex::AppendRowError(DataChunk &input, idx_t index) {
154154
return error;
155155
}
156156

157-
void BoundIndex::ApplyBufferedAppends(const vector<LogicalType> &table_types, ColumnDataCollection &buffered_appends,
157+
void BoundIndex::ApplyBufferedReplays(const vector<LogicalType> &table_types,
158+
vector<BufferedIndexData> &buffered_replays,
158159
const vector<StorageIndex> &mapped_column_ids) {
159-
IndexAppendInfo index_append_info(IndexAppendMode::INSERT_DUPLICATES, nullptr);
160-
161-
ColumnDataScanState state;
162-
buffered_appends.InitializeScan(state);
163-
164-
DataChunk scan_chunk;
165-
buffered_appends.InitializeScanChunk(scan_chunk);
166-
DataChunk table_chunk;
167-
table_chunk.InitializeEmpty(table_types);
168-
169-
while (buffered_appends.Scan(state, scan_chunk)) {
170-
for (idx_t i = 0; i < scan_chunk.ColumnCount() - 1; i++) {
171-
auto col_id = mapped_column_ids[i].GetPrimaryIndex();
172-
table_chunk.data[col_id].Reference(scan_chunk.data[i]);
173-
}
174-
table_chunk.SetCardinality(scan_chunk.size());
175-
176-
auto error = Append(table_chunk, scan_chunk.data.back(), index_append_info);
177-
if (error.HasError()) {
178-
throw InternalException("error while applying buffered appends: " + error.Message());
160+
for (auto &replay : buffered_replays) {
161+
ColumnDataScanState state;
162+
auto &buffered_data = *replay.data;
163+
buffered_data.InitializeScan(state);
164+
165+
DataChunk scan_chunk;
166+
buffered_data.InitializeScanChunk(scan_chunk);
167+
DataChunk table_chunk;
168+
table_chunk.InitializeEmpty(table_types);
169+
170+
while (buffered_data.Scan(state, scan_chunk)) {
171+
for (idx_t i = 0; i < scan_chunk.ColumnCount() - 1; i++) {
172+
auto col_id = mapped_column_ids[i].GetPrimaryIndex();
173+
table_chunk.data[col_id].Reference(scan_chunk.data[i]);
174+
}
175+
table_chunk.SetCardinality(scan_chunk.size());
176+
177+
switch (replay.type) {
178+
case BufferedIndexReplay::INSERT_ENTRY: {
179+
IndexAppendInfo index_append_info(IndexAppendMode::INSERT_DUPLICATES, nullptr);
180+
auto error = Append(table_chunk, scan_chunk.data.back(), index_append_info);
181+
if (error.HasError()) {
182+
throw InternalException("error while applying buffered appends: " + error.Message());
183+
}
184+
continue;
185+
}
186+
case BufferedIndexReplay::DEL_ENTRY: {
187+
Delete(table_chunk, scan_chunk.data.back());
188+
}
189+
}
179190
}
180191
}
181192
}

src/duckdb/src/execution/index/unbound_index.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
namespace duckdb {
1010

11+
BufferedIndexData::BufferedIndexData(BufferedIndexReplay replay_type, unique_ptr<ColumnDataCollection> data_p)
12+
: type(replay_type), data(std::move(data_p)) {
13+
}
14+
1115
UnboundIndex::UnboundIndex(unique_ptr<CreateInfo> create_info, IndexStorageInfo storage_info_p,
1216
TableIOManager &table_io_manager, AttachedDatabase &db)
1317
: Index(create_info->Cast<CreateIndexInfo>().column_ids, table_io_manager, db), create_info(std::move(create_info)),
@@ -35,26 +39,33 @@ void UnboundIndex::CommitDrop() {
3539
}
3640
}
3741

38-
void UnboundIndex::BufferChunk(DataChunk &chunk, Vector &row_ids, const vector<StorageIndex> &mapped_column_ids_p) {
42+
void UnboundIndex::BufferChunk(DataChunk &index_column_chunk, Vector &row_ids,
43+
const vector<StorageIndex> &mapped_column_ids_p, BufferedIndexReplay replay_type) {
3944
D_ASSERT(!column_ids.empty());
40-
auto types = chunk.GetTypes();
45+
auto types = index_column_chunk.GetTypes(); // column types
4146
types.push_back(LogicalType::ROW_TYPE);
4247

43-
if (!buffered_appends) {
44-
auto &allocator = Allocator::Get(db);
45-
buffered_appends = make_uniq<ColumnDataCollection>(allocator, types);
48+
auto &allocator = Allocator::Get(db);
49+
50+
BufferedIndexData buffered_data(replay_type, make_uniq<ColumnDataCollection>(allocator, types));
51+
52+
//! First time we are buffering data, canonical column_id mapping is stored.
53+
//! This should be a sorted list of all the physical offsets of Indexed columns on this table.
54+
if (mapped_column_ids.empty()) {
4655
mapped_column_ids = mapped_column_ids_p;
4756
}
4857
D_ASSERT(mapped_column_ids == mapped_column_ids_p);
4958

59+
// Combined chunk has all the indexed columns and rowids.
5060
DataChunk combined_chunk;
5161
combined_chunk.InitializeEmpty(types);
52-
for (idx_t i = 0; i < chunk.ColumnCount(); i++) {
53-
combined_chunk.data[i].Reference(chunk.data[i]);
62+
for (idx_t i = 0; i < index_column_chunk.ColumnCount(); i++) {
63+
combined_chunk.data[i].Reference(index_column_chunk.data[i]);
5464
}
5565
combined_chunk.data.back().Reference(row_ids);
56-
combined_chunk.SetCardinality(chunk.size());
57-
buffered_appends->Append(combined_chunk);
66+
combined_chunk.SetCardinality(index_column_chunk.size());
67+
buffered_data.data->Append(combined_chunk);
68+
buffered_replays.emplace_back(std::move(buffered_data));
5869
}
5970

6071
} // namespace duckdb

src/duckdb/src/function/table/version/pragma_version.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef DUCKDB_PATCH_VERSION
2-
#define DUCKDB_PATCH_VERSION "2-dev199"
2+
#define DUCKDB_PATCH_VERSION "2-dev241"
33
#endif
44
#ifndef DUCKDB_MINOR_VERSION
55
#define DUCKDB_MINOR_VERSION 4
@@ -8,10 +8,10 @@
88
#define DUCKDB_MAJOR_VERSION 1
99
#endif
1010
#ifndef DUCKDB_VERSION
11-
#define DUCKDB_VERSION "v1.4.2-dev199"
11+
#define DUCKDB_VERSION "v1.4.2-dev241"
1212
#endif
1313
#ifndef DUCKDB_SOURCE_ID
14-
#define DUCKDB_SOURCE_ID "9ea6e07a29"
14+
#define DUCKDB_SOURCE_ID "73c0d0db15"
1515
#endif
1616
#include "duckdb/function/table/system_functions.hpp"
1717
#include "duckdb/main/database.hpp"

src/duckdb/src/include/duckdb/common/enum_util.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ enum class BlockIteratorStateType : int8_t;
8686

8787
enum class BlockState : uint8_t;
8888

89+
enum class BufferedIndexReplay : uint8_t;
90+
8991
enum class CAPIResultSetType : uint8_t;
9092

9193
enum class CSVState : uint8_t;
@@ -528,6 +530,9 @@ const char* EnumUtil::ToChars<BlockIteratorStateType>(BlockIteratorStateType val
528530
template<>
529531
const char* EnumUtil::ToChars<BlockState>(BlockState value);
530532

533+
template<>
534+
const char* EnumUtil::ToChars<BufferedIndexReplay>(BufferedIndexReplay value);
535+
531536
template<>
532537
const char* EnumUtil::ToChars<CAPIResultSetType>(CAPIResultSetType value);
533538

@@ -1150,6 +1155,9 @@ BlockIteratorStateType EnumUtil::FromString<BlockIteratorStateType>(const char *
11501155
template<>
11511156
BlockState EnumUtil::FromString<BlockState>(const char *value);
11521157

1158+
template<>
1159+
BufferedIndexReplay EnumUtil::FromString<BufferedIndexReplay>(const char *value);
1160+
11531161
template<>
11541162
CAPIResultSetType EnumUtil::FromString<CAPIResultSetType>(const char *value);
11551163

src/duckdb/src/include/duckdb/common/enums/compression_type.hpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,48 @@ enum class CompressionType : uint8_t {
3636
COMPRESSION_COUNT // This has to stay the last entry of the type!
3737
};
3838

39-
bool CompressionTypeIsDeprecated(CompressionType compression_type,
40-
optional_ptr<StorageManager> storage_manager = nullptr);
39+
struct CompressionAvailabilityResult {
40+
private:
41+
enum class UnavailableReason : uint8_t {
42+
AVAILABLE,
43+
//! Introduced later, not available to this version
44+
NOT_AVAILABLE_YET,
45+
//! Used to be available, but isnt anymore
46+
DEPRECATED
47+
};
48+
49+
public:
50+
CompressionAvailabilityResult() = default;
51+
static CompressionAvailabilityResult Deprecated() {
52+
return CompressionAvailabilityResult(UnavailableReason::DEPRECATED);
53+
}
54+
static CompressionAvailabilityResult NotAvailableYet() {
55+
return CompressionAvailabilityResult(UnavailableReason::NOT_AVAILABLE_YET);
56+
}
57+
58+
public:
59+
bool IsAvailable() const {
60+
return reason == UnavailableReason::AVAILABLE;
61+
}
62+
bool IsDeprecated() {
63+
D_ASSERT(!IsAvailable());
64+
return reason == UnavailableReason::DEPRECATED;
65+
}
66+
bool IsNotAvailableYet() {
67+
D_ASSERT(!IsAvailable());
68+
return reason == UnavailableReason::NOT_AVAILABLE_YET;
69+
}
70+
71+
private:
72+
explicit CompressionAvailabilityResult(UnavailableReason reason) : reason(reason) {
73+
}
74+
75+
public:
76+
UnavailableReason reason = UnavailableReason::AVAILABLE;
77+
};
78+
79+
CompressionAvailabilityResult CompressionTypeIsAvailable(CompressionType compression_type,
80+
optional_ptr<StorageManager> storage_manager = nullptr);
4181
vector<string> ListCompressionTypes(void);
4282
CompressionType CompressionTypeFromString(const string &str);
4383
string CompressionTypeToString(CompressionType type);

0 commit comments

Comments
 (0)