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

Improve dropAllForeignKeyConstraints performance #2155

Conversation

Spindl
Copy link
Contributor

@Spindl Spindl commented Oct 22, 2021

Impact

  • Bug fix (non-breaking change which fixes expected existing functionality)
  • [] Enhancement/New feature (adds functionality without impacting existing logic)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

The dropAllForeignKeyConstraints change performs poorly for bigger database schemas in PostgreSQL databases, because more or less the complete schema metadata is loaded for finding the names of the foreign key constraints of a single table. Control was create but wasn't used.

Fixes #2154
Fixes #1571

Things to be aware of

  • Test coverage on DropAllForeignKeyConstraintsChangeTest .

Things to worry about

  • none

@molivasdat
Copy link
Contributor

Hi @Spindl Thanks for the issue and PR creation. We will add this to the list of issues and PRs that we are processing.
A member of the Liquibase team will take a look at your contribution and may suggest:

The PR will be prioritized according to our internal development and testing capacity.

We’ll let you know when it’s ready to move to the next step or if any changes are needed.

@filipelautert filipelautert self-assigned this Nov 4, 2022
@filipelautert filipelautert added the SafeToBuild Indicates that a particular PR contains changes which are safe to build using GitHub actions label Nov 4, 2022
@github-actions
Copy link

github-actions bot commented Nov 4, 2022

Unit Test Results

  4 668 files  ±0    4 668 suites  ±0   29m 15s ⏱️ - 4m 23s
  4 645 tests ±0    4 419 ✔️ ±0     226 💤 ±0  0 ±0 
54 744 runs  ±0  49 625 ✔️ ±0  5 119 💤 ±0  0 ±0 

Results for commit 1518214. ± Comparison against base commit 0f1cb97.

♻️ This comment has been updated with latest results.

@filipelautert
Copy link
Collaborator

Hi @Spindl - so from what I see this fall under the "bug fix" section right? Control was create but wasn't used.
Also about #1571, seems it is the same issue. So we can add mark it as fixing this one too.
I did some runs with your text data and it really speeds up things:

Original:
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 489ms
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 523ms
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 451ms
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 467ms
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 470ms
 
 
 Fix:
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 278ms
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 303ms
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 252ms
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 228ms
 db.foreignKeyDeletionTest.xml::dropTestForeignKeysSlow-1634818754::rsp ran successfully in 241ms

Also there is test coverage on DropAllForeignKeyConstraintsChangeTest .

Thanks!

@filipelautert filipelautert changed the title #2154: Adapts and uses snapshot control for getting FK Constraint names Improves dropAllForeignKeyConstraints by adapting and using snapshot control for getting FK Constraint names Nov 4, 2022
@filipelautert filipelautert self-requested a review November 4, 2022 21:54
@filipelautert filipelautert added SafeToBuild Indicates that a particular PR contains changes which are safe to build using GitHub actions and removed SafeToBuild Indicates that a particular PR contains changes which are safe to build using GitHub actions labels Nov 4, 2022
Copy link
Collaborator

@filipelautert filipelautert left a comment

Choose a reason for hiding this comment

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

Simple fix that improves performance as shown in my previous comment. Also there are test covering it.

Copy link
Contributor

@XDelphiGrl XDelphiGrl left a comment

Choose a reason for hiding this comment

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

This PR fixes a Postgres performance bug during foreign key drops. The fix sets a snapshotControl objects to ensure the entire schema metadata is not scanned to find matching foreign keys.

  • No additional testing required.

APPROVED

@nvoxland nvoxland changed the title Improves dropAllForeignKeyConstraints by adapting and using snapshot control for getting FK Constraint names Improve dropAllForeignKeyConstraints performance Nov 9, 2022
@filipelautert filipelautert merged commit 454c4e7 into liquibase:master Nov 18, 2022
@filipelautert filipelautert added this to the 4.18.0 milestone Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autocandidate complexityLocal criticalityBuilder DBAll DBPostgres featureSnapshot ImpactLow IntegrationAny performance RiskMedium Changes that require more testing or that affect many different code paths. SafeToBuild Indicates that a particular PR contains changes which are safe to build using GitHub actions Severity4 TypeEnhancement
Projects
Archived in project
7 participants