• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

babelfish-for-postgresql / babelfish_extensions / 11908748001

19 Nov 2024 08:08AM UTC coverage: 74.744% (+0.02%) from 74.723%
11908748001

push

github

web-flow
Make local variable to evaluate dynamically (only if it appears on TargetList) (#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>

116 of 119 new or added lines in 4 files covered. (97.48%)

14 existing lines in 2 files now uncovered.

45720 of 61169 relevant lines covered (74.74%)

162746.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.3
/contrib/babelfishpg_tsql/src/tsqlIface.cpp


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc