[MDEV-28257] Wrong results in derived_view.test for reexuction of statement Created: 2022-04-07  Updated: 2023-11-28

Status: Stalled
Project: MariaDB Server
Component/s: Prepared Statements
Affects Version/s: 10.7.3, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 10.5, 10.6

Type: Bug Priority: Critical
Reporter: Michael Widenius Assignee: Dmitry Shulga
Resolution: Unresolved Votes: 0
Labels: not-10.4


 Description   

This bug was introduced into 10.7, where I noticed the problem, in the merge commit f5c5f8e41ecd4d407022d3772ac43075c16824a5 (merge 10.5 -> 10.6)
The problem may also be in earlier versions

The test case of LP BUG#968720 shows wrong results.
(Two lines of '1' are missing in the last select result).

Here is an independent test case that shows the issue:
(This does not have to be added in the fix as the derived_view.test will show if this is fixed)

CREATE TABLE t1 (a int, INDEX(a));
INSERT INTO t1 VALUES (1);

CREATE TABLE t2 (a int, INDEX(a));
INSERT INTO t2 VALUES (1), (2);

explain INSERT INTO t1 SELECT a FROM (SELECT a FROM test.t1) AS s1 NATURAL JOIN t2 AS s2;

PREPARE stmt FROM "
INSERT INTO t1 SELECT a FROM (SELECT a FROM test.t1) AS s1 NATURAL JOIN t2 AS s2;
";
EXECUTE stmt;
EXECUTE stmt;
SELECT * FROM t1;

truncate table t1;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 SELECT a FROM (SELECT a FROM test.t1) AS s1 NATURAL JOIN t2 AS s2;
INSERT INTO t1 SELECT a FROM (SELECT a FROM test.t1) AS s1 NATURAL JOIN t2 AS s2;
SELECT * FROM t1;

The last select has 4 result lines (correct) while the previous select has only 2 result lines.

Note that in 10.7-selectivity, which is updated to latest 10.7 doesn't have this problem.
(Don't know why, but it may be that some of the many bug fixes in it solved the issue or it is just using another execution plan that doesn't have this issue)



 Comments   
Comment by Oleksandr Byelkin [ 2022-04-21 ]

On second execution the derived is not filled on optimize (and so do not filled at all)

      if (join->table_count == join->const_tables)
        derived->fill_me= TRUE;

Comment by Oleksandr Byelkin [ 2022-04-21 ]

On second execution for t1 table->file->stats.records is 2 (should be 1)

Comment by Oleksandr Byelkin [ 2022-04-21 ]

actually it should be 2, i.e. the problem is that prepared for static table statement can not be executed for table which become non-constant

Comment by Oleksandr Byelkin [ 2022-04-22 ]

10.4 has at first glance all the same but it build new temporary table during JOIN::optimize_statge2().

Generated at Thu Feb 08 09:59:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.