-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-38329: Named Parameters in Invocation of Stored Routines #4681
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
Draft
rajatmohan22
wants to merge
13
commits into
MariaDB:main
Choose a base branch
from
rajatmohan22:named-params-feature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0566aa9
add lexer support
rajatmohan22 4db43d6
Reset call_param_list in LEX::start() to fix test failures
rajatmohan22 d6f16e2
accept named params (ident => expr), execution via value_list
rajatmohan22 4b2d1e7
add a script to run MSAN build and failing CI tests on Linux
rajatmohan22 247c072
Merge branch 'main' into named-params-feature
rajatmohan22 d8c4a35
Merge branch 'main' into named-params-feature
rajatmohan22 06b57c0
MDEV-38329: address review,
rajatmohan22 184dda5
using list_iterator
rajatmohan22 346bd6e
resolving named CALL parameters to formal-parameter positions
rajatmohan22 bf8a042
out/inout tests
rajatmohan22 1532142
avoid reading past args in execute_procedure
rajatmohan22 c180cc6
call_named_param: out/inout tests, add run_call_tests.sh
rajatmohan22 1e6fb58
default values for omitted params and fix rcontext_create default-par…
rajatmohan22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # MDEV-38329 CALL with named parameters. | ||
| # Create procedure with 2 params | ||
| CREATE PROCEDURE p1(a INT, b INT) SELECT a, b; | ||
| # Positional call | ||
| CALL p1(1, 2); | ||
| a b | ||
| 1 2 | ||
| # Named call - same order as declaration | ||
| CALL p1(a => 10, b => 20); | ||
| a b | ||
| 10 20 | ||
| # Named call - reversed order (tests resolution) | ||
| CALL p1(b => 200, a => 100); | ||
| a b | ||
| 100 200 | ||
| # Mixed: positional first, then named | ||
| CALL p1(100, b => 200); | ||
| a b | ||
| 100 200 | ||
| # User variables as named parameters | ||
| SET @v1= 5, @v2= 10; | ||
| CALL p1(a => @v1, b => @v2); | ||
| a b | ||
| 5 10 | ||
| # Expressions as named parameters | ||
| CALL p1(a => 1+1, b => 3*4); | ||
| a b | ||
| 2 12 | ||
| # Error: unknown parameter names | ||
| CALL p1(x => 0, y => 3); | ||
| ERROR 42000: Undeclared variable: x | ||
| # 3-param procedure | ||
| CREATE PROCEDURE p2(x INT, y INT, z INT) SELECT x, y, z; | ||
| # Named call all 3 | ||
| CALL p2(x => 1, y => 2, z => 3); | ||
| x y z | ||
| 1 2 3 | ||
| # Named out-of-order | ||
| CALL p2(z => 30, x => 10, y => 20); | ||
| x y z | ||
| 10 20 30 | ||
| # Mixed: 1 positional + 2 named | ||
| CALL p2(1, z => 30, y => 20); | ||
| x y z | ||
| 1 20 30 | ||
| DROP PROCEDURE p1; | ||
| DROP PROCEDURE p2; | ||
| # Error: unknown parameter name | ||
| CREATE PROCEDURE p3(a INT) SELECT a; | ||
| CALL p3(x => 1); | ||
| ERROR 42000: Undeclared variable: x | ||
| # Error: duplicate parameter | ||
| CALL p3(a => 1, a => 2); | ||
| ERROR 42000: Duplicate parameter: a | ||
| DROP PROCEDURE p3; | ||
| # OUT parameters: named call out-of-order, writeback to correct variables | ||
| CREATE PROCEDURE p_out(OUT a INT, OUT b INT) | ||
| BEGIN | ||
| SELECT 10, 20 INTO a, b; | ||
| END| | ||
| CALL p_out(b => @bout, a => @aout); | ||
| SELECT @aout, @bout; | ||
| @aout @bout | ||
| 10 20 | ||
| DROP PROCEDURE p_out; | ||
| # INOUT parameters with named call | ||
| CREATE PROCEDURE p_inout(INOUT x INT, INOUT y INT) | ||
| BEGIN | ||
| SET x= x * 10, y= y + 100; | ||
| END| | ||
| SET @xin= 1, @yin= 2; | ||
| CALL p_inout(y => @yin, x => @xin); | ||
| SELECT @xin, @yin; | ||
| @xin @yin | ||
| 10 102 | ||
| DROP PROCEDURE p_inout; | ||
| # Default parameters: omitted params get default value | ||
| CREATE PROCEDURE p_def(a INT, b INT DEFAULT 10) SELECT a, b; | ||
| # Positional: one arg, second gets default | ||
| CALL p_def(1); | ||
| a b | ||
| 1 10 | ||
| # Positional: two args | ||
| CALL p_def(1, 2); | ||
| a b | ||
| 1 2 | ||
| # Named: omit b, b gets default (2e) | ||
| CALL p_def(a => 5); | ||
| a b | ||
| 5 10 | ||
| # Named: both given | ||
| CALL p_def(a => 1, b => 20); | ||
| a b | ||
| 1 20 | ||
| # Named: reversed order, give both | ||
| CALL p_def(b => 100, a => 7); | ||
| a b | ||
| 7 100 | ||
| DROP PROCEDURE p_def; | ||
| # Error: required param omitted (no default) | ||
| CREATE PROCEDURE p_req(a INT, b INT) SELECT a, b; | ||
| CALL p_req(a => 1); | ||
| ERROR 42000: Incorrect number of arguments for PROCEDURE test.p_req; expected 2, got 1 | ||
| DROP PROCEDURE p_req; | ||
| # End of 13.0 tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # MDEV-38329 CALL with named parameters. | ||
|
|
||
| --echo # MDEV-38329 CALL with named parameters. | ||
| --echo # Create procedure with 2 params | ||
| CREATE PROCEDURE p1(a INT, b INT) SELECT a, b; | ||
|
|
||
| --echo # Positional call | ||
| CALL p1(1, 2); | ||
|
|
||
| --echo # Named call - same order as declaration | ||
| CALL p1(a => 10, b => 20); | ||
rajatmohan22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| --echo # Named call - reversed order (tests resolution) | ||
| CALL p1(b => 200, a => 100); | ||
|
|
||
| --echo # Mixed: positional first, then named | ||
| CALL p1(100, b => 200); | ||
rajatmohan22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| --echo # User variables as named parameters | ||
| SET @v1= 5, @v2= 10; | ||
| CALL p1(a => @v1, b => @v2); | ||
|
|
||
| --echo # Expressions as named parameters | ||
| CALL p1(a => 1+1, b => 3*4); | ||
|
|
||
| --echo # Error: unknown parameter names | ||
| --error ER_SP_UNDECLARED_VAR | ||
| CALL p1(x => 0, y => 3); | ||
|
|
||
| --echo # 3-param procedure | ||
| CREATE PROCEDURE p2(x INT, y INT, z INT) SELECT x, y, z; | ||
|
|
||
| --echo # Named call all 3 | ||
| CALL p2(x => 1, y => 2, z => 3); | ||
|
|
||
| --echo # Named out-of-order | ||
| CALL p2(z => 30, x => 10, y => 20); | ||
|
|
||
| --echo # Mixed: 1 positional + 2 named | ||
| CALL p2(1, z => 30, y => 20); | ||
|
|
||
| DROP PROCEDURE p1; | ||
| DROP PROCEDURE p2; | ||
|
|
||
| --echo # Error: unknown parameter name | ||
| CREATE PROCEDURE p3(a INT) SELECT a; | ||
|
|
||
| --error ER_SP_UNDECLARED_VAR | ||
| CALL p3(x => 1); | ||
|
|
||
| --echo # Error: duplicate parameter | ||
| --error ER_SP_DUP_PARAM | ||
| CALL p3(a => 1, a => 2); | ||
|
|
||
| DROP PROCEDURE p3; | ||
|
|
||
| --echo # OUT parameters: named call out-of-order, writeback to correct variables | ||
| delimiter |; | ||
| CREATE PROCEDURE p_out(OUT a INT, OUT b INT) | ||
| BEGIN | ||
| SELECT 10, 20 INTO a, b; | ||
| END| | ||
| delimiter ;| | ||
| CALL p_out(b => @bout, a => @aout); | ||
| SELECT @aout, @bout; | ||
| DROP PROCEDURE p_out; | ||
|
|
||
| --echo # INOUT parameters with named call | ||
| delimiter |; | ||
| CREATE PROCEDURE p_inout(INOUT x INT, INOUT y INT) | ||
| BEGIN | ||
| SET x= x * 10, y= y + 100; | ||
| END| | ||
| delimiter ;| | ||
| SET @xin= 1, @yin= 2; | ||
| CALL p_inout(y => @yin, x => @xin); | ||
| SELECT @xin, @yin; | ||
| DROP PROCEDURE p_inout; | ||
|
|
||
| --echo # Default parameters: omitted params get default value | ||
| CREATE PROCEDURE p_def(a INT, b INT DEFAULT 10) SELECT a, b; | ||
|
|
||
| --echo # Positional: one arg, second gets default | ||
| CALL p_def(1); | ||
| --echo # Positional: two args | ||
| CALL p_def(1, 2); | ||
| --echo # Named: omit b, b gets default (2e) | ||
| CALL p_def(a => 5); | ||
| --echo # Named: both given | ||
| CALL p_def(a => 1, b => 20); | ||
| --echo # Named: reversed order, give both | ||
| CALL p_def(b => 100, a => 7); | ||
| DROP PROCEDURE p_def; | ||
|
|
||
| --echo # Error: required param omitted (no default) | ||
| CREATE PROCEDURE p_req(a INT, b INT) SELECT a, b; | ||
| --error ER_SP_WRONG_NO_OF_ARGS | ||
| CALL p_req(a => 1); | ||
| DROP PROCEDURE p_req; | ||
|
|
||
| --echo # End of 13.0 tests | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/bin/sh | ||
| # Run tests relevant to CALL / named params. Run from repo root. | ||
| # Usage: ./mysql-test/run_call_tests.sh [--quick|--main|--main-ps|--push] | ||
|
|
||
| set -e | ||
| ROOT="$(cd "$(dirname "$0")/.." && pwd)" | ||
| MTR="$ROOT/build/mysql-test/mtr" | ||
|
|
||
| if [ ! -x "$MTR" ]; then | ||
| echo "Build or MTR not found. Run: cd build && ninja" | ||
| exit 1 | ||
| fi | ||
|
|
||
| cd "$ROOT/build/mysql-test" | ||
|
|
||
| case "${1:-}" in | ||
| --quick) | ||
| echo "=== Quick: call_named_param (default + ps-protocol) ===" | ||
| ./mtr --force call_named_param | ||
| ./mtr --force --ps-protocol call_named_param | ||
| ;; | ||
| --main) | ||
| echo "=== Main suite ===" | ||
| ./mtr --force --suite-timeout=120 --max-test-fail=10 --retry=3 --suite=main | ||
| ;; | ||
| --main-ps) | ||
| echo "=== Main suite with --ps-protocol ===" | ||
| ./mtr --force --ps-protocol --suite-timeout=120 --max-test-fail=10 --retry=3 --suite=main | ||
| ;; | ||
| --push) | ||
| echo "=== default.push: n_mix ===" | ||
| ./mtr --timer --force --parallel=auto --comment=n_mix --vardir=var-n_mix --mysqld=--binlog-format=mixed --skip-test-list=collections/disabled-per-push.list | ||
| echo "=== default.push: ps_row ===" | ||
| ./mtr --timer --force --parallel=auto --comment=ps_row --vardir=var-ps_row --ps-protocol --mysqld=--binlog-format=row --skip-test-list=collections/disabled-per-push.list | ||
| ;; | ||
| *) | ||
| echo "Usage: $0 --quick | --main | --main-ps | --push" | ||
| echo " --quick call_named_param only (default + ps-protocol)" | ||
| echo " --main full main suite" | ||
| echo " --main-ps main suite with prepared statements" | ||
| echo " --push first two default.push runs (n_mix, ps_row)" | ||
| exit 1 | ||
| ;; | ||
| esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.