[MDEV-7600] Wrong result (missing rows) on 2nd execution of PS with ANY ( SQ ) Created: 2015-02-17  Updated: 2022-11-24  Resolved: 2022-11-24

Status: Closed
Project: MariaDB Server
Component/s: Optimizer, Prepared Statements
Affects Version/s: 5.5, 10.1, 10.2, 10.3, 10.4, 10.5
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Dmitry Shulga
Resolution: Cannot Reproduce Votes: 0
Labels: verified


 Description   

The problem appeared on 5.5 tree quite some time ago, with the following revision:

revno: 3843
revision-id: psergey@askmonty.org-20130731132452-4qb11t56i2jw16aa
parent: psergey@askmonty.org-20130731093701-10tmxhe668f3u1lx
committer: Sergey Petrunya <psergey@askmonty.org>
branch nick: 5.5
timestamp: Wed 2013-07-31 17:24:52 +0400
message:
  MDEV-4817: Optimizer fails to optimize expression of the form 'FOO' IS NULL
  - Modify the way Item_cond::fix_fields() and Item_cond::eval_not_null_tables() 
    calculate bitmap for Item_cond_or::not_null_tables():
    if they see a "... OR inexpensive_const_false_item OR ..." then the item can
    be ignored.
  - Updated test results. There can be more warnings produced since parts of WHERE 
    are evaluated more times.

Test case

CREATE TABLE t1 (a INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
 
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1),(2);
 
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
INSERT INTO t3 VALUES (2),(5);
 
prepare stmt from "SELECT * FROM t1 INNER JOIN t2 ON (b = a) WHERE 3 > ANY ( SELECT c FROM t3 )";
execute stmt;
execute stmt;
 
drop table t1, t2, t3;

Results

MariaDB [test]> execute stmt;
+------+------+
| a    | b    |
+------+------+
|    1 |    1 |
|    2 |    2 |
+------+------+
2 rows in set (0.05 sec)
 
MariaDB [test]> execute stmt;
Empty set (0.00 sec)

5.5 commit fdd6c111c254c5044cd9b6c2f7e4d0c74f427a79, also reproducible on 10.0 and 10.1 trees.



 Comments   
Comment by Elena Stepanova [ 2020-01-20 ]

Still reproducible on all of 5.5-10.5.

Comment by Elena Stepanova [ 2021-01-06 ]

Still reproducible, and still presents an obstacle for correctness testing.

Comment by Alice Sherepa [ 2022-11-24 ]

Correct results on the current 10.3-10.10 (10.3 f4a1298f245f678badc8a5b5)

Generated at Thu Feb 08 07:20:51 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.