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 improvements for SSMS query while trying to expand stored procedures #1923

Conversation

basasairohan
Copy link
Contributor

@basasairohan basasairohan commented Oct 16, 2023

Description

Currently, the SSMS query to expand stored procedures is found to be very slow (~ 6 hours for 1000 procedures).
The bad performance is found to be majorly occuring from sys.all_objects view. So, the following modifications have been done to the sys.all_objects :

  1. Bad row estimation arising due to the is_ms_shipped column in sys.all_objects view. This change fixes it by pushing down the computation of is_ms_shipped column to the respective unions.
  2. Made the datatype of type and name column consistent and removed the outer CAST as we are already casting them in the respective UNIONs.
  3. Removed subqueries and replaced them with suitable JOINs for better query planning.

Signed-off-by: Sai Rohan Basa [email protected]

Issues Resolved

BABEL-4008

Test Scenarios Covered

  • Use case based - Tests for sys.all_objects are already present in sys_all_objects-vu-* files

  • Boundary conditions - N/A

  • Arbitrary inputs - N/A

  • Negative test cases - N/A

  • Minor version upgrade tests - N/A

  • Major version upgrade tests - N/A

  • Performance tests - Evaluated the performance before and after making the changes. Here are the results for 1000 stored procedures.

Before : Execution time = ~ 9 mins , Query Plan
After : Execution time = ~ 17 secs , Query Plan

  • Tooling impact - N/A

  • Client tests - N/A

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.

where t.relkind = 'v'
and (s.nspname = 'sys' or (nis.name is not null and ext.nspname is not null))
and has_schema_privilege(s.oid, 'USAGE')
and has_table_privilege(quote_ident(s.nspname) ||'.'||quote_ident(t.relname), 'SELECT,INSERT,UPDATE,DELETE,TRUNCATE,TRIGGER')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call has_table_privilege with t.oid. The string creation seems redundant

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

and has_schema_privilege(s.oid, 'USAGE')
and has_table_privilege(t.oid, 'SELECT,INSERT,UPDATE,DELETE,TRUNCATE,TRIGGER')

union all
-- details of user defined and system views
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add comment on these additional unions on why they are needed

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

case
when t.typname = 'trigger'
then 'TR'::char(2)
when p.proretset then
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this valid for TSQL?

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.

@Deepesh125 Deepesh125 merged commit 64d91ac into babelfish-for-postgresql:BABEL_3_X_DEV Oct 25, 2023
27 checks passed
@Deepesh125 Deepesh125 deleted the jira-babel-4008-2 branch October 25, 2023 10:18
basasairohan added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Oct 26, 2023
… procedures (babelfish-for-postgresql#1923)

Currently, the SSMS query to expand stored procedures is found to be very slow (~ 6 hours for 1000 procedures).
The bad performance is found to be majorly occurring from sys.all_objects view. So, the following modifications have
been done to the sys.all_objects :

Bad row estimation arising due to the is_ms_shipped column in sys.all_objects view. This change fixes it by pushing
down the computation of is_ms_shipped column to the respective unions.

Made the datatype of type and name column consistent and removed the outer CAST as we are already casting them in
the respective UNIONs.

Removed subqueries and replaced them with suitable JOINs for better query planning.

Task: BABEL-4008
Signed-off-by: Sai Rohan Basa <[email protected]>
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