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

Fix issue with sp_tables failing for cross-database table qualifiers #2961

Conversation

roshan0708
Copy link
Contributor

@roshan0708 roshan0708 commented Sep 23, 2024

Description

This change fixes an issue with the sp_tables stored procedure, which incorrectly handled three-part object names across databases, throwing an error regarding database context. The root cause was sys.db_name() returning the wrong database name based on the object qualifier.

The issue affected the usability of linked servers in Babelfish, as it prevented accurate metadata retrieval, limiting compatibility with SQL Server.

The fix replaced sys.db_name() with a direct SELECT sys.db_name() to fetch the correct database name before comparing it against the table_qualifier.

SSMS Testing

Created 3 databases - master, roshan, and testdb and some dummy tables and views to execute sp_tables procedure.
Screenshot 2024-09-27 at 4 01 50 PM

Issues Resolved

Task: BABEL-5263

Test Scenarios Covered

  • Use case based - yes

  • Boundary conditions - yes

  • Arbitrary inputs - yes

  • Negative test cases - yes

  • Minor version upgrade tests -

  • Major version upgrade tests -

  • Performance tests -

  • Tooling impact -

  • Client tests -

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.

This fix resolves the issue where sp_tables fails when a three-part
object name is used with a database qualifier different from the current
database. The root cause was identified as sys.db_name() returning the
incorrect database name based on the object qualifier in certain contexts.
By replacing this with a direct select of sys.db_name(), the correct
database name is fetched ensuring proper handling of cross-database references.

Task: BABEL-5263
Signed-off-by: Roshan Kanwar <[email protected]>
@coveralls
Copy link
Collaborator

coveralls commented Sep 24, 2024

Pull Request Test Coverage Report for Build 11013371085

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.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 74.464%

Totals Coverage Status
Change from base Build 11001733306: 0.003%
Covered Lines: 44931
Relevant Lines: 60339

💛 - Coveralls

@KushaalShroff
Copy link
Contributor

LGTM but need verification on fix for SSMS. Lets add the testing done with SSMS to the description.

@shardgupta shardgupta merged commit ba6df87 into babelfish-for-postgresql:BABEL_4_X_DEV Sep 27, 2024
46 checks passed
@shardgupta shardgupta deleted the JIRA-BABEL-5263 branch September 27, 2024 10:58
roshan0708 added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Sep 27, 2024
…abelfish-for-postgresql#2961)

This change fixes an issue with the sp_tables stored procedure, which incorrectly handled three-part object names across databases, throwing an error regarding database context. The root cause was sys.db_name() returning the wrong database name based on the object qualifier.

The issue affected the usability of linked servers in Babelfish, as it prevented accurate metadata retrieval, limiting compatibility with SQL Server.

The fix replaced sys.db_name() with a direct SELECT sys.db_name() to fetch the correct database name before comparing it against the table_qualifier.

Task: BABEL-5263

Signed-off-by: Roshan Kanwar <[email protected]>
shardgupta pushed a commit that referenced this pull request Sep 27, 2024
…2961) (#2984)

This change fixes an issue with the sp_tables stored procedure, which incorrectly handled three-part object names across databases, throwing an error regarding database context. The root cause was sys.db_name() returning the wrong database name based on the object qualifier.

The issue affected the usability of linked servers in Babelfish, as it prevented accurate metadata retrieval, limiting compatibility with SQL Server.

The fix replaced sys.db_name() with a direct SELECT sys.db_name() to fetch the correct database name before comparing it against the table_qualifier.

Task: BABEL-5263

Signed-off-by: Roshan Kanwar <[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.

5 participants