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

Add foreign keys to parent during swap #67

Merged
merged 1 commit into from
Mar 13, 2022
Merged

Add foreign keys to parent during swap #67

merged 1 commit into from
Mar 13, 2022

Conversation

shayonj
Copy link
Owner

@shayonj shayonj commented Mar 13, 2022

Until now we were structurally copying the primary
table into shadow table. While doing so, we were also
copying the FKs. This could lead to locks on other queries
running on the primary/dependent table during copy.

This PR fixes it by not adding the FKs to the shadow table (to avoid any locks during copy),
but adding the FK to the parent table itself from the same transaction,
during the swap with NOT VALID. It then, after swap, validates all constraint
on the self table (primary) and referential tables (other tables with FK of primary
table). So that, no FK constraints are left in NOT VALID state.

Add smoke tests using pgbench (--foreign-keys)

Fixes: #61 #59

@shayonj shayonj force-pushed the s/fk-fix branch 3 times, most recently from fce9b44 to 9715f11 Compare March 13, 2022 19:35
@shayonj shayonj requested a review from jfrost March 13, 2022 19:38
Copy link
Collaborator

@jfrost jfrost left a comment

Choose a reason for hiding this comment

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

LGTM! I suggested a typo fix.

spec/lib/orchestrate_spec.rb Outdated Show resolved Hide resolved
Until now we were structuraly copying the primary
table into shadow table. While doing so, we were also
copying the FKs. This could lead to locks on other queries
running on the primary/dependent table.

This PR fixes it by not adding the FKs to the shadow table,
but adding the FK to the parent table itself from the same transaction,
during the swap with 'NOT VALID'. It then, after swap, validates all constraint
on the self table (primary) and referential tables (other tables with FK of primary
table). So that, no FK constraints are left in NOT VALID state.

Add smoke tests using pgbench (--foreign-keys)
@jfrost
Copy link
Collaborator

jfrost commented Mar 13, 2022

Ready to merge when tests pass!

@shayonj shayonj merged commit f47f7aa into main Mar 13, 2022
@shayonj shayonj deleted the s/fk-fix branch March 13, 2022 20:06
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.

Integration/smoke test
2 participants