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 #3241

Open
wants to merge 5 commits into
base: BABEL_4_X_DEV
Choose a base branch
from

Conversation

sumitj824
Copy link
Contributor

@sumitj824 sumitj824 commented Dec 12, 2024

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.

Sumit Jaiswal added 2 commits December 12, 2024 08:50
…INTS and KEY_COLUMN_USAGE views

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

coveralls commented Dec 12, 2024

Pull Request Test Coverage Report for Build 12314271462

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1738 unchanged lines in 14 files lost coverage.
  • Overall coverage increased (+0.1%) to 74.832%

Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tsql/src/schemacmds.c 2 92.54%
contrib/babelfishpg_tsql/src/pl_funcs-2.c 3 45.82%
contrib/babelfishpg_tsql/src/pl_funcs.c 4 18.95%
contrib/babelfishpg_tsql/src/session.c 5 97.41%
contrib/babelfishpg_tsql/src/procedures.c 62 88.76%
contrib/babelfishpg_tsql/src/pltsql_utils.c 67 92.12%
contrib/babelfishpg_tsql/src/multidb.c 77 82.69%
contrib/babelfishpg_tds/src/backend/tds/tdsutils.c 110 73.66%
contrib/babelfishpg_tsql/src/rolecmds.c 159 85.11%
contrib/babelfishpg_tsql/src/pl_exec-2.c 219 82.24%
Totals Coverage Status
Change from base Build 12278087977: 0.1%
Covered Lines: 46509
Relevant Lines: 62151

💛 - Coveralls

Sumit Jaiswal added 3 commits December 12, 2024 11:09
Signed-off-by: Sumit Jaiswal <sumiji@amazon.com>
Signed-off-by: Sumit Jaiswal <sumiji@amazon.com>
Signed-off-by: Sumit Jaiswal <sumiji@amazon.com>
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.

3 participants