[Commits] Rev 2895: Fixed LP bug #707848. in file:///home/igor/maria/maria-5.3-bug707848/

Igor Babaev igor at askmonty.org
Thu Jan 27 06:45:24 EET 2011


At file:///home/igor/maria/maria-5.3-bug707848/

------------------------------------------------------------
revno: 2895
revision-id: igor at askmonty.org-20110127044523-9kvx1t3x3166hjyr
parent: igor at askmonty.org-20110126193029-gpklw3fl904r0b65
committer: Igor Babaev <igor at askmonty.org>
branch nick: maria-5.3-bug707848
timestamp: Wed 2011-01-26 20:45:23 -0800
message:
  Fixed LP bug #707848.
  This was another bug in the patch for bug 698882. The new
  code from this patch did not ensured that substitutions
  of fields for best equal fields were performed on all
  AND-OR levels. As a result substitutions for best fields
  in some predicates that had been used by the range optimizer
  were not actually performed while range plans could employ
  these substitutions. This could lead to inconsistent data
  structures and ultimately to a crash.
-------------- next part --------------
=== modified file 'mysql-test/r/order_by.result'
--- a/mysql-test/r/order_by.result	2010-12-27 22:22:05 +0000
+++ b/mysql-test/r/order_by.result	2011-01-27 04:45:23 +0000
@@ -1643,4 +1643,34 @@
 1	SIMPLE	t1	index	NULL	a	8	NULL	10	Using index; Using temporary; Using filesort
 1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	4	test.t1.b	1	Using where
 DROP TABLE t1, t2;
+#
+# Bug #707848: WHERE condition with OR + ORDER BY + field substitution  
+#
+CREATE TABLE t1 (a int PRIMARY KEY);
+INSERT INTO t1 VALUES
+(9), (7), (11), (15), (2), (4), (1), (5), (14), (54), (3), (8);
+EXPLAIN EXTENDED
+SELECT * FROM t1 r JOIN t1 s ON r.a = s.a 
+WHERE s.a IN (2,9) OR s.a < 100  AND s.a != 0
+ORDER BY 1 LIMIT 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	r	index	PRIMARY	PRIMARY	4	NULL	10	120.00	Using where; Using index
+1	SIMPLE	s	eq_ref	PRIMARY	PRIMARY	4	test.r.a	1	100.00	Using index
+Warnings:
+Note	1003	select `test`.`r`.`a` AS `a`,`test`.`s`.`a` AS `a` from `test`.`t1` `r` join `test`.`t1` `s` where ((`test`.`s`.`a` = `test`.`r`.`a`) and ((`test`.`r`.`a` in (2,9)) or ((`test`.`r`.`a` < 100) and (`test`.`r`.`a` <> 0)))) order by 1 limit 10
+SELECT * FROM t1 r JOIN t1 s ON r.a = s.a 
+WHERE s.a IN (2,9) OR s.a < 100 AND s.a != 0
+ORDER BY 1 LIMIT 10;
+a	a
+1	1
+2	2
+3	3
+4	4
+5	5
+7	7
+8	8
+9	9
+11	11
+14	14
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/t/order_by.test'
--- a/mysql-test/t/order_by.test	2010-12-27 22:22:05 +0000
+++ b/mysql-test/t/order_by.test	2011-01-27 04:45:23 +0000
@@ -1497,5 +1497,23 @@
 
 DROP TABLE t1, t2;
 
+--echo #
+--echo # Bug #707848: WHERE condition with OR + ORDER BY + field substitution  
+--echo #
+
+CREATE TABLE t1 (a int PRIMARY KEY);
+INSERT INTO t1 VALUES
+  (9), (7), (11), (15), (2), (4), (1), (5), (14), (54), (3), (8);
+
+EXPLAIN EXTENDED
+SELECT * FROM t1 r JOIN t1 s ON r.a = s.a 
+  WHERE s.a IN (2,9) OR s.a < 100  AND s.a != 0
+    ORDER BY 1 LIMIT 10;
+
+SELECT * FROM t1 r JOIN t1 s ON r.a = s.a 
+  WHERE s.a IN (2,9) OR s.a < 100 AND s.a != 0
+    ORDER BY 1 LIMIT 10;
+
+DROP TABLE t1;
 
 --echo End of 5.1 tests

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-01-26 19:30:29 +0000
+++ b/sql/sql_select.cc	2011-01-27 04:45:23 +0000
@@ -9902,12 +9902,16 @@
     cond= eliminate_item_equal(0, cond_equal, item_equal);
     return cond ? cond : org_cond;
   }
-  else if (cond_equal)
+  else 
   {
-    List_iterator_fast<Item_equal> it(cond_equal->current_level);
-    while((item_equal= it++))
+    while (cond_equal)
     {
-      cond= cond->transform(&Item::replace_equal_field, (uchar *) item_equal);
+      List_iterator_fast<Item_equal> it(cond_equal->current_level);
+      while((item_equal= it++))
+      {
+        cond= cond->transform(&Item::replace_equal_field, (uchar *) item_equal);
+      }
+      cond_equal= cond_equal->upper_levels;
     }
   }
   return cond;



More information about the commits mailing list