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

Make local variable to evaluate dynamically (only if it appears on TargetList) #3011

Merged

Conversation

Deepesh125
Copy link
Contributor

@Deepesh125 Deepesh125 commented Oct 8, 2024

Description

Currently, declared local variables are assumed to be static by analyser and hence it is replaced with const node by optimiser. Currently, the parameter value will be supplied through pltsql_param_fetch(..) which is setup during pltsql_estate_setup as part of ParamListInfo setup. This hook is purely used during planning phase and is not used during query execution.

If parameter value is required during execution then values will be read from estate->ndatums through pltsql_param_eval_var callback for EEOP_PARAM_CALLBACK step. This estate->ndatums setup during pltsql_estate_setup and values are copied through copy_pltsql_datums(…). And currently, any assignments to declare variables are implemented using "select target" which will be executed at the end of executor. Hence, any use of variables will read original (value copied during pltsql_estate_setup(...)) and it would not reflect any dynamic change in the value of any variable.

In order to make this behaviour dynamic, this commit introduces internal function sys.pltsql_assign_var(dno, expr). Argument dno is item number of declared variable and expr could be anything whose value will be assigned to declared variable pointed by dno during execution. We will use this function to rewrite any variables assignment operation during ANTLR parsing as stated in following example,

select @a = expr

Will be written to

select @a = sys.pltsql_assign_var(dno, expr)

Internally, sys.pltsql_assign_var invokes exec_assign_value(…) to assign appropriate value directly to variable by updating estate->ndatums array and hence any subsequent read will read latest value.

Engine PR: babelfish-for-postgresql/postgresql_modified_for_babelfish#469
Task: BABEL-5325
Signed-off-by: Dipesh Dhameliya dddhamel@amazon.com

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 Oct 15, 2024

Pull Request Test Coverage Report for Build 11839208255

Details

  • 116 of 119 (97.48%) changed or added relevant lines in 4 files are covered.
  • 14 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 74.742%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contrib/babelfishpg_tsql/src/tsqlIface.cpp 86 89 96.63%
Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tsql/src/tsqlIface.cpp 4 90.29%
contrib/babelfishpg_tsql/src/hooks.c 10 83.51%
Totals Coverage Status
Change from base Build 11831695974: 0.02%
Covered Lines: 45715
Relevant Lines: 61164

💛 - Coveralls

test/JDBC/expected/BABEL-2843.out Outdated Show resolved Hide resolved
test/JDBC/expected/BABEL-1181.out Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_exec.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/tsqlIface.cpp Show resolved Hide resolved
test/JDBC/expected/test_dynamic_local_vars.out Outdated Show resolved Hide resolved
test/JDBC/expected/test_dynamic_local_vars.out Outdated Show resolved Hide resolved
@Deepesh125 Deepesh125 changed the title Make local variable to evaluate dynamically Make local variable to evaluate dynamically (only if it appears on TargetList) Nov 12, 2024
contrib/babelfishpg_tsql/src/pl_exec.c Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_exec.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_exec.c Show resolved Hide resolved
test/JDBC/input/test_dynamic_local_vars.sql Show resolved Hide resolved
Deepesh125 added a commit to babelfish-for-postgresql/postgresql_modified_for_babelfish that referenced this pull request Nov 19, 2024
…ext of expression being processed (#469)

Extend the ability of planner_node_transformer_hook to store the context of expression being process. This saved context will be used during planning to transform declared variable either as a Param (if it appears in TargetList) or as a const (all the other places).

Extension: babelfish-for-postgresql/babelfish_extensions#3011
Task: BABEL-5188
Signed-off-by: Dipesh Dhameliya <dddhamel@amazon.com>
@Deepesh125 Deepesh125 merged commit 6be12f1 into babelfish-for-postgresql:BABEL_4_X_DEV Nov 19, 2024
46 checks passed
@Deepesh125 Deepesh125 deleted the jira-babel-5188 branch November 19, 2024 08:08
roshan0708 pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Nov 20, 2024
…ext of expression being processed (babelfish-for-postgresql#469)

Extend the ability of planner_node_transformer_hook to store the context of expression being process. This saved context will be used during planning to transform declared variable either as a Param (if it appears in TargetList) or as a const (all the other places).

Extension: babelfish-for-postgresql/babelfish_extensions#3011
Task: BABEL-5188
Signed-off-by: Dipesh Dhameliya <dddhamel@amazon.com>
roshan0708 pushed a commit to amazon-aurora/babelfish_extensions that referenced this pull request Nov 20, 2024
…rgetList) (babelfish-for-postgresql#3011)

Currently, declared local variables are assumed to be static by analyser and hence it is replaced with const node by
optimiser. Currently, the parameter value will be supplied through pltsql_param_fetch(..) which is setup during
pltsql_estate_setup as part of ParamListInfo setup. This hook is purely used during planning phase and is not used
during query execution.

If parameter value is required during execution then values will be read from estate->ndatums through
pltsql_param_eval_var callback for EEOP_PARAM_CALLBACK step. This estate->ndatums setup during
pltsql_estate_setup and values are copied through copy_pltsql_datums(…). And currently, any assignments to declare
variables are implemented using "select target" which will be executed at the end of executor. Hence, any use of
variables will read original (value copied during pltsql_estate_setup(...)) and it would not reflect any dynamic change in
the value of any variable.

In order to make this behaviour dynamic, this commit introduces internal function sys.pltsql_assign_var(dno, expr).
Argument dno is item number of declared variable and expr could be anything whose value will be assigned to declared
variable pointed by dno during execution. We will use this function to rewrite any variables assignment operation during
ANTLR parsing as stated in following example,

select @A = expr

Will be written to

select @A = sys.pltsql_assign_var(dno, expr)

Internally, sys.pltsql_assign_var invokes exec_assign_value(…) to assign appropriate value directly to variable by
updating estate->ndatums array and hence any subsequent read will read latest value.

Engine PR: babelfish-for-postgresql/postgresql_modified_for_babelfish#469
Task: BABEL-5325
Signed-off-by: Dipesh Dhameliya <dddhamel@amazon.com>
roshan0708 pushed a commit to amazon-aurora/babelfish_extensions that referenced this pull request Nov 20, 2024
…rgetList) (babelfish-for-postgresql#3011)

Currently, declared local variables are assumed to be static by analyser and hence it is replaced with const node by
optimiser. Currently, the parameter value will be supplied through pltsql_param_fetch(..) which is setup during
pltsql_estate_setup as part of ParamListInfo setup. This hook is purely used during planning phase and is not used
during query execution.

If parameter value is required during execution then values will be read from estate->ndatums through
pltsql_param_eval_var callback for EEOP_PARAM_CALLBACK step. This estate->ndatums setup during
pltsql_estate_setup and values are copied through copy_pltsql_datums(…). And currently, any assignments to declare
variables are implemented using "select target" which will be executed at the end of executor. Hence, any use of
variables will read original (value copied during pltsql_estate_setup(...)) and it would not reflect any dynamic change in
the value of any variable.

In order to make this behaviour dynamic, this commit introduces internal function sys.pltsql_assign_var(dno, expr).
Argument dno is item number of declared variable and expr could be anything whose value will be assigned to declared
variable pointed by dno during execution. We will use this function to rewrite any variables assignment operation during
ANTLR parsing as stated in following example,

select @A = expr

Will be written to

select @A = sys.pltsql_assign_var(dno, expr)

Internally, sys.pltsql_assign_var invokes exec_assign_value(…) to assign appropriate value directly to variable by
updating estate->ndatums array and hence any subsequent read will read latest value.

Engine PR: babelfish-for-postgresql/postgresql_modified_for_babelfish#469
Task: BABEL-5325
Signed-off-by: Dipesh Dhameliya <dddhamel@amazon.com>
Deepesh125 added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Nov 21, 2024
…rgetList) (babelfish-for-postgresql#3011)

Currently, declared local variables are assumed to be static by analyser and hence it is replaced with const node by
optimiser. Currently, the parameter value will be supplied through pltsql_param_fetch(..) which is setup during
pltsql_estate_setup as part of ParamListInfo setup. This hook is purely used during planning phase and is not used
during query execution.

If parameter value is required during execution then values will be read from estate->ndatums through
pltsql_param_eval_var callback for EEOP_PARAM_CALLBACK step. This estate->ndatums setup during
pltsql_estate_setup and values are copied through copy_pltsql_datums(…). And currently, any assignments to declare
variables are implemented using "select target" which will be executed at the end of executor. Hence, any use of
variables will read original (value copied during pltsql_estate_setup(...)) and it would not reflect any dynamic change in
the value of any variable.

In order to make this behaviour dynamic, this commit introduces internal function sys.pltsql_assign_var(dno, expr).
Argument dno is item number of declared variable and expr could be anything whose value will be assigned to declared
variable pointed by dno during execution. We will use this function to rewrite any variables assignment operation during
ANTLR parsing as stated in following example,

select @A = expr

Will be written to

select @A = sys.pltsql_assign_var(dno, expr)

Internally, sys.pltsql_assign_var invokes exec_assign_value(…) to assign appropriate value directly to variable by
updating estate->ndatums array and hence any subsequent read will read latest value.

Engine PR: babelfish-for-postgresql/postgresql_modified_for_babelfish#469
Task: BABEL-5325
Signed-off-by: Dipesh Dhameliya <dddhamel@amazon.com>
rishabhtanwar29 pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Nov 25, 2024
…ext of expression being processed (babelfish-for-postgresql#469)

Extend the ability of planner_node_transformer_hook to store the context of expression being process. This saved context will be used during planning to transform declared variable either as a Param (if it appears in TargetList) or as a const (all the other places).

Extension: babelfish-for-postgresql/babelfish_extensions#3011
Task: BABEL-5188
Signed-off-by: Dipesh Dhameliya <dddhamel@amazon.com>
rishabhtanwar29 pushed a commit to amazon-aurora/babelfish_extensions that referenced this pull request Nov 25, 2024
…rgetList) (babelfish-for-postgresql#3011)

Currently, declared local variables are assumed to be static by analyser and hence it is replaced with const node by
optimiser. Currently, the parameter value will be supplied through pltsql_param_fetch(..) which is setup during
pltsql_estate_setup as part of ParamListInfo setup. This hook is purely used during planning phase and is not used
during query execution.

If parameter value is required during execution then values will be read from estate->ndatums through
pltsql_param_eval_var callback for EEOP_PARAM_CALLBACK step. This estate->ndatums setup during
pltsql_estate_setup and values are copied through copy_pltsql_datums(…). And currently, any assignments to declare
variables are implemented using "select target" which will be executed at the end of executor. Hence, any use of
variables will read original (value copied during pltsql_estate_setup(...)) and it would not reflect any dynamic change in
the value of any variable.

In order to make this behaviour dynamic, this commit introduces internal function sys.pltsql_assign_var(dno, expr).
Argument dno is item number of declared variable and expr could be anything whose value will be assigned to declared
variable pointed by dno during execution. We will use this function to rewrite any variables assignment operation during
ANTLR parsing as stated in following example,

select @A = expr

Will be written to

select @A = sys.pltsql_assign_var(dno, expr)

Internally, sys.pltsql_assign_var invokes exec_assign_value(…) to assign appropriate value directly to variable by
updating estate->ndatums array and hence any subsequent read will read latest value.

Engine PR: babelfish-for-postgresql/postgresql_modified_for_babelfish#469
Task: BABEL-5325
Signed-off-by: Dipesh Dhameliya <dddhamel@amazon.com>
shardgupta pushed a commit to babelfish-for-postgresql/postgresql_modified_for_babelfish that referenced this pull request Nov 25, 2024
…ext of expression being processed (#469)

Extend the ability of planner_node_transformer_hook to store the context of expression being process. This saved context will be used during planning to transform declared variable either as a Param (if it appears in TargetList) or as a const (all the other places).

Extension: babelfish-for-postgresql/babelfish_extensions#3011
Task: BABEL-5188
Signed-off-by: Dipesh Dhameliya <dddhamel@amazon.com>
shardgupta pushed a commit that referenced this pull request Nov 25, 2024
…rgetList) (#3011)

Currently, declared local variables are assumed to be static by analyser and hence it is replaced with const node by
optimiser. Currently, the parameter value will be supplied through pltsql_param_fetch(..) which is setup during
pltsql_estate_setup as part of ParamListInfo setup. This hook is purely used during planning phase and is not used
during query execution.

If parameter value is required during execution then values will be read from estate->ndatums through
pltsql_param_eval_var callback for EEOP_PARAM_CALLBACK step. This estate->ndatums setup during
pltsql_estate_setup and values are copied through copy_pltsql_datums(…). And currently, any assignments to declare
variables are implemented using "select target" which will be executed at the end of executor. Hence, any use of
variables will read original (value copied during pltsql_estate_setup(...)) and it would not reflect any dynamic change in
the value of any variable.

In order to make this behaviour dynamic, this commit introduces internal function sys.pltsql_assign_var(dno, expr).
Argument dno is item number of declared variable and expr could be anything whose value will be assigned to declared
variable pointed by dno during execution. We will use this function to rewrite any variables assignment operation during
ANTLR parsing as stated in following example,

select @A = expr

Will be written to

select @A = sys.pltsql_assign_var(dno, expr)

Internally, sys.pltsql_assign_var invokes exec_assign_value(…) to assign appropriate value directly to variable by
updating estate->ndatums array and hence any subsequent read will read latest value.

Engine PR: babelfish-for-postgresql/postgresql_modified_for_babelfish#469
Task: BABEL-5325
Signed-off-by: Dipesh Dhameliya <dddhamel@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.

4 participants