Commit 7a0f9c8d authored by unknown's avatar unknown

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
parents c97cc113 96dbaffd
...@@ -2937,6 +2937,35 @@ retailerID statusID changed ...@@ -2937,6 +2937,35 @@ retailerID statusID changed
0048 1 2006-01-06 12:37:50 0048 1 2006-01-06 12:37:50
0059 1 2006-01-06 12:37:50 0059 1 2006-01-06 12:37:50
drop table t1; 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)); create table t1 (df decimal(5,1));
insert into t1 values(1.1); insert into t1 values(1.1);
insert into t1 values(2.2); insert into t1 values(2.2);
......
...@@ -1892,6 +1892,32 @@ select * from t1 r1 ...@@ -1892,6 +1892,32 @@ select * from t1 r1
group by r2.retailerId); group by r2.retailerId);
drop table t1; 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 # End of 4.1 tests
# #
......
...@@ -6724,6 +6724,14 @@ int QUICK_RANGE_SELECT::get_next() ...@@ -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. Get the next record with a different prefix.
...@@ -9378,6 +9386,11 @@ static void print_ror_scans_arr(TABLE *table, const char *msg, ...@@ -9378,6 +9386,11 @@ static void print_ror_scans_arr(TABLE *table, const char *msg,
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
void QUICK_SELECT_DESC::reset(void)
{
rev_it.rewind();
QUICK_SELECT::reset();
}
/***************************************************************************** /*****************************************************************************
** Print a quick range for debugging ** Print a quick range for debugging
......
...@@ -668,7 +668,7 @@ class QUICK_SELECT_DESC: public QUICK_RANGE_SELECT ...@@ -668,7 +668,7 @@ class QUICK_SELECT_DESC: public QUICK_RANGE_SELECT
#ifdef NOT_USED #ifdef NOT_USED
bool test_if_null_range(QUICK_RANGE *range, uint used_key_parts); bool test_if_null_range(QUICK_RANGE *range, uint used_key_parts);
#endif #endif
int reset(void) { rev_it.rewind(); return QUICK_RANGE_SELECT::reset(); } void reset(void);
List<QUICK_RANGE> rev_ranges; List<QUICK_RANGE> rev_ranges;
List_iterator<QUICK_RANGE> rev_it; List_iterator<QUICK_RANGE> rev_it;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment