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
13 changes: 9 additions & 4 deletions src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ namespace duckdb {
void ViewCatalogEntry::Initialize(CreateViewInfo &info) {
query = std::move(info.query);
this->aliases = info.aliases;
if (!info.types.empty() && !info.names.empty()) {
if (!info.types.empty()) {
bind_state = ViewBindState::BOUND;
view_columns = make_shared_ptr<ViewColumnInfo>();
view_columns->types = info.types;
view_columns->names = info.names;
if (info.types.size() != info.names.size()) {
throw InternalException("Error creating view %s - view types / names size mismatch (%d types, %d names)",
name, info.types.size(), info.names.size());
if (view_columns->names.empty()) {
// DuckDB v0.9.2 and below store their names in the "aliases" field
view_columns->names = info.aliases;
}
if (view_columns->types.size() != view_columns->names.size()) {
throw InvalidInputException(
"Error creating view %s - view types / names size mismatch (%d types, %d names)", name,
view_columns->types.size(), view_columns->names.size());
}
}
this->temporary = info.temporary;
Expand Down
19 changes: 0 additions & 19 deletions src/duckdb/src/common/enum_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,25 +1169,6 @@ CompressedMaterializationDirection EnumUtil::FromString<CompressedMaterializatio
return static_cast<CompressedMaterializationDirection>(StringUtil::StringToEnum(GetCompressedMaterializationDirectionValues(), 3, "CompressedMaterializationDirection", value));
}

const StringUtil::EnumStringLiteral *GetCompressionFunctionSetLoadResultValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(CompressionFunctionSetLoadResult::ALREADY_LOADED_BEFORE_LOCK), "ALREADY_LOADED_BEFORE_LOCK" },
{ static_cast<uint32_t>(CompressionFunctionSetLoadResult::ALREADY_LOADED_AFTER_LOCK), "ALREADY_LOADED_AFTER_LOCK" },
{ static_cast<uint32_t>(CompressionFunctionSetLoadResult::LAZILY_LOADED), "LAZILY_LOADED" }
};
return values;
}

template<>
const char* EnumUtil::ToChars<CompressionFunctionSetLoadResult>(CompressionFunctionSetLoadResult value) {
return StringUtil::EnumToString(GetCompressionFunctionSetLoadResultValues(), 3, "CompressionFunctionSetLoadResult", static_cast<uint32_t>(value));
}

template<>
CompressionFunctionSetLoadResult EnumUtil::FromString<CompressionFunctionSetLoadResult>(const char *value) {
return static_cast<CompressionFunctionSetLoadResult>(StringUtil::StringToEnum(GetCompressionFunctionSetLoadResultValues(), 3, "CompressionFunctionSetLoadResult", value));
}

const StringUtil::EnumStringLiteral *GetCompressionTypeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(CompressionType::COMPRESSION_AUTO), "AUTO" },
Expand Down
12 changes: 12 additions & 0 deletions src/duckdb/src/common/multi_file/multi_file_column_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,20 @@ static unique_ptr<TableFilter> TryCastTableFilter(const TableFilter &global_filt
}

void SetIndexToZero(unique_ptr<Expression> &root_expr) {
#ifdef DEBUG
optional_idx index;
ExpressionIterator::VisitExpressionMutable<BoundReferenceExpression>(root_expr, [&](BoundReferenceExpression &ref,
unique_ptr<Expression> &expr) {
if (index.IsValid() && index.GetIndex() != ref.index) {
throw InternalException("Expected an expression that only references a single column, but found multiple!");
}
index = ref.index;
ref.index = 0;
});
#else
ExpressionIterator::VisitExpressionMutable<BoundReferenceExpression>(
root_expr, [&](BoundReferenceExpression &ref, unique_ptr<Expression> &expr) { ref.index = 0; });
#endif
}

