Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommitState::WriteCatalogEntry refactor #10555

Merged
merged 6 commits into from Feb 9, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
106 changes: 59 additions & 47 deletions src/transaction/commit_state.cpp
Expand Up @@ -45,8 +45,14 @@ void CommitState::WriteCatalogEntry(CatalogEntry &entry, data_ptr_t dataptr) {

switch (parent.type) {
case CatalogType::TABLE_ENTRY:
if (entry.type == CatalogType::RENAMED_ENTRY || entry.type == CatalogType::TABLE_ENTRY) {
// ALTER TABLE statement, read the extra data after the entry
case CatalogType::VIEW_ENTRY:
case CatalogType::INDEX_ENTRY:
case CatalogType::SEQUENCE_ENTRY:
case CatalogType::TYPE_ENTRY:
case CatalogType::MACRO_ENTRY:
case CatalogType::TABLE_MACRO_ENTRY:
if (entry.type == CatalogType::RENAMED_ENTRY || entry.type == parent.type) {
// ALTER statement, read the extra data after the entry
auto extra_data_size = Load<idx_t>(dataptr);
auto extra_data = data_ptr_cast(dataptr + sizeof(idx_t));

Expand All @@ -57,18 +63,61 @@ void CommitState::WriteCatalogEntry(CatalogEntry &entry, data_ptr_t dataptr) {
auto parse_info = deserializer.ReadProperty<unique_ptr<ParseInfo>>(101, "alter_info");
deserializer.End();

if (!column_name.empty()) {
D_ASSERT(entry.type != CatalogType::RENAMED_ENTRY);
auto &table_entry = entry.Cast<DuckTableEntry>();
D_ASSERT(table_entry.IsDuckTable());
// write the alter table in the log
table_entry.CommitAlter(column_name);
switch (parent.type) {
case CatalogType::TABLE_ENTRY:
if (!column_name.empty()) {
D_ASSERT(entry.type != CatalogType::RENAMED_ENTRY);
auto &table_entry = entry.Cast<DuckTableEntry>();
D_ASSERT(table_entry.IsDuckTable());
// write the alter table in the log
table_entry.CommitAlter(column_name);
}
break;
case CatalogType::VIEW_ENTRY:
case CatalogType::INDEX_ENTRY:
case CatalogType::SEQUENCE_ENTRY:
case CatalogType::TYPE_ENTRY:
case CatalogType::MACRO_ENTRY:
case CatalogType::TABLE_MACRO_ENTRY:
(void)column_name;
break;
default:
throw InternalException("Don't know how to drop this type!");
carlopi marked this conversation as resolved.
Show resolved Hide resolved
}

auto &alter_info = parse_info->Cast<AlterInfo>();
log->WriteAlter(alter_info);
} else {
// CREATE TABLE statement
log->WriteCreateTable(parent.Cast<TableCatalogEntry>());
switch (parent.type) {
case CatalogType::TABLE_ENTRY:
// CREATE TABLE statement
log->WriteCreateTable(parent.Cast<TableCatalogEntry>());
break;
case CatalogType::VIEW_ENTRY:
// CREATE VIEW statement
log->WriteCreateView(parent.Cast<ViewCatalogEntry>());
break;
case CatalogType::INDEX_ENTRY:
// CREATE INDEX statement
log->WriteCreateIndex(parent.Cast<IndexCatalogEntry>());
break;
case CatalogType::SEQUENCE_ENTRY:
// CREATE SEQUENCE statement
log->WriteCreateSequence(parent.Cast<SequenceCatalogEntry>());
break;
case CatalogType::TYPE_ENTRY:
// CREATE TYPE statement
log->WriteCreateType(parent.Cast<TypeCatalogEntry>());
break;
case CatalogType::MACRO_ENTRY:
log->WriteCreateMacro(parent.Cast<ScalarMacroCatalogEntry>());
break;
case CatalogType::TABLE_MACRO_ENTRY:
log->WriteCreateTableMacro(parent.Cast<TableMacroCatalogEntry>());
break;
default:
throw InternalException("Don't know how to drop this type!");
carlopi marked this conversation as resolved.
Show resolved Hide resolved
}
}
break;
case CatalogType::SCHEMA_ENTRY:
Expand All @@ -78,43 +127,6 @@ void CommitState::WriteCatalogEntry(CatalogEntry &entry, data_ptr_t dataptr) {
}
log->WriteCreateSchema(parent.Cast<SchemaCatalogEntry>());
break;
case CatalogType::VIEW_ENTRY:
if (entry.type == CatalogType::RENAMED_ENTRY || entry.type == CatalogType::VIEW_ENTRY) {
// ALTER TABLE statement, read the extra data after the entry
auto extra_data_size = Load<idx_t>(dataptr);
auto extra_data = data_ptr_cast(dataptr + sizeof(idx_t));
// deserialize it
MemoryStream source(extra_data, extra_data_size);
BinaryDeserializer deserializer(source);
deserializer.Begin();
auto column_name = deserializer.ReadProperty<string>(100, "column_name");
auto parse_info = deserializer.ReadProperty<unique_ptr<ParseInfo>>(101, "alter_info");
deserializer.End();

(void)column_name;

// write the alter table in the log
auto &alter_info = parse_info->Cast<AlterInfo>();
log->WriteAlter(alter_info);
} else {
log->WriteCreateView(parent.Cast<ViewCatalogEntry>());
}
break;
case CatalogType::SEQUENCE_ENTRY:
log->WriteCreateSequence(parent.Cast<SequenceCatalogEntry>());
break;
case CatalogType::MACRO_ENTRY:
log->WriteCreateMacro(parent.Cast<ScalarMacroCatalogEntry>());
break;
case CatalogType::TABLE_MACRO_ENTRY:
log->WriteCreateTableMacro(parent.Cast<TableMacroCatalogEntry>());
break;
case CatalogType::INDEX_ENTRY:
log->WriteCreateIndex(parent.Cast<IndexCatalogEntry>());
break;
case CatalogType::TYPE_ENTRY:
log->WriteCreateType(parent.Cast<TypeCatalogEntry>());
break;
case CatalogType::RENAMED_ENTRY:
// This is a rename, nothing needs to be done for this
break;
Expand Down