Repository navigation
Fix package datum misresolution in plisql_param_compile - #1381
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdjusts the varlena optimization check in ChangesPackage Constant Fast-Path Fix and Regression Test
Estimated code review effort: 2 (Simple) | ~12 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/pl/plisql/src/pl_exec.c (1)
7101-7118: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFix looks correct.
The added
!OidIsValid(((PLiSQL_var *) datum)->pkgoid)guard correctly prevents the fast path from misapplying to package-qualified datums, matching howget_package_datum_bydnodispatches onpkgoid. The explanatory comment is accurate and helpful.Minor nit:
datum->pkgoidis already accessible directly on the basePLiSQL_datumstruct (as used at Line 7145), so the cast to(PLiSQL_var *) datumhere is unnecessary.🧹 Optional cleanup
- if (isvarlena && dno == expr->target_param && expr->expr_simple_expr && - !OidIsValid(((PLiSQL_var *) datum)->pkgoid)) + if (isvarlena && dno == expr->target_param && expr->expr_simple_expr && + !OidIsValid(datum->pkgoid))🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pl/plisql/src/pl_exec.c` around lines 7101 - 7118, The fast-path guard in the PL/pgSQL parameter setup is correct, but the new `pkgoid` check is using an unnecessary cast to `PLiSQL_var` even though `pkgoid` is available on `PLiSQL_datum`. Update the condition in this `plisql_param_eval_var_check` selection logic to read `pkgoid` directly from `datum`, keeping the existing `dno`, `expr->target_param`, and `expr->expr_simple_expr` checks unchanged.src/oracle_test/regress/sql/ora_package.sql (1)
6133-6171: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider covering the non-constant variable case too.
The PR objectives mention the bug affects "repeated references to a package CONSTANT or variable," but this test only exercises the CONSTANT scenario. Since the underlying misresolution is about
dno/pkgoidhandling regardless of constant-ness, adding a parallel case for a mutable package variable would close the coverage gap.As per path instructions,
**/sql/*.sqlfiles should "Ensure comprehensive coverage of features."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/oracle_test/regress/sql/ora_package.sql` around lines 6133 - 6171, Add coverage for the mutable package variable path in this regression test, since the current `pkg_const_repeat_test` block only exercises `my_const` and does not verify repeated references to a package variable. Extend the existing `CREATE OR REPLACE PACKAGE`/`DO $$` test pattern to include a package variable alongside `my_const`, then reference it multiple times in separate assignments and assertions to confirm `plisql_param_compile`/`plisql_param_eval_var_check` resolve it correctly with the proper package namespace handling. Keep the new checks adjacent to the existing `pkg_const_repeat_test` scenario so the regression covers both constant and variable cases.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/oracle_test/regress/sql/ora_package.sql`:
- Around line 6133-6171: Add coverage for the mutable package variable path in
this regression test, since the current `pkg_const_repeat_test` block only
exercises `my_const` and does not verify repeated references to a package
variable. Extend the existing `CREATE OR REPLACE PACKAGE`/`DO $$` test pattern
to include a package variable alongside `my_const`, then reference it multiple
times in separate assignments and assertions to confirm
`plisql_param_compile`/`plisql_param_eval_var_check` resolve it correctly with
the proper package namespace handling. Keep the new checks adjacent to the
existing `pkg_const_repeat_test` scenario so the regression covers both constant
and variable cases.
In `@src/pl/plisql/src/pl_exec.c`:
- Around line 7101-7118: The fast-path guard in the PL/pgSQL parameter setup is
correct, but the new `pkgoid` check is using an unnecessary cast to `PLiSQL_var`
even though `pkgoid` is available on `PLiSQL_datum`. Update the condition in
this `plisql_param_eval_var_check` selection logic to read `pkgoid` directly
from `datum`, keeping the existing `dno`, `expr->target_param`, and
`expr->expr_simple_expr` checks unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2da596ae-ee22-433e-a378-0139ba4eaec5
📒 Files selected for processing (3)
src/oracle_test/regress/expected/ora_package.outsrc/oracle_test/regress/sql/ora_package.sqlsrc/pl/plisql/src/pl_exec.c
e378236 to
6fb45e7
Compare
Fixes IvorySQL#1382 plisql_param_compile rebinds dno to the resolved datum's own dno, which for a package-qualified reference lives in the package's datum namespace rather than the calling function's. That dno was then compared against expr->target_param (a dno in the calling function's namespace to decide whether to install the plisql_param_eval_var_check fast path. Unlike its siblings plisql_param_eval_var/_ro, that path indexes estate->datums[dno] directly with no pkgoid awareness, so a coincidental numeric match between the two namespaces (common for small packages/blocks, e.g. both being dno 0) made it read and return an unrelated local variable's value instead of the package datum. Symptom: referencing a package CONSTANT/variable more than once while evaluating a simple expression could silently return the wrong value - either empty (uninitialized target) or the stale value of whatever variable happened to share that dno in the calling block. Skip that fast path for package-qualified datums so they fall through to plisql_param_eval_var_ro, which already resolves package datums correctly via get_package_datum_bydno(). Adds a regression case to ora_package.sql reproducing the exact failure pattern. Reported-by: Yasir Hussain Shah <[email protected]>
6fb45e7 to
3363aae
Compare
|
Thanks for your patch! We'll review it soon. |
Nitpicks have been addressed in the latest commit |
bigplaice
left a comment
There was a problem hiding this comment.
This is a nice fix. Suggest to merge it.
Fix package datum misresolution in plisql_param_compile (cherry picked from commit 82a83d2)
Fix package datum misresolution in plisql_param_compile (cherry picked from commit 82a83d2)
Fixes #1382
plisql_param_compile rebinds dno to the resolved datum's own dno, which for a package-qualified reference lives in the package's datum namespace rather than the calling function's. That dno was then compared against expr->target_param (a dno in the calling function's namespace to decide whether to install the plisql_param_eval_var_check fast path. Unlike its siblings plisql_param_eval_var/_ro, that path indexes estate->datums[dno] directly with no pkgoid awareness, so a coincidental numeric match between the two namespaces (common for small packages/blocks, e.g. both being dno 0) made it read and return an unrelated local variable's value instead of the package datum.
Symptom: referencing a package CONSTANT/variable more than once while evaluating a simple expression could silently return the wrong value
Skip that fast path for package-qualified datums so they fall through to plisql_param_eval_var_ro, which already resolves package datums correctly via get_package_datum_bydno(). Adds a regression case to ora_package.sql reproducing the exact failure pattern.
Reported-by: Yasir Hussain Shah [email protected]
Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
Tests