bool CanPropagateCast(const MultiFileIndexMapping &mapping, const LogicalType &local_type,
Expand Down
6 changes: 6 additions & 0 deletions src/duckdb/src/execution/operator/join/physical_iejoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ idx_t IEJoinUnion::JoinComplexBlocks(unsafe_vector<idx_t> &lsel, unsafe_vector<i
// 8. initialize join result as an empty list for tuple pairs
idx_t result_count = 0;

lsel.resize(STANDARD_VECTOR_SIZE);
rsel.resize(STANDARD_VECTOR_SIZE);

// 11. for(i←1 to n) do
while (i < n) {
// 13. for (j ← pos+eqOff to n) do
Expand Down Expand Up @@ -776,6 +779,9 @@ idx_t IEJoinUnion::JoinComplexBlocks(unsafe_vector<idx_t> &lsel, unsafe_vector<i
}
}

lsel.resize(result_count);
rsel.resize(result_count);

return result_count;
}

Expand Down
22 changes: 19 additions & 3 deletions src/duckdb/src/execution/physical_plan/plan_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,21 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalGet &op) {
vector<unique_ptr<Expression>> select_list;
unique_ptr<Expression> unsupported_filter;
unordered_set<idx_t> to_remove;

virtual_column_map_t virtual_columns;
if (op.function.get_virtual_columns) {
virtual_columns = op.function.get_virtual_columns(context, op.bind_data.get());
}
for (auto &entry : table_filters->filters) {
auto column_id = column_ids[entry.first].GetPrimaryIndex();
auto &type = op.returned_types[column_id];
if (!op.function.supports_pushdown_type(*op.bind_data, column_id)) {
LogicalType column_type;
if (IsVirtualColumn(column_id)) {
auto &column = virtual_columns.at(column_id);
column_type = column.type;
} else {
column_type = op.returned_types[column_id];
}
idx_t column_id_filter = entry.first;
bool found_projection = false;
for (idx_t i = 0; i < projection_ids.size(); i++) {
Expand All @@ -119,7 +130,7 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalGet &op) {
projection_ids.push_back(entry.first);
column_id_filter = projection_ids.size() - 1;
}
auto column = make_uniq<BoundReferenceExpression>(type, column_id_filter);
auto column = make_uniq<BoundReferenceExpression>(column_type, column_id_filter);
select_list.push_back(entry.second->ToExpression(*column));
to_remove.insert(entry.first);
}
Expand All @@ -132,7 +143,12 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalGet &op) {
vector<LogicalType> filter_types;
for (auto &c : projection_ids) {
auto column_id = column_ids[c].GetPrimaryIndex();
filter_types.push_back(op.returned_types[column_id]);
if (IsVirtualColumn(column_id)) {
auto &column = virtual_columns.at(column_id);
filter_types.push_back(column.type);
} else {
filter_types.push_back(op.returned_types[column_id]);
}
}
filter = Make<PhysicalFilter>(filter_types, std::move(select_list), op.estimated_cardinality);
}
Expand Down
126 changes: 33 additions & 93 deletions src/duckdb/src/function/compression_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,31 @@ idx_t CompressionFunctionSet::GetCompressionIndex(CompressionType type) {
}

CompressionFunctionSet::CompressionFunctionSet() {
for (idx_t i = 0; i < PHYSICAL_TYPE_COUNT; i++) {
is_loaded[i] = false;
}
ResetDisabledMethods();
functions.resize(PHYSICAL_TYPE_COUNT);

static PhysicalType physical_types[PHYSICAL_TYPE_COUNT] = {
PhysicalType::BOOL, PhysicalType::UINT8, PhysicalType::INT8, PhysicalType::UINT16, PhysicalType::INT16,
PhysicalType::UINT32, PhysicalType::INT32, PhysicalType::UINT64, PhysicalType::INT64, PhysicalType::FLOAT,
PhysicalType::DOUBLE, PhysicalType::INTERVAL, PhysicalType::LIST, PhysicalType::STRUCT, PhysicalType::ARRAY,
PhysicalType::VARCHAR, PhysicalType::UINT128, PhysicalType::INT128, PhysicalType::BIT,
};
for (idx_t type_index = 0; type_index < PHYSICAL_TYPE_COUNT; type_index++) {
const auto physical_type = physical_types[type_index];
const auto index = GetCompressionIndex(physical_type);
auto &function_list = functions[index];

for (idx_t method_index = 0; internal_compression_methods[method_index].get_function; method_index++) {
auto &method = internal_compression_methods[method_index];
if (!method.supports_type(physical_type)) {
// Not supported for this type.
continue;
}
// The type is supported.
// We create the function and insert it into the set of available functions.
function_list.push_back(method.get_function(physical_type));
}
}
}

bool EmitCompressionFunction(CompressionType type) {
Expand All @@ -113,14 +133,12 @@ bool EmitCompressionFunction(CompressionType type) {

vector<reference<const CompressionFunction>>
CompressionFunctionSet::GetCompressionFunctions(PhysicalType physical_type) {
LoadCompressionFunctions(physical_type);
auto index = GetCompressionIndex(physical_type);
const auto index = GetCompressionIndex(physical_type);
auto &function_list = functions[index];
vector<reference<const CompressionFunction>> result;
for (auto &entry : function_list) {
auto compression_index = GetCompressionIndex(entry.type);
const auto compression_index = GetCompressionIndex(entry.type);
if (is_disabled[compression_index]) {
// explicitly disabled
continue;
}
if (!EmitCompressionFunction(entry.type)) {
Expand All @@ -131,50 +149,22 @@ CompressionFunctionSet::GetCompressionFunctions(PhysicalType physical_type) {
return result;
}

CompressionFunctionSetLoadResult CompressionFunctionSet::LoadCompressionFunctions(PhysicalType physical_type) {
auto index = GetCompressionIndex(physical_type);
if (is_loaded[index]) {
return CompressionFunctionSetLoadResult::ALREADY_LOADED_BEFORE_LOCK;
}
// not loaded - try to load it
lock_guard<mutex> guard(lock);
// verify nobody loaded it in the mean-time
if (is_loaded[index]) {
return CompressionFunctionSetLoadResult::ALREADY_LOADED_AFTER_LOCK;
}
// actually perform the load
auto &function_list = functions[index];
for (idx_t i = 0; internal_compression_methods[i].get_function; i++) {
auto &method = internal_compression_methods[i];
if (!method.supports_type(physical_type)) {
// not supported for this type
continue;
}
// The type is supported. We create the function and insert it into the set of available functions.
function_list.push_back(method.get_function(physical_type));
}
is_loaded[index] = true;
return CompressionFunctionSetLoadResult::LAZILY_LOADED;
}

pair<CompressionFunctionSetLoadResult, optional_ptr<const CompressionFunction>>
optional_ptr<const CompressionFunction>
CompressionFunctionSet::GetCompressionFunction(CompressionType type, const PhysicalType physical_type) {
const auto load_result = LoadCompressionFunctions(physical_type);

const auto index = GetCompressionIndex(physical_type);
const auto &function_list = functions[index];
for (auto &function : function_list) {
if (function.type == type) {
return make_pair(load_result, &function);
return &function;
}
}
return make_pair(load_result, nullptr);
return nullptr;
}

void CompressionFunctionSet::SetDisabledCompressionMethods(const vector<CompressionType> &methods) {
ResetDisabledMethods();
for (auto &method : methods) {
auto idx = GetCompressionIndex(method);
const auto idx = GetCompressionIndex(method);
is_disabled[idx] = true;
}
}
Expand All @@ -193,55 +183,6 @@ vector<CompressionType> CompressionFunctionSet::GetDisabledCompressionMethods()
return result;
}

string CompressionFunctionSet::GetDebugInfo() const {
static PhysicalType physical_types[PHYSICAL_TYPE_COUNT] = {
PhysicalType::BOOL, PhysicalType::UINT8, PhysicalType::INT8, PhysicalType::UINT16, PhysicalType::INT16,
PhysicalType::UINT32, PhysicalType::INT32, PhysicalType::UINT64, PhysicalType::INT64, PhysicalType::FLOAT,
PhysicalType::DOUBLE, PhysicalType::INTERVAL, PhysicalType::LIST, PhysicalType::STRUCT, PhysicalType::ARRAY,
PhysicalType::VARCHAR, PhysicalType::UINT128, PhysicalType::INT128, PhysicalType::BIT,
};

vector<string> compression_type_debug_infos;
for (idx_t i = 0; i < COMPRESSION_TYPE_COUNT; i++) {
compression_type_debug_infos.push_back(
StringUtil::Format("%llu: {compression type: %s, is disabled: %llu}", i,
EnumUtil::ToString(internal_compression_methods[i].type), is_disabled[i].load()));
}

lock_guard<mutex> guard(lock);
vector<string> physical_type_debug_infos;
for (idx_t index = 0; index < PHYSICAL_TYPE_COUNT; index++) {
const auto &physical_type = physical_types[index];
D_ASSERT(GetCompressionIndex(physical_type) == index);

idx_t out_of = 0;
for (idx_t i = 0; internal_compression_methods[i].get_function; i++) {
auto &method = internal_compression_methods[i];
if (method.supports_type(physical_type)) {
out_of++;
}
}

const auto &function_list = functions[index];
vector<string> function_list_debug_infos;
for (idx_t function_index = 0; function_index < function_list.size(); function_index++) {
auto &function = function_list[function_index];
function_list_debug_infos.push_back(StringUtil::Format("%llu: {compression type: %s, physical type: %s}",
function_index, EnumUtil::ToString(function.type),
EnumUtil::ToString(function.data_type)));
}

physical_type_debug_infos.push_back(StringUtil::Format(
"%llu: {physical type: %s, loaded: %llu, loaded functions: %llu (out of: %llu)}\t\t%s", index,
EnumUtil::ToString(physical_type), is_loaded[index].load(), function_list.size(), out_of,
function_list_debug_infos.empty() ? "" : "\n\t\t" + StringUtil::Join(function_list_debug_infos, "\n\t\t")));
}

return StringUtil::Format("DEBUG INFO:\n - Compression types:\n\t%s\n\n - Physical types:\n\t%s",
StringUtil::Join(compression_type_debug_infos, "\n\t"),
StringUtil::Join(physical_type_debug_infos, "\n\t"));
}

vector<CompressionType> DBConfig::GetDisabledCompressionMethods() const {
return compression_functions->GetDisabledCompressionMethods();
}
Expand All @@ -258,18 +199,17 @@ vector<reference<const CompressionFunction>> DBConfig::GetCompressionFunctions(c

optional_ptr<const CompressionFunction> DBConfig::TryGetCompressionFunction(CompressionType type,
const PhysicalType physical_type) const {
return compression_functions->GetCompressionFunction(type, physical_type).second;
return compression_functions->GetCompressionFunction(type, physical_type);
}

reference<const CompressionFunction> DBConfig::GetCompressionFunction(CompressionType type,
const PhysicalType physical_type) const {
auto result = compression_functions->GetCompressionFunction(type, physical_type);
if (!result.second) {
if (!result) {
throw InternalException(
"Could not find compression function \"%s\" for physical type \"%s\". Load result: %s. %s",
EnumUtil::ToString(type), EnumUtil::ToString(physical_type), EnumUtil::ToString(result.first),
compression_functions->GetDebugInfo());
EnumUtil::ToString(type), EnumUtil::ToString(physical_type));
}
return *result.second;
return *result;
}
} // namespace duckdb
16 changes: 14 additions & 2 deletions src/duckdb/src/function/table/system/duckdb_views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ static unique_ptr<FunctionData> DuckDBViewsBind(ClientContext &context, TableFun
names.emplace_back("sql");
return_types.emplace_back(LogicalType::VARCHAR);

names.emplace_back("is_bound");
return_types.emplace_back(LogicalType::BOOLEAN);

return nullptr;
}

Expand Down Expand Up @@ -135,15 +138,24 @@ void DuckDBViewsFunction(ClientContext &context, TableFunctionInput &data_p, Dat
case 10: {
// column_count, LogicalType::BIGINT
// make sure the view is bound so we know the columns it emits
view.BindView(context);
auto columns = view.GetColumnInfo();
output.SetValue(c, count, Value::BIGINT(NumericCast<int64_t>(columns->types.size())));
Value column_count;
if (columns) {
column_count = Value::BIGINT(NumericCast<int64_t>(columns->types.size()));
}
output.SetValue(c, count, column_count);
break;
}
case 11:
// sql, LogicalType::VARCHAR
output.SetValue(c, count, Value(view.ToSQL()));
break;
case 12: {
// is_bound, LogicalType::BOOLEAN
auto columns = view.GetColumnInfo();
output.SetValue(c, count, Value::BOOLEAN(columns.get()));
break;
}
default:
throw InternalException("Unsupported column index for duckdb_views");
}
Expand Down
6 changes: 6 additions & 0 deletions src/duckdb/src/function/table/table_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,15 @@ bool TryScanIndex(ART &art, IndexEntry &entry, const ColumnList &column_list, Ta
vector<reference<ART>> arts_to_scan;
arts_to_scan.push_back(art);
if (entry.deleted_rows_in_use) {
if (entry.deleted_rows_in_use->GetIndexType() != ART::TYPE_NAME) {
throw InternalException("Concurrent changes made to a non-ART index");
}
arts_to_scan.push_back(entry.deleted_rows_in_use->Cast<ART>());
}
if (entry.added_data_during_checkpoint) {
if (entry.added_data_during_checkpoint->GetIndexType() != ART::TYPE_NAME) {
throw InternalException("Concurrent changes made to a non-ART index");
}
arts_to_scan.push_back(entry.added_data_during_checkpoint->Cast<ART>());
}

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 "0-dev7526"
#define DUCKDB_PATCH_VERSION "0-dev7605"
#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.0-dev7526"
#define DUCKDB_VERSION "v1.5.0-dev7605"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "490e7a8f47"
#define DUCKDB_SOURCE_ID "3a3967aa81"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
Loading