diff --git a/src/catalog/catalog_entry/duck_table_entry.cpp b/src/catalog/catalog_entry/duck_table_entry.cpp index e453df2e66b..c25c76bb279 100644 --- a/src/catalog/catalog_entry/duck_table_entry.cpp +++ b/src/catalog/catalog_entry/duck_table_entry.cpp @@ -76,7 +76,7 @@ vector GetUniqueConstraintKeys(const ColumnList &columns, const U if (constraint.HasIndex()) { indexes.push_back(columns.LogicalToPhysical(constraint.GetIndex())); } else { - for(auto &keyname : constraint.GetColumnNames()) { + for (auto &keyname : constraint.GetColumnNames()) { indexes.push_back(columns.GetColumn(keyname).Physical()); } } @@ -360,7 +360,7 @@ void DuckTableEntry::UpdateConstraintsOnColumnDrop(const LogicalIndex &removed_i const vector &adjusted_indices, const RemoveColumnInfo &info, CreateTableInfo &create_info, const vector> &bound_constraints, - bool is_generated) { + bool is_generated) { // handle constraints for the new table D_ASSERT(constraints.size() == bound_constraints.size()); for (idx_t constr_idx = 0; constr_idx < constraints.size(); constr_idx++) { @@ -483,7 +483,8 @@ unique_ptr DuckTableEntry::RemoveColumn(ClientContext &context, Re auto binder = Binder::CreateBinder(context); auto bound_constraints = binder->BindConstraints(constraints, name, columns); - UpdateConstraintsOnColumnDrop(removed_index, adjusted_indices, info, *create_info, bound_constraints, dropped_column_is_generated); + UpdateConstraintsOnColumnDrop(removed_index, adjusted_indices, info, *create_info, bound_constraints, + dropped_column_is_generated); auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info), schema); if (columns.GetColumn(LogicalIndex(removed_index)).Generated()) { diff --git a/src/catalog/catalog_entry/table_catalog_entry.cpp b/src/catalog/catalog_entry/table_catalog_entry.cpp index 493403830e2..8f73ec416e6 100644 --- a/src/catalog/catalog_entry/table_catalog_entry.cpp +++ b/src/catalog/catalog_entry/table_catalog_entry.cpp @@ -234,8 +234,8 @@ vector TableCatalogEntry::GetColumnSegmentInfo() { return {}; } -void TableCatalogEntry::BindUpdateConstraints(Binder &binder, LogicalGet &get, LogicalProjection &proj, LogicalUpdate &update, - ClientContext &context) { +void TableCatalogEntry::BindUpdateConstraints(Binder &binder, LogicalGet &get, LogicalProjection &proj, + LogicalUpdate &update, ClientContext &context) { // check the constraints and indexes of the table to see if we need to project any additional columns // we do this for indexes with multiple columns and CHECK constraints in the UPDATE clause // suppose we have a constraint CHECK(i + j < 10); now we need both i and j to check the constraint diff --git a/src/execution/operator/persistent/physical_insert.cpp b/src/execution/operator/persistent/physical_insert.cpp index 181216a15b7..c7b499855c5 100644 --- a/src/execution/operator/persistent/physical_insert.cpp +++ b/src/execution/operator/persistent/physical_insert.cpp @@ -108,7 +108,8 @@ class InsertLocalState : public LocalSinkState { idx_t update_count = 0; unique_ptr constraint_state; - ConstraintVerificationState &GetConstraintState(DataTable &table, TableCatalogEntry &tableref, ClientContext &context) { + ConstraintVerificationState &GetConstraintState(DataTable &table, TableCatalogEntry &tableref, + ClientContext &context) { if (!constraint_state) { constraint_state = table.InitializeConstraintVerification(tableref, context); } diff --git a/src/function/table/system/duckdb_constraints.cpp b/src/function/table/system/duckdb_constraints.cpp index c35eaf0da9a..71fabb16b5c 100644 --- a/src/function/table/system/duckdb_constraints.cpp +++ b/src/function/table/system/duckdb_constraints.cpp @@ -132,7 +132,7 @@ unique_ptr DuckDBConstraintsInit(ClientContext &contex }); sort(entries.begin(), entries.end(), [&](CatalogEntry &x, CatalogEntry &y) { return (x.name < y.name); }); - for(auto &entry : entries) { + for (auto &entry : entries) { result->entries.emplace_back(context, entry.get().Cast()); } }; diff --git a/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp b/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp index 7c1323a4f30..5396f31115c 100644 --- a/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +++ b/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp @@ -58,7 +58,8 @@ class DuckTableEntry : public TableCatalogEntry { unique_ptr SetColumnComment(ClientContext &context, SetColumnCommentInfo &info); void UpdateConstraintsOnColumnDrop(const LogicalIndex &removed_index, const vector &adjusted_indices, - const RemoveColumnInfo &info, CreateTableInfo &create_info, const vector> &bound_constraints, bool is_generated); + const RemoveColumnInfo &info, CreateTableInfo &create_info, + const vector> &bound_constraints, bool is_generated); private: //! A reference to the underlying storage unit used for this table diff --git a/src/include/duckdb/planner/binder.hpp b/src/include/duckdb/planner/binder.hpp index 67e2bc1ec6b..705f3559501 100644 --- a/src/include/duckdb/planner/binder.hpp +++ b/src/include/duckdb/planner/binder.hpp @@ -122,9 +122,13 @@ class Binder : public std::enable_shared_from_this { unique_ptr BindCreateTableInfo(unique_ptr info, SchemaCatalogEntry &schema); unique_ptr BindCreateTableInfo(unique_ptr info, SchemaCatalogEntry &schema, vector> &bound_defaults); - static vector> BindConstraints(ClientContext &context, const vector> &constraints, const string &table_name, const ColumnList &columns); - vector> BindConstraints(const vector> &constraints, const string &table_name, const ColumnList &columns); - vector> BindNewConstraints(vector> &constraints, const string &table_name, const ColumnList &columns); + static vector> BindConstraints(ClientContext &context, + const vector> &constraints, + const string &table_name, const ColumnList &columns); + vector> BindConstraints(const vector> &constraints, + const string &table_name, const ColumnList &columns); + vector> BindNewConstraints(vector> &constraints, + const string &table_name, const ColumnList &columns); void BindCreateViewInfo(CreateViewInfo &base); SchemaCatalogEntry &BindSchema(CreateInfo &info); diff --git a/src/include/duckdb/storage/data_table.hpp b/src/include/duckdb/storage/data_table.hpp index 74a5c228383..e6aedf464bc 100644 --- a/src/include/duckdb/storage/data_table.hpp +++ b/src/include/duckdb/storage/data_table.hpp @@ -115,7 +115,6 @@ class DataTable { //! Delete the entries with the specified row identifier from the table idx_t Delete(TableDeleteState &state, ClientContext &context, Vector &row_ids, idx_t count); - unique_ptr InitializeUpdate(TableCatalogEntry &table, ClientContext &context); //! Update the entries with the specified row identifier from the table void Update(TableUpdateState &state, ClientContext &context, Vector &row_ids, @@ -194,14 +193,15 @@ class DataTable { bool IndexNameIsUnique(const string &name); //! Initialize constraint verification - unique_ptr InitializeConstraintVerification(TableCatalogEntry &table, ClientContext &context); + unique_ptr InitializeConstraintVerification(TableCatalogEntry &table, + ClientContext &context); //! Verify constraints with a chunk from the Append containing all columns of the table void VerifyAppendConstraints(ConstraintVerificationState &state, ClientContext &context, DataChunk &chunk, - optional_ptr conflict_manager = nullptr); + optional_ptr conflict_manager = nullptr); public: static void VerifyUniqueIndexes(TableIndexList &indexes, ClientContext &context, DataChunk &chunk, - optional_ptr conflict_manager); + optional_ptr conflict_manager); private: //! Verify the new added constraints against current persistent&local data diff --git a/src/include/duckdb/storage/table/append_state.hpp b/src/include/duckdb/storage/table/append_state.hpp index 475a59187f1..8f9a56c5cba 100644 --- a/src/include/duckdb/storage/table/append_state.hpp +++ b/src/include/duckdb/storage/table/append_state.hpp @@ -71,7 +71,8 @@ struct TableAppendState { }; struct ConstraintVerificationState { - explicit ConstraintVerificationState(TableCatalogEntry &table_p) : table(table_p) {} + explicit ConstraintVerificationState(TableCatalogEntry &table_p) : table(table_p) { + } TableCatalogEntry &table; vector> bound_constraints; diff --git a/src/planner/binder/statement/bind_create_table.cpp b/src/planner/binder/statement/bind_create_table.cpp index 10ef50599a0..8a032b9fe1e 100644 --- a/src/planner/binder/statement/bind_create_table.cpp +++ b/src/planner/binder/statement/bind_create_table.cpp @@ -35,7 +35,8 @@ static void CreateColumnDependencyManager(BoundCreateTableInfo &info) { } } -static unique_ptr BindCheckConstraint(Binder &binder, const string &table_name, const ColumnList &columns, const unique_ptr &cond) { +static unique_ptr BindCheckConstraint(Binder &binder, const string &table_name, + const ColumnList &columns, const unique_ptr &cond) { auto bound_constraint = make_uniq(); // check constraint: bind the expression CheckBinder check_binder(binder, binder.context, table_name, columns, bound_constraint->bound_columns); @@ -47,12 +48,15 @@ static unique_ptr BindCheckConstraint(Binder &binder, const str return std::move(bound_constraint); } -vector> Binder::BindConstraints(ClientContext &context, const vector> &constraints, const string &table_name, const ColumnList &columns) { +vector> Binder::BindConstraints(ClientContext &context, + const vector> &constraints, + const string &table_name, const ColumnList &columns) { auto binder = Binder::CreateBinder(context); return binder->BindConstraints(constraints, table_name, columns); } -vector> Binder::BindConstraints(const vector> &constraints, const string &table_name, const ColumnList &columns) { +vector> Binder::BindConstraints(const vector> &constraints, + const string &table_name, const ColumnList &columns) { vector> bound_constraints; for (auto &constr : constraints) { switch (constr->type) { @@ -128,16 +132,17 @@ vector> Binder::BindConstraints(const vector> Binder::BindNewConstraints(vector> &constraints, const string &table_name, const ColumnList &columns) { +vector> Binder::BindNewConstraints(vector> &constraints, + const string &table_name, const ColumnList &columns) { auto bound_constraints = BindConstraints(constraints, table_name, columns); // handle primary keys/not null constraints bool has_primary_key = false; logical_index_set_t not_null_columns; vector primary_keys; - for(idx_t c = 0; c < constraints.size(); c++) { + for (idx_t c = 0; c < constraints.size(); c++) { auto &constr = constraints[c]; - switch(constr->type) { + switch (constr->type) { case ConstraintType::NOT_NULL: { auto ¬_null = constr->Cast(); auto &col = columns.GetColumn(LogicalIndex(not_null.index)); @@ -263,7 +268,8 @@ static void ExtractExpressionDependencies(Expression &expr, LogicalDependencyLis expr, [&](Expression &child) { ExtractExpressionDependencies(child, dependencies); }); } -static void ExtractDependencies(BoundCreateTableInfo &info, vector> &defaults, vector> &constraints) { +static void ExtractDependencies(BoundCreateTableInfo &info, vector> &defaults, + vector> &constraints) { for (auto &default_value : defaults) { if (default_value) { ExtractExpressionDependencies(*default_value, info.dependencies); diff --git a/src/storage/data_table.cpp b/src/storage/data_table.cpp index 8dab59b0e1a..8a610b38c7c 100644 --- a/src/storage/data_table.cpp +++ b/src/storage/data_table.cpp @@ -617,7 +617,7 @@ void DataTable::VerifyUniqueIndexes(TableIndexList &indexes, ClientContext &cont } void DataTable::VerifyAppendConstraints(ConstraintVerificationState &state, ClientContext &context, DataChunk &chunk, - optional_ptr conflict_manager) { + optional_ptr conflict_manager) { auto &table = state.table; if (table.HasGeneratedColumns()) { // Verify that the generated columns expression work with the inserted values @@ -675,7 +675,8 @@ void DataTable::VerifyAppendConstraints(ConstraintVerificationState &state, Clie } } -unique_ptr DataTable::InitializeConstraintVerification(TableCatalogEntry &table, ClientContext &context) { +unique_ptr DataTable::InitializeConstraintVerification(TableCatalogEntry &table, + ClientContext &context) { auto result = make_uniq(table); auto binder = Binder::CreateBinder(context); result->bound_constraints = binder->BindConstraints(table.GetConstraints(), table.name, table.GetColumns()); @@ -1063,7 +1064,8 @@ idx_t DataTable::Delete(TableDeleteState &state, ClientContext &context, Vector if (state.has_delete_constraints) { // perform the constraint verification ColumnFetchState fetch_state; - local_storage.FetchChunk(*this, offset_ids, current_count, state.col_ids, state.verify_chunk, fetch_state); + local_storage.FetchChunk(*this, offset_ids, current_count, state.col_ids, state.verify_chunk, + fetch_state); VerifyDeleteConstraints(state, context, state.verify_chunk); } delete_count += local_storage.Delete(*this, offset_ids, current_count); @@ -1118,7 +1120,7 @@ static bool CreateMockChunk(TableCatalogEntry &table, const vector &column_ids) { auto &table = state.table; auto &constraints = table.GetConstraints();