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

Move table splitting logic to SQL #3119

Merged
merged 17 commits into from Aug 4, 2023
Merged

Move table splitting logic to SQL #3119

merged 17 commits into from Aug 4, 2023

Conversation

mathemancer
Copy link
Contributor

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

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@mathemancer mathemancer marked this pull request as ready for review August 1, 2023 14:57
@mathemancer mathemancer added the pr-status: review A PR awaiting review label Aug 1, 2023
@kgodey kgodey added this to the v0.1.3 milestone Aug 1, 2023
Copy link
Contributor

@silentninja silentninja left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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.

@silentninja silentninja added pr-status: revision A PR awaiting follow-up work from its author after review and removed pr-status: review A PR awaiting review labels Aug 3, 2023
@mathemancer mathemancer added this pull request to the merge queue Aug 4, 2023
Merged via the queue into develop with commit ab68686 Aug 4, 2023
16 checks passed
@mathemancer mathemancer deleted the split_tables_sql branch August 4, 2023 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: revision A PR awaiting follow-up work from its author after review
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants