Skip to content

Drop MD tables when MD support is disabled #771

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Y--
Copy link
Collaborator

@Y-- Y-- commented May 7, 2025

Currently PG catalog entries mirroring MD tables are dropped only when the extension is.

This PR changes this behavior to have them depend on the motherduck SERVER so that when it is removed, the entries are removed as well.

@Y-- Y-- force-pushed the yl/md-tables-depend-fdw branch from fcb25a1 to e1aa072 Compare May 7, 2025 19:07
Base automatically changed from fix-md-issues to main May 7, 2025 19:08
@Y-- Y-- force-pushed the yl/md-tables-depend-fdw branch from e1aa072 to 4f1078a Compare May 7, 2025 19:12
.objectSubId = 0,
};
recordDependencyOn(&schema_address, &extension_address, DEPENDENCY_NORMAL);
recordDependencyOn(&schema_address, &server_address, DEPENDENCY_NORMAL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for tables in a ddb$ schema, because those will then depend on the SERVER indirectly through their schema. But this doesn't yet work for tables in the default database, for those we need to create a direct dependency between the table and the schema. (and probably we just want to create the direct dependency for any duckdb table, no matter what schema they are in, just for consistency).

@JelteF JelteF added this to the 1.0.0 milestone May 7, 2025
@Y-- Y-- force-pushed the yl/md-tables-depend-fdw branch from 9655d2c to 9cbf120 Compare May 7, 2025 19:38
.objectId = oid,
.objectSubId = 0,
};
recordDependencyOnMDServer(&object_address);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done in our DDL hook instead. That way the dependency is also recorded when someone creates a motherduck table from Postgres, not just when a table is synced to by the background worker.

@Y-- Y-- force-pushed the yl/md-tables-depend-fdw branch 2 times, most recently from d39af6a to 6065296 Compare May 9, 2025 09:17
@Y-- Y-- force-pushed the yl/md-tables-depend-fdw branch 2 times, most recently from d313255 to 42c3336 Compare May 9, 2025 09:19
@Y-- Y-- force-pushed the yl/md-tables-depend-fdw branch from 42c3336 to 7a99398 Compare May 9, 2025 09:57
} else {
// Something went really wrong (since `create_table_succeeded`)
elog(WARNING, "Failed to find table '%s.%s' so won't record dependency to 'motherduck' SERVER", table_name,
postgres_schema_name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
postgres_schema_name);
postgres_schema_name);
RollbackAndReleaseCurrentSubTransaction();
return false;

And as a nit: then we can change this to "early return" style if we change

if (HeapTupleIsValid(new_table_tuple)) {

to the inverse

if (!HeapTupleIsValid(new_table_tuple)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants