Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/duckdb/extension/core_functions/scalar/math/numeric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,9 @@ namespace {
struct FactorialOperator {
template <class TA, class TR>
static inline TR Operation(TA left) {
if (left < 0) {
throw OutOfRangeException("factorial of a negative number is undefined");
}
TR ret = 1;
for (TA i = 2; i <= left; i++) {
if (!TryMultiplyOperator::Operation(ret, TR(i), ret)) {
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/common/allocator/allocator_jemalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool Allocator::SupportsFlush() {
void Allocator::ThreadFlush(bool allocator_background_threads, idx_t threshold, idx_t thread_count) {
if (!allocator_background_threads) {
// We flush after exceeding the threshold
if (GetJemallocCTL<uint64_t>("thread.peak.read") > threshold) {
if (GetJemallocCTL<uint64_t>("thread.peak.read") <= threshold) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion src/duckdb/src/function/scalar/list/list_zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ static void ListZipFunction(DataChunk &args, ExpressionState &state, Vector &res
offset += len;
}
for (idx_t child_idx = 0; child_idx < args_size; child_idx++) {
if (args.data[child_idx].GetType() != LogicalType::SQLNULL) {
if (args.data[child_idx].GetType() == LogicalType::SQLNULL ||
ListVector::GetListSize(args.data[child_idx]) == 0) {
struct_entries[child_idx]->SetVectorType(VectorType::CONSTANT_VECTOR);
ConstantVector::SetNull(*struct_entries[child_idx], true);
} else {
struct_entries[child_idx]->Slice(ListVector::GetEntry(args.data[child_idx]), selections[child_idx],
result_size);
}
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "3-dev373"
#define DUCKDB_PATCH_VERSION "3"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 5
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.5.3-dev373"
#define DUCKDB_VERSION "v1.5.3"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "f1a6e65815"
#define DUCKDB_SOURCE_ID "14eca11bd9"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
3 changes: 3 additions & 0 deletions src/duckdb/src/include/duckdb/main/extension_entries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ static constexpr ExtensionFunctionEntry EXTENSION_FUNCTIONS[] = {
{"iceberg_metadata", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"iceberg_partition_stats", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"iceberg_scan", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"iceberg_schema_properties", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"iceberg_snapshots", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"iceberg_table_properties", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"iceberg_to_ducklake", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
Expand Down Expand Up @@ -571,6 +572,7 @@ static constexpr ExtensionFunctionEntry EXTENSION_FUNCTIONS[] = {
{"regr_sxx", "core_functions", CatalogType::AGGREGATE_FUNCTION_ENTRY},
{"regr_sxy", "core_functions", CatalogType::AGGREGATE_FUNCTION_ENTRY},
{"regr_syy", "core_functions", CatalogType::AGGREGATE_FUNCTION_ENTRY},
{"remove_iceberg_schema_properties", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"remove_iceberg_table_properties", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"repeat", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
{"replace", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
Expand All @@ -587,6 +589,7 @@ static constexpr ExtensionFunctionEntry EXTENSION_FUNCTIONS[] = {
{"rtrim", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
{"sem", "core_functions", CatalogType::AGGREGATE_FUNCTION_ENTRY},
{"set_bit", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
{"set_iceberg_schema_properties", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"set_iceberg_table_properties", "iceberg", CatalogType::TABLE_FUNCTION_ENTRY},
{"setseed", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
{"shapefile_meta", "spatial", CatalogType::TABLE_FUNCTION_ENTRY},
Expand Down
6 changes: 6 additions & 0 deletions src/duckdb/src/include/duckdb/storage/data_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ class DataTable : public enable_shared_from_this<DataTable> {

shared_ptr<DataTableInfo> &GetDataTableInfo();

//! Direct access to the row group collection. Intended for extensions that need to walk storage internals;
//! prefer the higher-level DataTable API for normal use.
const shared_ptr<RowGroupCollection> &GetRowGroupCollection() const {
return row_groups;
}

void BindIndexes(ClientContext &context);
bool HasIndexes() const;
bool HasUniqueIndexes() const;
Expand Down
4 changes: 4 additions & 0 deletions src/duckdb/src/include/duckdb/storage/table/row_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ class RowGroup : public SegmentBase<RowGroup> {

vector<MetaBlockPointer> CheckpointDeletes(RowGroupWriter &writer);

//! Direct accessors, fall outside of general use but can be useful to some extensions
ColumnData &GetRawColumnData(const StorageIndex &c) const;
ColumnData &GetRawColumnData(storage_t c) const;

private:
optional_ptr<RowVersionManager> GetVersionInfo();
optional_ptr<RowVersionManager> GetVersionInfoIfLoaded() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,13 @@ class RowGroupCollection {
//! Returns the total amount of segments - use sparingly, as this forces all segments to be loaded
idx_t GetSegmentCount();

//! Get a ptr to the raw segment tree. This can be useful for some extensions to have directly exposed.
shared_ptr<RowGroupSegmentTree> GetRowGroups() const;

private:
optional_ptr<SegmentNode<RowGroup>> NextUpdateRowGroup(RowGroupSegmentTree &row_groups, row_t *ids, idx_t &pos,
idx_t count) const;

shared_ptr<RowGroupSegmentTree> GetRowGroups() const;
void SetRowGroups(shared_ptr<RowGroupSegmentTree> row_groups);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class StandardColumnData : public ColumnData {
void Verify(RowGroup &parent) override;

void SetValidityData(shared_ptr<ValidityColumnData> validity);
//! Direct access to the validity column data. Intended for extensions that need to walk storage internals.
ValidityColumnData &GetValidityData();

protected:
//! The validity column data
Expand Down
11 changes: 5 additions & 6 deletions src/duckdb/src/main/connection_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@ void ConnectionManager::AssignConnectionId(Connection &connection) {
vector<shared_ptr<ClientContext>> ConnectionManager::GetConnectionList() {
lock_guard<mutex> lock(connections_lock);
vector<shared_ptr<ClientContext>> result;
for (auto &it : connections) {
auto connection = it.second.lock();
for (auto it = connections.begin(); it != connections.end();) {
auto connection = it->second.lock();
if (!connection) {
connections.erase(it.first);
connection_count = connections.size();
continue;
it = connections.erase(it);
} else {
result.push_back(std::move(connection));
++it;
}
}

connection_count = connections.size();
return result;
}

Expand Down
9 changes: 5 additions & 4 deletions src/duckdb/src/main/database_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,13 @@ shared_ptr<AttachedDatabase> DatabaseManager::AttachDatabase(ClientContext &cont

if (requires_tracking_attaches) {
// Start timing the ATTACH-delay step.
auto profiler = context.client_data->profiler->StartTimer(MetricType::WAITING_TO_ATTACH_LATENCY);

auto timer = context.client_data->profiler->StartTimer(MetricType::WAITING_TO_ATTACH_LATENCY);
// Start trying to attach.
while (InsertDatabasePath(info, options) == InsertDatabasePathResult::ALREADY_EXISTS) {
// database with this name and path already exists
// first check if it exists within this transaction
auto &meta_transaction = MetaTransaction::Get(context);
auto existing_db = meta_transaction.GetReferencedDatabaseOwning(info.name);
if (existing_db) {
if (auto existing_db = meta_transaction.GetReferencedDatabaseOwning(info.name)) {
// it does! return it
return existing_db;
}
Expand All @@ -171,6 +170,8 @@ shared_ptr<AttachedDatabase> DatabaseManager::AttachDatabase(ClientContext &cont
throw InterruptException();
}
}
// Returning in the loop above will also end the timer, otherwise, do it explicitly here.
timer.EndTimer();
}
auto &config = DBConfig::GetConfig(context);
GetDatabaseType(context, info, config, options);
Expand Down
3 changes: 1 addition & 2 deletions src/duckdb/src/optimizer/row_group_pruner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ bool RowGroupPruner::TryOptimize(LogicalOperator &op) const {

void RowGroupPruner::GetLimitAndOffset(const LogicalLimit &logical_limit, optional_idx &row_limit,
optional_idx &row_offset) const {
// UNSET = no LIMIT = unbounded; leave row_limit invalid.
if (logical_limit.limit_val.Type() == LimitNodeType::CONSTANT_VALUE) {
row_limit = logical_limit.limit_val.GetConstantValue();
} else if (logical_limit.limit_val.Type() == LimitNodeType::UNSET) {
row_limit = 0;
}

if (logical_limit.offset_val.Type() == LimitNodeType::CONSTANT_VALUE) {
Expand Down
5 changes: 3 additions & 2 deletions src/duckdb/src/storage/data_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1821,12 +1821,13 @@ void DataTable::Checkpoint(TableDataWriter &writer, Serializer &serializer) {
row_groups->Checkpoint(writer, global_stats);
row_groups->SetRowGroupAppendMode(RowGroupAppendMode::SUGGEST_NEW);
if (writer.GetRebuildIndexes()) {
ActiveTimer rebuild_indexes_timer;
ActiveTimer timer;
auto context = writer.TryGetClientContext();
if (context) {
rebuild_indexes_timer = QueryProfiler::Get(*context).StartTimer(MetricType::CUMULATIVE_VACUUM_TIME);
timer = QueryProfiler::Get(*context).StartTimer(MetricType::CUMULATIVE_VACUUM_TIME);
}
RebuildIndexes();
timer.EndTimer();
}
// The row group payload data has been written. Now write:
// sample
Expand Down
13 changes: 5 additions & 8 deletions src/duckdb/src/storage/storage_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,8 @@ void SingleFileStorageManager::LoadDatabase(QueryContext context) {
auto checkpoint_reader = SingleFileCheckpointReader(*this);
checkpoint_reader.LoadFromStorage();

// End timing the storage load step.
// Reset the timer (also ends it).
if (timer) {
timer->EndTimer();
timer = nullptr;
}

Expand All @@ -518,10 +517,7 @@ void SingleFileStorageManager::LoadDatabase(QueryContext context) {
wal_path = GetWALPath();
wal = WriteAheadLog::Replay(context, *this, wal_path);

// End timing the WAL replay step.
if (timer) {
timer->EndTimer();
}
// Timer will go out of scope here, if set.
}

if (row_group_size > 122880ULL && GetStorageVersion() < 4) {
Expand Down Expand Up @@ -697,14 +693,15 @@ void SingleFileStorageManager::CreateCheckpoint(QueryContext context, Checkpoint
try {
// Start timing the checkpoint.
auto client_context = context.GetClientContext();
ActiveTimer profiler;
ActiveTimer timer;
if (client_context) {
profiler = client_context->client_data->profiler->StartTimer(MetricType::CHECKPOINT_LATENCY);
timer = client_context->client_data->profiler->StartTimer(MetricType::CHECKPOINT_LATENCY);
}

// Write the checkpoint.
auto checkpointer = CreateCheckpointWriter(context, options);
checkpointer->CreateCheckpoint();
timer.EndTimer();

} catch (std::exception &ex) {
ErrorData error(ex);
Expand Down
8 changes: 8 additions & 0 deletions src/duckdb/src/storage/table/row_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ ColumnData &RowGroup::GetColumn(storage_t c) const {
return c == COLUMN_IDENTIFIER_ROW_ID ? *row_id_column_data : *columns[c];
}

ColumnData &RowGroup::GetRawColumnData(const StorageIndex &c) const {
return GetColumn(c);
}

ColumnData &RowGroup::GetRawColumnData(storage_t c) const {
return GetColumn(c);
}

void RowGroup::LoadColumn(storage_t c) const {
if (c == COLUMN_IDENTIFIER_ROW_ID) {
LoadRowIdColumnData();
Expand Down
12 changes: 8 additions & 4 deletions src/duckdb/src/storage/table/row_group_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,14 +1200,16 @@ class VacuumTask : public BaseCheckpointTask {
}

void ExecuteTask() override {
ActiveTimer vacuum_task_timer;
ActiveTimer timer;
auto context = checkpoint_state.writer.TryGetClientContext();
if (context) {
vacuum_task_timer = QueryProfiler::Get(*context).StartTimer(MetricType::CUMULATIVE_VACUUM_TIME);
timer = QueryProfiler::Get(*context).StartTimer(MetricType::CUMULATIVE_VACUUM_TIME);
}

auto &collection = checkpoint_state.collection;
const idx_t row_group_size = collection.GetRowGroupSize();
auto &types = collection.GetTypes();

// create the new set of target row groups (initially empty)
vector<unique_ptr<RowGroup>> new_row_groups;
vector<idx_t> append_counts;
Expand All @@ -1218,7 +1220,6 @@ class VacuumTask : public BaseCheckpointTask {
new_row_group->InitializeEmpty(types, ColumnDataType::MAIN_TABLE);
new_row_groups.push_back(std::move(new_row_group));
append_counts.push_back(0);

row_group_rows -= current_row_group_rows;
}

Expand Down Expand Up @@ -1301,7 +1302,10 @@ class VacuumTask : public BaseCheckpointTask {
"Mismatch in row group count %d vs verify count %d in RowGroupCollection::Checkpoint", merge_rows,
total_append_count);
}
vacuum_task_timer.EndTimer();

// Explicitly end the timer for the vacuum tasks here.
timer.EndTimer();

// merging is complete - execute checkpoint tasks of the target row groups
for (idx_t i = 0; i < target_count; i++) {
auto checkpoint_task = collection.GetCheckpointTask(checkpoint_state, segment_idx + i);
Expand Down
5 changes: 5 additions & 0 deletions src/duckdb/src/storage/table/standard_column_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ void StandardColumnData::SetValidityData(shared_ptr<ValidityColumnData> validity
this->validity = std::move(validity_p);
}

ValidityColumnData &StandardColumnData::GetValidityData() {
D_ASSERT(validity);
return *validity;
}

struct StandardColumnCheckpointState : public ColumnCheckpointState {
StandardColumnCheckpointState(const RowGroup &row_group, ColumnData &column_data,
PartialBlockManager &partial_block_manager)
Expand Down
4 changes: 3 additions & 1 deletion src/duckdb/src/transaction/duck_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ ErrorData DuckTransaction::WriteToWAL(ClientContext &context, AttachedDatabase &
commit_state = storage_manager.GenStorageCommitState(*wal);

auto &profiler = *context.client_data->profiler;

auto commit_timer = profiler.StartTimer(MetricType::COMMIT_LOCAL_STORAGE_LATENCY);
storage->Commit(commit_state.get());
commit_timer.EndTimer();

auto wal_timer = profiler.StartTimer(MetricType::WRITE_TO_WAL_LATENCY);
undo_buffer.WriteToWAL(*wal, commit_state.get());
Expand All @@ -233,6 +233,8 @@ ErrorData DuckTransaction::WriteToWAL(ClientContext &context, AttachedDatabase &
// hence we need to ensure those optimistically written blocks are persisted
storage_manager.GetBlockManager().FileSync();
}
wal_timer.EndTimer();

} catch (std::exception &ex) {
// Call RevertCommit() outside this try-catch as it itself may throw
error_data = ErrorData(ex);
Expand Down
12 changes: 6 additions & 6 deletions src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,17 @@

#include "extension/icu/third_party/icu/i18n/wintzimpl.cpp"

#include "extension/icu/third_party/icu/i18n/double-conversion-string-to-double.cpp"

#include "extension/icu/third_party/icu/i18n/double-conversion-cached-powers.cpp"

#include "extension/icu/third_party/icu/i18n/double-conversion-string-to-double.cpp"
#include "extension/icu/third_party/icu/i18n/double-conversion-fast-dtoa.cpp"

#include "extension/icu/third_party/icu/i18n/double-conversion-double-to-string.cpp"
#include "extension/icu/third_party/icu/i18n/double-conversion-bignum.cpp"

#include "extension/icu/third_party/icu/i18n/double-conversion-bignum-dtoa.cpp"
#include "extension/icu/third_party/icu/i18n/double-conversion-double-to-string.cpp"

#include "extension/icu/third_party/icu/i18n/double-conversion-strtod.cpp"

#include "extension/icu/third_party/icu/i18n/double-conversion-bignum.cpp"

#include "extension/icu/third_party/icu/i18n/double-conversion-fast-dtoa.cpp"
#include "extension/icu/third_party/icu/i18n/double-conversion-bignum-dtoa.cpp"

Loading