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
Move table splitting logic to SQL #3119
Conversation
This less-strict stance will make it easier to get things working in the python layer for now. We should reconsider later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I have made some requests to improve readability, please add it to the PR and merge it.
'not_null', attnotnull, | ||
'default', | ||
-- We only copy non-dynamic default expressions to new table to avoid double-use of sequences. | ||
CASE WHEN NOT msar.is_default_possibly_dynamic(tab_id, col_id) THEN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we lose the dynamic default information in case a column has one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for now. We should probably add that as an issue. I believe we were already dropping those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll clarify the comment. The issue is that in the case of sequence dynamic defaults, the sequence is owned by the column that uses it, and can't be reused by any other column. It'll throw an error if you try. but, our dynamic default detection isn't (yet) sophisticated enough to detect when this is the case, and we shouldn't copy it, or when it's something safe like NOW()
.
@@ -2087,18 +2195,18 @@ $$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT; | |||
|
|||
CREATE OR REPLACE FUNCTION | |||
msar.create_many_to_one_link( | |||
from_rel_id oid, | |||
to_rel_id oid, | |||
frel_id oid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the from_rel_id
better as it informs the direction of the link. Any reason for renaming it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it was backwards, so it must not have helped that much 😄. I.e., the foreign key was from to_rel_id
to from_rel_id
. The reason I changed it was to match up with what's in the pg_attribute
table, and related terminology. I haven't actually found a good name, so I figure it makes most sense to match up with what is in the PG catalog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added more in the docstring to that effect.
fkey_attnum := msar.create_many_to_one_link(extracted_table_id, tab_id, fkey_name); | ||
PERFORM __msar.exec_ddl($t$ | ||
WITH fkey_cte AS ( | ||
SELECT id, %1$s, dense_rank() OVER (ORDER BY %1$s) AS __msar_tmp_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be helpful to add comments on what the placeholders refer to. Something like
-- %1$s refers to the columns to be moved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done; I also added a number of other comments describing the process.
Related to #2737
This PR moves the logic for splitting tables by extracting chosen columns to the database. It also moves the tests to SQL tests.
Checklist
Update index.md
).develop
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin