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

Performance improvement for queries having join between TABLE_CONSTRAINTS and KEY_COLUMN_USAGE views #3257

Open
wants to merge 1 commit into
base: BABEL_3_X_DEV
Choose a base branch
from

Conversation

sumitj824
Copy link
Contributor

Description

This commit addresses poor performance issues in queries that join the TABLE_CONSTRAINTS and KEY_COLUMN_USAGE views. The problem was caused by inaccurate row estimates resulting from a CASE expression in the TABLE_CONSTRAINTS view, leading to suboptimal query plans.

Signed-off-by: Sumit Jaiswal sumiji@amazon.com

Issues Resolved

Task: BABEL-5427

Test Scenarios Covered

Test are already present for modified views.

Performance Result

  1. Improvement for query having join between TABLE_CONSTRAINTS and KEY_COLUMN_USAGE:
Objects Before (ms) After (ms) Improvement %
1181 tables and primary key constraints 4781 87 98.18%
3000 tables and primary key constraints 33011 98 99.70%
3000 tables, primary key, unique and check constraints 14173 116 99.18%

2 Improvement for different queries:

Objects Query Before (ms) After (ms) Improvement %
1181 tables and primary key constraints SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS 29 32.2 -11.03%
^ SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = 't456' 38 33.6 11.58%
^ SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA = 'dbo' 13.8 16.8 -21.74%
^ SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'PRIMARY KEY' 24.4 16.6 31.97%
^ SELECT * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE 22 20.2 8.18%
^ SELECT * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = 't456' 8 6.4 20%
^ SELECT * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = 'dbo' 21.4 19.2 10.28%
3000 tables, primary key, unique and check constraints SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS 105.2 128 -21.67%
^ SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = 't456' 79.8 58.2 27.07%
^ SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA = 'dbo' 77.8 100.6 -29.31%
^ SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'PRIMARY KEY' 61.4 53.2 13.36%
^ SELECT * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE 71.4 65.6 8.12%
^ SELECT * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = 't456' 12 10 16.67%
^ SELECT * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = 'dbo' 75.6 67.2 11.11%

NOTE: We don't observe ANY degradation if we have 100 user schemas

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…INTS and KEY_COLUMN_USAGE views

Signed-off-by: Sumit Jaiswal <sumiji@amazon.com>
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 12314800454

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 73.811%

Totals Coverage Status
Change from base Build 12314489542: 0.0%
Covered Lines: 43164
Relevant Lines: 58479

💛 - Coveralls

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