Skip to content

Commit

Permalink
Merge pull request duckdb#11721 from Mytherin/removebounddefaults
Browse files Browse the repository at this point in the history
Remove bound_defaults from BoundCreateTableInfo
  • Loading branch information
Mytherin committed Apr 19, 2024
2 parents c580626 + 443119e commit e00d442
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/catalog/catalog_entry/duck_table_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ unique_ptr<CatalogEntry> DuckTableEntry::AddColumn(ClientContext &context, AddCo
create_info->columns.AddColumn(std::move(col));

auto binder = Binder::CreateBinder(context);
auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info), schema);
auto new_storage =
make_shared_ptr<DataTable>(context, *storage, info.new_column, *bound_create_info->bound_defaults.back());
vector<unique_ptr<Expression>> bound_defaults;
auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info), schema, bound_defaults);
auto new_storage = make_shared_ptr<DataTable>(context, *storage, info.new_column, *bound_defaults.back());
return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, new_storage);
}

Expand Down
2 changes: 2 additions & 0 deletions src/include/duckdb/planner/binder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class Binder : public enable_shared_from_this<Binder> {

unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info);
unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry &schema);
unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry &schema,
vector<unique_ptr<Expression>> &bound_defaults);

void BindCreateViewInfo(CreateViewInfo &base);
SchemaCatalogEntry &BindSchema(CreateInfo &info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ struct BoundCreateTableInfo {
vector<unique_ptr<Constraint>> constraints;
//! List of bound constraints on the table
vector<unique_ptr<BoundConstraint>> bound_constraints;
//! Bound default values
vector<unique_ptr<Expression>> bound_defaults;
//! Dependents of the table (in e.g. default values)
LogicalDependencyList dependencies;
//! The existing table data on disk (if any)
Expand Down
15 changes: 11 additions & 4 deletions src/planner/binder/statement/bind_create_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ static void ExtractExpressionDependencies(Expression &expr, LogicalDependencyLis
expr, [&](Expression &child) { ExtractExpressionDependencies(child, dependencies); });
}

static void ExtractDependencies(BoundCreateTableInfo &info) {
for (auto &default_value : info.bound_defaults) {
static void ExtractDependencies(BoundCreateTableInfo &info, vector<unique_ptr<Expression>> &bound_defaults) {
for (auto &default_value : bound_defaults) {
if (default_value) {
ExtractExpressionDependencies(*default_value, info.dependencies);
}
Expand All @@ -252,7 +252,14 @@ static void ExtractDependencies(BoundCreateTableInfo &info) {
}
}
}

unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry &schema) {
vector<unique_ptr<Expression>> bound_defaults;
return BindCreateTableInfo(std::move(info), schema, bound_defaults);
}

unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry &schema,
vector<unique_ptr<Expression>> &bound_defaults) {
auto &base = info->Cast<CreateTableInfo>();
auto result = make_uniq<BoundCreateTableInfo>(schema, std::move(info));
if (base.query) {
Expand All @@ -279,10 +286,10 @@ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateIn
// bind any constraints
BindConstraints(*this, *result);
// bind the default values
BindDefaultValues(base.columns, result->bound_defaults);
BindDefaultValues(base.columns, bound_defaults);
}
// extract dependencies from any default values or CHECK constraints
ExtractDependencies(*result);
ExtractDependencies(*result, bound_defaults);

if (base.columns.PhysicalColumnCount() == 0) {
throw BinderException("Creating a table without physical (non-generated) columns is not supported");
Expand Down

0 comments on commit e00d442

Please sign in to comment.