From c563ea0717f3de43b7331dd4368e9f9cf4559be0 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 16 Feb 2012 16:06:49 -0800 Subject: [PATCH] Fixed LP bug #933117. The bug was fixed with the code back-ported from the patch for LP bug 800184 pushed into mariadb-5.3. --- mysql-test/r/range.result | 15 +++++++++++++++ mysql-test/t/range.test | 14 ++++++++++++++ sql/opt_range.cc | 9 +++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result index ae63edf87b9..13ae77c13e3 100644 --- a/mysql-test/r/range.result +++ b/mysql-test/r/range.result @@ -1768,3 +1768,18 @@ SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk; pk i4 pk i4 DROP TABLE t1; End of 5.1 tests +# +# LP Bug #533117: Wrong use_count in SEL_ARG trees +# (Bug #58731) +# +create table t1 (a int, b int, c int, key idx (a,b,c)); +insert into t1 values (0,0,0), (2,2,0), (1,1,1), (2,2,1); +explain +select * from t1 force index (idx) where a >=1 and c <= 1 and a=b and b > 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range idx idx 5 NULL 3 Using where; Using index +select * from t1 force index (idx) where a >=1 and c <= 1 and a=b and b > 1; +a b c +2 2 0 +2 2 1 +drop table t1; diff --git a/mysql-test/t/range.test b/mysql-test/t/range.test index 6c9320b708a..a5ab6905b74 100644 --- a/mysql-test/t/range.test +++ b/mysql-test/t/range.test @@ -1393,3 +1393,17 @@ SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk; DROP TABLE t1; --echo End of 5.1 tests + +--echo # +--echo # LP Bug #533117: Wrong use_count in SEL_ARG trees +--echo # (Bug #58731) +--echo # + +create table t1 (a int, b int, c int, key idx (a,b,c)); +insert into t1 values (0,0,0), (2,2,0), (1,1,1), (2,2,1); + +explain +select * from t1 force index (idx) where a >=1 and c <= 1 and a=b and b > 1; +select * from t1 force index (idx) where a >=1 and c <= 1 and a=b and b > 1; + +drop table t1; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index bc434e2edc1..185f3eecd3c 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -498,6 +498,11 @@ public: pos->increment_use_count(count); } } + void incr_refs() + { + increment_use_count(1); + use_count++; + } void free_tree() { for (SEL_ARG *pos=first(); pos ; pos=pos->next) @@ -6475,8 +6480,8 @@ key_and(RANGE_OPT_PARAM *param, SEL_ARG *key1, SEL_ARG *key2, uint clone_flag) continue; SEL_ARG *next=key_and(param, e1->next_key_part, e2->next_key_part, clone_flag); - e1->increment_use_count(1); - e2->increment_use_count(1); + e1->incr_refs(); + e2->incr_refs(); if (!next || next->type != SEL_ARG::IMPOSSIBLE) { SEL_ARG *new_arg= e1->clone_and(e2);