Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
11.7.2, 12.0
-
None
Description
I run this script:
DELIMITER /
|
CREATE OR REPLACE FUNCTION f1() RETURNS INT |
BEGIN
|
SET @counter= COALESCE(@counter, 0) + 1; |
RETURN @counter; |
END; |
/
|
DELIMITER ;
|
SET @counter=0; |
SELECT f1()=1, @counter FROM seq_1_to_5; |
+--------+----------+
|
| f1()=1 | @counter |
|
+--------+----------+
|
| 1 | 1 |
|
| 0 | 2 |
|
| 0 | 3 |
|
| 0 | 4 |
|
| 0 | 5 |
|
+--------+----------+
|
So far so good: the counter increments by one every row.
Now I change the query to use ROWs:
SELECT ROW(f1(),1) = ROW(1,1), @counter FROM seq_1_to_5; |
+------------------+----------+
|
| (f1(),1) = (1,1) | @counter |
|
+------------------+----------+
|
| 0 | 7 |
|
| 0 | 9 |
|
| 0 | 11 |
|
| 0 | 13 |
|
| 0 | 15 |
|
+------------------+----------+
|
Now the counter increments twice per row. Looks wrong.
Tracing in gdb reveals that Item_func_sp::execute() is indeed called twice per row:
- From Item_func_sp::bring_value()
- From Arg_comparator::compare_int_signed() when Arg_comparator::compare_row() evaluates equality of its members.
Attachments
Issue Links
- is caused by
-
MDEV-12252 ROW data type for stored function return values
-
- Closed
-
Activity
Field | Original Value | New Value |
---|---|---|
Description |
I run this script:
{code:sql} DELIMITER / CREATE OR REPLACE FUNCTION f1() RETURNS INT BEGIN SET @counter= COALESCE(@counter, 0) + 1; RETURN @counter; END; / DELIMITER ; SET @counter=0; SELECT f1()=1, @counter FROM seq_1_to_5; {code} {noformat} +--------+----------+ | f1()=1 | @counter | +--------+----------+ | 1 | 1 | | 0 | 2 | | 0 | 3 | | 0 | 4 | | 0 | 5 | +--------+----------+ {noformat} So far so good: the counter increments by one every row. Now I change the quuer to use ROWs: {code:sql} SELECT ROW(f1(),1) = ROW(1,1), @counter FROM seq_1_to_5; {code} {noformat} +------------------+----------+ | (f1(),1) = (1,1) | @counter | +------------------+----------+ | 0 | 7 | | 0 | 9 | | 0 | 11 | | 0 | 13 | | 0 | 15 | +------------------+----------+ {noformat} Now the counter increments twice per row. Looks wrong. Tracing in gdb reveals that Item_func_sp::execute() is indeed called twice per row: - From Item_func_sp::bring_value() - From Arg_comparator::compare_int_signed() when Arg_comparator::compare_row() evaluates equality of its members. |
I run this script:
{code:sql} DELIMITER / CREATE OR REPLACE FUNCTION f1() RETURNS INT BEGIN SET @counter= COALESCE(@counter, 0) + 1; RETURN @counter; END; / DELIMITER ; SET @counter=0; SELECT f1()=1, @counter FROM seq_1_to_5; {code} {noformat} +--------+----------+ | f1()=1 | @counter | +--------+----------+ | 1 | 1 | | 0 | 2 | | 0 | 3 | | 0 | 4 | | 0 | 5 | +--------+----------+ {noformat} So far so good: the counter increments by one every row. Now I change the query to use ROWs: {code:sql} SELECT ROW(f1(),1) = ROW(1,1), @counter FROM seq_1_to_5; {code} {noformat} +------------------+----------+ | (f1(),1) = (1,1) | @counter | +------------------+----------+ | 0 | 7 | | 0 | 9 | | 0 | 11 | | 0 | 13 | | 0 | 15 | +------------------+----------+ {noformat} Now the counter increments twice per row. Looks wrong. Tracing in gdb reveals that Item_func_sp::execute() is indeed called twice per row: - From Item_func_sp::bring_value() - From Arg_comparator::compare_int_signed() when Arg_comparator::compare_row() evaluates equality of its members. |
Link |
This issue is caused by |
Summary | Comparison of a ROW(stored_func(),1)=ROW(1,1) calls the function twice per row | Comparison ROW(stored_func(),1)=ROW(1,1) calls the function twice per row |
Status | Open [ 1 ] | Confirmed [ 10101 ] |
Assignee | Alexander Barkov [ bar ] |
Assignee | Alexander Barkov [ bar ] | Oleksandr Byelkin [ sanja ] |
Status | Confirmed [ 10101 ] | In Review [ 10002 ] |
Assignee | Oleksandr Byelkin [ sanja ] | Alexander Barkov [ bar ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Fix Version/s | 11.8.2 [ 30001 ] | |
Fix Version/s | 12.0.0 [ 30115 ] | |
Fix Version/s | 11.8 [ 29921 ] |
Resolution | Fixed [ 1 ] | |
Status | Stalled [ 10000 ] | Closed [ 6 ] |