summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <gkodinov@dl145s.mysql.com>2006-09-18 11:19:40 +0200
committerunknown <gkodinov@dl145s.mysql.com>2006-09-18 11:19:40 +0200
commit7a0f9c8d4c02826d7fec0d3027dcac7bd1be7bc7 (patch)
tree9c065798a81a2c49828707063b47782fdb4ca457
parentc97cc113921a74ed2e2450045e57b5ddfb969351 (diff)
parent96dbaffda6c606e1769b7feeedf91d9839e820b8 (diff)
downloadmariadb-git-7a0f9c8d4c02826d7fec0d3027dcac7bd1be7bc7.tar.gz
Merge dl145s.mysql.com:/data/bk/team_tree_merge/MERGE/mysql-4.1-opt
into dl145s.mysql.com:/data/bk/team_tree_merge/MERGE/mysql-5.0-opt mysql-test/r/subselect.result: SCCS merged mysql-test/t/subselect.test: SCCS merged
-rw-r--r--mysql-test/r/subselect.result29
-rw-r--r--mysql-test/t/subselect.test26
-rw-r--r--sql/opt_range.cc13
-rw-r--r--sql/opt_range.h2
4 files changed, 69 insertions, 1 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 2e3ca9b71f0..3fdf0a6d8ff 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -2937,6 +2937,35 @@ retailerID statusID changed
0048 1 2006-01-06 12:37:50
0059 1 2006-01-06 12:37:50
drop table t1;
+create table t1(a int, primary key (a));
+insert into t1 values (10);
+create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
+insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
+explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
+ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
+ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
+1 PRIMARY r const PRIMARY PRIMARY 4 const 1
+2 DEPENDENT SUBQUERY t2 range b b 38 NULL 2 Using where
+SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
+ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
+ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
+a a b
+10 3 35989
+explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
+ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
+ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
+1 PRIMARY r const PRIMARY PRIMARY 4 const 1
+2 DEPENDENT SUBQUERY t2 range b b 38 NULL 2 Using where
+SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
+ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
+ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
+a a b
+10 1 359
+drop table t1,t2;
create table t1 (df decimal(5,1));
insert into t1 values(1.1);
insert into t1 values(2.2);
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 740cb08c5bd..a4e535ac418 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -1892,6 +1892,32 @@ select * from t1 r1
group by r2.retailerId);
drop table t1;
+#
+# Bug #21180: Subselect with index for both WHERE and ORDER BY
+# produces empty result
+#
+create table t1(a int, primary key (a));
+insert into t1 values (10);
+
+create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
+insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
+
+explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
+ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
+ ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
+SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
+ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
+ ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
+
+explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
+ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
+ ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
+SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
+ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
+ ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
+
+drop table t1,t2;
+
# End of 4.1 tests
#
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 6189d0412b3..1ed74c6de2e 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -6724,6 +6724,14 @@ int QUICK_RANGE_SELECT::get_next()
}
}
+void QUICK_SELECT::reset(void)
+{
+ next= 0;
+ it.rewind();
+ range= 0;
+ if (file->inited == handler::NONE)
+ file->ha_index_init(index);
+}
/*
Get the next record with a different prefix.
@@ -9378,6 +9386,11 @@ static void print_ror_scans_arr(TABLE *table, const char *msg,
DBUG_VOID_RETURN;
}
+void QUICK_SELECT_DESC::reset(void)
+{
+ rev_it.rewind();
+ QUICK_SELECT::reset();
+}
/*****************************************************************************
** Print a quick range for debugging
diff --git a/sql/opt_range.h b/sql/opt_range.h
index 9474f2d469f..c1f1b63d468 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -668,7 +668,7 @@ private:
#ifdef NOT_USED
bool test_if_null_range(QUICK_RANGE *range, uint used_key_parts);
#endif
- int reset(void) { rev_it.rewind(); return QUICK_RANGE_SELECT::reset(); }
+ void reset(void);
List<QUICK_RANGE> rev_ranges;
List_iterator<QUICK_RANGE> rev_it;
};