-
Notifications
You must be signed in to change notification settings - Fork 105
Parse cursor queries with antlr before executing #3777
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
base: BABEL_5_X_DEV
Are you sure you want to change the base?
Parse cursor queries with antlr before executing #3777
Conversation
Pull Request Test Coverage Report for Build 15712163874Warning: 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
💛 - Coveralls |
* Antlr parser will converts TSQL query into PSQL syntax and properly handles idenfier delimiters, | ||
* allowing PostgreSQL reserved words to be used as column aliases. | ||
*/ | ||
if (stmt != NULL && sql_dialect == SQL_DIALECT_TSQL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ANTLR can be a pretty heavy parser, so we maintain a session level cache for the ANTLR parse result for a procedure's body. Again invoking ANTLR here for sp_cursor procs would mean we always ANTLR parse during runtime.
Can we avoid that by doing this in the first parse of the statement itself ?
* Antlr parser will converts TSQL query into PSQL syntax and properly handles idenfier delimiters, | ||
* allowing PostgreSQL reserved words to be used as column aliases. | ||
*/ | ||
if (prepare && stmt != NULL && sql_dialect == SQL_DIALECT_TSQL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge this block with the prepare block below ? Also why do we need dialect check here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't merge it because we want to parse before creating SPI connection because if parse fails SPI connection is not required. Since SPI connection is used outside prepare if statement added it separately before SPI connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dialect I added as safety as antlr parser should be used only for TSQL context right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we will ever reach here in non TSQL dialect, can you please confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified its only getting called through ProcessTDSRequest->ProcessRPCRequest->HandleSPCursorOpenCommon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we dont need the TSQL Dialect check, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I can remove that.
* Antlr parser will converts TSQL query into PSQL syntax and properly handles idenfier delimiters, | ||
* allowing PostgreSQL reserved words to be used as column aliases. | ||
*/ | ||
if (prepare && stmt != NULL && sql_dialect == SQL_DIALECT_TSQL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we will ever reach here in non TSQL dialect, can you please confirm?
*/ | ||
if (prepare && stmt != NULL && sql_dialect == SQL_DIALECT_TSQL) | ||
{ | ||
pltsql_curr_compile = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to set this locally?
4d4b7c1
to
8e44cf5
Compare
* Antlr parser will converts TSQL query into PSQL syntax and properly handles idenfier delimiters, | ||
* allowing PostgreSQL reserved words to be used as column aliases. | ||
*/ | ||
if (prepare && stmt != NULL && sql_dialect == SQL_DIALECT_TSQL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we dont need the TSQL Dialect check, right?
if (pltsql_curr_compile) | ||
collation = pltsql_curr_compile->fn_input_collation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a possibility that pltsql_curr_compile is NULL here? Thats serious isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If its NULL then we will not access it. It will be the assigned value above InvalidOid. Before it was causing seg fault because we were accessing it without null check below so added this.
Please also add test cases for sp_cursor procedures. |
Description
Cursor queries are not parsed with antlr parser before sending it to Postgres parser, which leads to syntax error if there is any psql related keywords in the query. Antlr parser transforms the query by delimit the psql keywords in the query. Adding antlr parser logic for CURSOR queries in Pabelfish before sending it to Postgres for execution.
Issues Resolved
BABEL-5743
Test Scenarios Covered
Use case based -
Yes
Boundary conditions -
Yes
Arbitrary inputs -
Yes
Negative test cases -
Yes
Minor version upgrade tests -
NA
Major version upgrade tests -
NA
Performance tests -
NA
Tooling impact -
NA
Client tests -
NA
Check List
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.