mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Patch for Bug#13805127: Stored program cache produces wrong result in same THD.
Background:
- as described in MySQL Internals Prepared Stored
(http://forge.mysql.com/wiki/MySQL_Internals_Prepared_Stored),
the Optimizer sometimes does destructive changes to the parsed
LEX-object (Item-tree), which makes it impossible to re-use
that tree for PS/SP re-execution.
- in order to be able to re-use the Item-tree, the destructive
changes are remembered and rolled back after the statement execution.
The problem, discovered by this bug, was that the objects representing
GROUP-BY clause did not restored after query execution. So, the GROUP-BY
part of the statement could not be properly re-initialized for re-execution
after destructive changes.
Those objects do not take part in the Item-tree, so they can not be saved
using the approach for Item-tree.
The fix is as follows:
- introduce a new array in st_select_lex to store the original
ORDER pointers, representing the GROUP-BY clause;
- Initialize this array in fix_prepare_information().
- restore the list of GROUP-BY items in reinit_stmt_before_use().
This commit is contained in:
@@ -3746,5 +3746,108 @@ FROM (SELECT 1 UNION SELECT 2) t;
|
||||
1
|
||||
1
|
||||
2
|
||||
|
||||
# Bug#13805127: Stored program cache produces wrong result in same THD
|
||||
|
||||
PREPARE s1 FROM
|
||||
"
|
||||
SELECT c1, t2.c2, count(c3)
|
||||
FROM
|
||||
(
|
||||
SELECT 3 as c2 FROM dual WHERE @x = 1
|
||||
UNION
|
||||
SELECT 2 FROM dual WHERE @x = 1 OR @x = 2
|
||||
) AS t1,
|
||||
(
|
||||
SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 02:00:00', 3, 2 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 01:00:00', 2, 1 FROM dual
|
||||
) AS t2
|
||||
WHERE t2.c2 = t1.c2
|
||||
GROUP BY c1, c2
|
||||
";
|
||||
|
||||
SET @x = 1;
|
||||
SELECT c1, t2.c2, count(c3)
|
||||
FROM
|
||||
(
|
||||
SELECT 3 as c2 FROM dual WHERE @x = 1
|
||||
UNION
|
||||
SELECT 2 FROM dual WHERE @x = 1 OR @x = 2
|
||||
) AS t1,
|
||||
(
|
||||
SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 02:00:00', 3, 2 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 01:00:00', 2, 1 FROM dual
|
||||
) AS t2
|
||||
WHERE t2.c2 = t1.c2
|
||||
GROUP BY c1, c2;
|
||||
c1 c2 count(c3)
|
||||
2012-03-01 01:00:00 2 1
|
||||
2012-03-01 01:00:00 3 1
|
||||
2012-03-01 02:00:00 3 1
|
||||
|
||||
EXECUTE s1;
|
||||
c1 c2 count(c3)
|
||||
2012-03-01 01:00:00 2 1
|
||||
2012-03-01 01:00:00 3 1
|
||||
2012-03-01 02:00:00 3 1
|
||||
|
||||
SET @x = 2;
|
||||
SELECT c1, t2.c2, count(c3)
|
||||
FROM
|
||||
(
|
||||
SELECT 3 as c2 FROM dual WHERE @x = 1
|
||||
UNION
|
||||
SELECT 2 FROM dual WHERE @x = 1 OR @x = 2
|
||||
) AS t1,
|
||||
(
|
||||
SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 02:00:00', 3, 2 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 01:00:00', 2, 1 FROM dual
|
||||
) AS t2
|
||||
WHERE t2.c2 = t1.c2
|
||||
GROUP BY c1, c2;
|
||||
c1 c2 count(c3)
|
||||
2012-03-01 01:00:00 2 1
|
||||
|
||||
EXECUTE s1;
|
||||
c1 c2 count(c3)
|
||||
2012-03-01 01:00:00 2 1
|
||||
|
||||
SET @x = 1;
|
||||
SELECT c1, t2.c2, count(c3)
|
||||
FROM
|
||||
(
|
||||
SELECT 3 as c2 FROM dual WHERE @x = 1
|
||||
UNION
|
||||
SELECT 2 FROM dual WHERE @x = 1 OR @x = 2
|
||||
) AS t1,
|
||||
(
|
||||
SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 02:00:00', 3, 2 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 01:00:00', 2, 1 FROM dual
|
||||
) AS t2
|
||||
WHERE t2.c2 = t1.c2
|
||||
GROUP BY c1, c2;
|
||||
c1 c2 count(c3)
|
||||
2012-03-01 01:00:00 2 1
|
||||
2012-03-01 01:00:00 3 1
|
||||
2012-03-01 02:00:00 3 1
|
||||
|
||||
EXECUTE s1;
|
||||
c1 c2 count(c3)
|
||||
2012-03-01 01:00:00 2 1
|
||||
2012-03-01 01:00:00 3 1
|
||||
2012-03-01 02:00:00 3 1
|
||||
DEALLOCATE PREPARE s1;
|
||||
#
|
||||
# End of 5.5 tests.
|
||||
|
||||
@@ -7747,6 +7747,44 @@ CALL p2();
|
||||
DROP PROCEDURE p1;
|
||||
DROP PROCEDURE p2;
|
||||
DROP TABLE t1;
|
||||
|
||||
# Bug#13805127: Stored program cache produces wrong result in same THD
|
||||
|
||||
CREATE PROCEDURE p1(x INT UNSIGNED)
|
||||
BEGIN
|
||||
SELECT c1, t2.c2, count(c3)
|
||||
FROM
|
||||
(
|
||||
SELECT 3 as c2 FROM dual WHERE x = 1
|
||||
UNION
|
||||
SELECT 2 FROM dual WHERE x = 1 OR x = 2
|
||||
) AS t1,
|
||||
(
|
||||
SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 02:00:00', 3, 2 FROM dual
|
||||
UNION
|
||||
SELECT '2012-03-01 01:00:00', 2, 1 FROM dual
|
||||
) AS t2
|
||||
WHERE t2.c2 = t1.c2
|
||||
GROUP BY c1, c2
|
||||
;
|
||||
END|
|
||||
|
||||
CALL p1(1);
|
||||
c1 c2 count(c3)
|
||||
2012-03-01 01:00:00 2 1
|
||||
2012-03-01 01:00:00 3 1
|
||||
2012-03-01 02:00:00 3 1
|
||||
CALL p1(2);
|
||||
c1 c2 count(c3)
|
||||
2012-03-01 01:00:00 2 1
|
||||
CALL p1(1);
|
||||
c1 c2 count(c3)
|
||||
2012-03-01 01:00:00 2 1
|
||||
2012-03-01 01:00:00 3 1
|
||||
2012-03-01 02:00:00 3 1
|
||||
DROP PROCEDURE p1;
|
||||
# End of 5.5 test
|
||||
#
|
||||
# Bug#12663165 SP DEAD CODE REMOVAL DOESN'T UNDERSTAND CONTINUE HANDLERS
|
||||
|
||||
Reference in New Issue
Block a user