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

Reset cross-db flag for each statement #3237

Conversation

HarshLunagariya
Copy link
Contributor

@HarshLunagariya HarshLunagariya commented Dec 11, 2024

Description

Earlier, while parsing the batch, We were marking the all the subsequent statements of the batch as cross-database statements once we encounter any cross-database statement in batch which was incorrect.

This commit fixes above behaviour by resetting 'is_cross_db' maintained at mutator level once we mark some statement as cross_db in the parse tree.

Issues Resolved

BABEL-5447

Test Scenarios Covered

  • Use case based -

  • Boundary conditions -

  • Arbitrary inputs -

  • Negative test cases -

  • 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.

@coveralls
Copy link
Collaborator

coveralls commented Dec 11, 2024

Pull Request Test Coverage Report for Build 12408305896

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 74.823%

Totals Coverage Status
Change from base Build 12395755914: 0.0%
Covered Lines: 46478
Relevant Lines: 62117

💛 - Coveralls

Signed-off-by: Harsh Lunagariya <[email protected]>
@HarshLunagariya HarshLunagariya changed the title [DO NOT MERGE] Reset cross-db flag for each statement Reset cross-db flag for each statement Dec 13, 2024
Copy link
Contributor

@shalinilohia50 shalinilohia50 left a comment

Choose a reason for hiding this comment

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

LGTM!

GO

-- Batches having system objects
BEGIN; SELECT DISTINCT 1 FROM my_babel_cross_db_vu_prepare_db1.dbo.sysdatabases; BEGIN; SELECT DISTINCT 1 FROM babel_cross_db_vu_prepare_master_t1; END; END;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Let's also add test where we call sys objects as well like db1.sys.databases etc.
  2. Create temp tables after executing cross-db stmt as DDL permissions work differently.

Copy link
Contributor

@anju15bharti anju15bharti Dec 13, 2024

Choose a reason for hiding this comment

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

Also let's include below cases:

  1. tests for statements in batch inside a transaction.
  2. some cases where login/user has some default db and schemas with it and it's executing one cross-db query with other queries in a batch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Let's also add test where we call sys objects as well like db1.sys.databases etc.
  • Create temp tables after executing cross-db stmt as DDL permissions work differently.

Done.

Also let's include below cases:

  1. tests for statements in batch inside a transaction.
  2. some cases where login/user has some default db and schemas with it and it's executing one cross-db query with other queries in a batch.

Regarding, 2nd point - not adding anything for default db setting since it doesn't affect anything while query execution. It is only utilised while setting up a new db session.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

regarding default_schema, It is being tracked by BABEL-5050, needs separate fix.

GO

-- Batches having system objects
BEGIN; SELECT DISTINCT 1 FROM my_babel_cross_db_vu_prepare_db1.dbo.sysdatabases; BEGIN; SELECT DISTINCT 1 FROM babel_cross_db_vu_prepare_master_t1; END; END;
Copy link
Contributor

@anju15bharti anju15bharti Dec 13, 2024

Choose a reason for hiding this comment

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

Also let's include below cases:

  1. tests for statements in batch inside a transaction.
  2. some cases where login/user has some default db and schemas with it and it's executing one cross-db query with other queries in a batch.

Signed-off-by: Harsh Lunagariya <[email protected]>
stmt->is_cross_db = true;
is_cross_db = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

We are also setting this flag to true in makeExecuteProcedure but not resetting it back. What would happen if we exec a batch like

EXEC db.dbo.p
SELECT * FROM t

Copy link
Contributor

@tanscorpio7 tanscorpio7 Dec 16, 2024

Choose a reason for hiding this comment

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

can we reset is_cross_db in enterDMLStatement ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also seems like we can just remove use of this flag from makeExecuteProcedure

Copy link
Contributor Author

@HarshLunagariya HarshLunagariya Dec 16, 2024

Choose a reason for hiding this comment

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

Also seems like we can just remove use of this flag from makeExecuteProcedure

Yes, I noticed it too. On top of that we can cleanup some logic from pl_exec as well. We should track it separately because I assume there we will need more test coverage, can't just rely on existing tests to conclude that given logic is redundant.

can we reset is_cross_db in enterDMLStatement ?

Done.

Signed-off-by: Harsh Lunagariya <[email protected]>
Signed-off-by: Harsh Lunagariya <[email protected]>
KushaalShroff
KushaalShroff previously approved these changes Dec 18, 2024
~~ROW COUNT: 4~~


SELECT * FROM my_babel_cross_db_vu_prepare_db1.dbo.babel_cross_db_vu_prepare_db1_t1;
Copy link
Contributor

Choose a reason for hiding this comment

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

This one needs an ORDER BY clause or else it will be flaky.

~~ROW COUNT: 1~~


SELECT * FROM my_babel_cross_db_vu_prepare_db1.dbo.babel_cross_db_vu_prepare_db1_t1;
Copy link
Contributor

Choose a reason for hiding this comment

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

This one also needs an ORDER BY clause.

~~ROW COUNT: 1~~


SELECT * FROM dbo.my_babel_cross_db_vu_prepare_db1_t2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, needs ORDER BY.

Signed-off-by: Harsh Lunagariya <[email protected]>
@rishabhtanwar29 rishabhtanwar29 merged commit d2e7653 into babelfish-for-postgresql:BABEL_5_X_DEV Dec 19, 2024
44 checks passed
@rishabhtanwar29 rishabhtanwar29 deleted the babel_cbd_imp branch December 19, 2024 08:57
HarshLunagariya added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Dec 24, 2024
Earlier, while parsing the batch, We were marking the all the subsequent statements of the batch as cross-database statements once we encounter any cross-database statement in batch which was incorrect.

This commit fixes above behaviour by resetting 'is_cross_db' maintained at mutator level once we mark some statement as cross_db in the parse tree.

Task: BABEL-5447
Signed-off-by: Harsh Lunagariya <[email protected]>
HarshLunagariya added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Dec 24, 2024
Earlier, while parsing the batch, We were marking the all the subsequent statements of the batch as cross-database statements once we encounter any cross-database statement in batch which was incorrect.

This commit fixes above behaviour by resetting 'is_cross_db' maintained at mutator level once we mark some statement as cross_db in the parse tree.

Task: BABEL-5447
Signed-off-by: Harsh Lunagariya <[email protected]>
rishabhtanwar29 pushed a commit that referenced this pull request Dec 24, 2024
Earlier, while parsing the batch, We were marking the all the subsequent statements of the batch as cross-database statements once we encounter any cross-database statement in batch which was incorrect.

This commit fixes above behaviour by resetting 'is_cross_db' maintained at mutator level once we mark some statement as cross_db in the parse tree.

Cherry-pick of d2e7653

Task: BABEL-5447
Signed-off-by: Harsh Lunagariya <[email protected]>
rishabhtanwar29 pushed a commit that referenced this pull request Dec 24, 2024
Earlier, while parsing the batch, We were marking the all the subsequent statements of the batch as cross-database statements once we encounter any cross-database statement in batch which was incorrect.

This commit fixes above behaviour by resetting 'is_cross_db' maintained at mutator level once we mark some statement as cross_db in the parse tree.

Cherry-pick of d2e7653

Task: BABEL-5447
Signed-off-by: Harsh Lunagariya <[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.

7 participants