[MDEV-4836] Wrong result on <not null date column> IS NULL (old documented hack stopped working) Created: 2013-08-02 Updated: 2013-09-03 Resolved: 2013-09-03 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 5.5.33 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | optimizer | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
Due to the fix for Here is the story: http://bugs.mysql.com/bug.php?id=940
Here is how it looks:
But it doesn't work any longer for scenarios affected by
|
| Comments |
| Comment by Elena Stepanova [ 2013-08-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
5.5.32 is not affected, the regression was introduced later (I mistakenly put 5.5.32 as a fix version earlier, thanks for correcting it). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As Igor has pointed out: It seems, the server has this implicit convention: do not evaluate parts of WHERE/ON condition before optimize_cond() has been run on it. I'm wondering whether that also applies to HAVING, select list, and other parts where one could have conditions. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The IS NULL -> 0000-00-00 conversion is done for WHERE clause, but not for select_list: MariaDB [j3]> SELECT *, d IS NULL FROM t1 WHERE d IS NULL;
-----
----- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Committed a patch | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2013-08-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The following test case still fails on /~maria-captains/maria/5.5-test1/ revno 3862: CREATE TABLE t1 (i1 INT, d1 DATE NOT NULL); CREATE TABLE t2 (i2 INT, j2 INT); SELECT * FROM t1 LEFT JOIN t2 ON i1 = j2 WHERE d1 IS NULL AND 1 OR i1 = i2; It produces an empty result, while there should be a row | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I think I have figured out why the last testcase doesn't work. In the patch, I wrote: if (item->const_item()) In the testcase we see that "item" is "d1 IS NULL AND 1". That is, cond_is_datetime_is_null(item) returns FALSE, and the item is evaluated and removed. We should not evaluate items that contain not_null_datecol IS NULL, at all. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
> We should not evaluate items that contain not_null_datecol IS NULL, at all. This is not 100% correct. datecol IS NULL substitution only works for items that are in the WHERE clause, and are directly reachable from root condition by descending the AND/OR tree. Here's how it works: explain extended Now, let's wrap d1 IS NULL into a function: explain extended We don't see IF (...) in the WHERE because d1 IS NULL was not substituted. Then. optimize_cond removed it as a constant part of WHERE. Let's try the same on a nullable INT column: explain extended Here, IF(...) was not removed. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Committed a fix for this, pushed into bzr+ssh://bazaar.launchpad.net/~maria-captains/maria/5.5-test1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2013-08-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The following test case returns 2 rows on the work tree, revno 3863, while 5.3, 5.5.32, 5.6.13 all return empty result set, which I think is a correct result. When the view is not used, the work tree also returns an empty result set. CREATE TABLE t1 (i1 INT) ENGINE=MyISAM; CREATE TABLE t2 (i2 INT, a INT, b INT) ENGINE=MyISAM; INSERT INTO t2 VALUES (NULL,1,2),(NULL,2,3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The EXPLAINs are: MariaDB [j11]> explain extended SELECT * FROM t1 LEFT JOIN t2 ON i1 = i2 WHERE a < b;
-----
----- MariaDB [j12]> explain extended SELECT * FROM t1 LEFT JOIN v2 ON i1 = i2 WHERE a < b;
-----
----- EXPLAIN EXTENDED line is the same with/without the VIEW. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Debugging, I find the difference to be in the first (gdb) p dbug_print_item(select_cond) (gdb) p dbug_print_item(select_cond) When the VIEW is used, "t2.i2 = NULL" is not present. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I am looking at the trees from: psergey@askmonty.org-20130826173804-fl2mdyqvottvjvr7 (rev 3863, latest and observe the result difference with inner join:
-----
----- old: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branching off this problem to | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-08-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem in |