Commit 2b173bf8 authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #878769.

The method DsMrr_impl::dsmrr_init erroneously tried to get a KEY descriptor
for key with number MAX_KEY. This caused valgrind complains.
parent fdf789a7
drop table if exists t1,t2;
#
# Bug #878769: valgrind complains when using join cache
# to join an InnoDB table without primary key
#
CREATE TABLE t1 (
col_int_key int(11), col_time_key time, col_varchar_key varchar(1),
KEY (col_int_key), KEY (col_varchar_key,col_int_key)
) ENGINE=InnoDB;
INSERT IGNORE INTO t1 VALUES
(7,'10:19:31','d'),(1,'14:40:36','r'),(7,'04:37:47','f'),(9,'19:34:06','y'),
(2,'00:00:00','m'),(4,'00:13:25','q'),(0,'03:47:16',NULL),(4,'01:41:48','d'),
(8,'00:00:00','g'),(NULL,'22:32:04','x'),(NULL,'16:44:14','f'),
(0,'17:38:37','p'),(NULL,'08:46:48','j'),(8,'14:11:27','c');
CREATE TABLE t2 (
col_int_nokey int(11), col_int_key int(11),
col_datetime_key datetime, col_datetime_nokey datetime,
col_varchar_key varchar(1), col_varchar_nokey varchar(1),
KEY (col_int_key), KEY (col_varchar_key,col_int_key)
);
INSERT IGNORE INTO t2 VALUES
(150,62,'2008-01-03 10:33:32','2008-01-03 10:33:32','v','v'),
(2,1,'2007-10-09 19:53:04','2007-10-09 19:53:04',NULL,NULL),
(5,0,'2001-11-08 21:02:12','2001-11-08 21:02:12','x','x'),
(3,7,'2003-04-01 00:00','2003-04-01 00:00','i','i'),
(1,7,'1900-01-01 00:00','1900-01-01 00:00:00','e','e'),
(NULL,7,'2005-04-04 01:21','2005-04-04 01:21','s','s'),
(2,1,'1900-01-01 00:00','1900-01-01 00:00','j','j'),
(8,0,'2004-04-28 21:44','2004-04-28 21:44','a','a'),
(6,8,'2001-04-18 00:00','2001-04-18 00:00:00','y','y'),
(8,1,'2008-12-18 19:39:55','2008-12-18 19:39:55',NULL,NULL),
(3,1,'2000-08-01 12:19:39','2000-08-01 12:19:39','r','r'),
(3,9,'2004-09-25 21:29:06','2004-09-25 21:29:06','v','v');
set session optimizer_switch='mrr=on,mrr_sort_keys=on';
set session join_cache_level=6;
EXPLAIN
SELECT t1.col_time_key, t1.col_varchar_key
FROM t2 STRAIGHT_JOIN t1 ON t1.col_int_key = t2.col_int_key
GROUP BY 1,2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index col_int_key col_int_key 5 NULL 12 Using where; Using index; Using temporary; Using filesort
1 SIMPLE t1 ref col_int_key col_int_key 5 test.t2.col_int_key 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
SELECT t1.col_time_key, t1.col_varchar_key
FROM t2 STRAIGHT_JOIN t1 ON t1.col_int_key = t2.col_int_key
GROUP BY 1,2;
col_time_key col_varchar_key
00:00:00 g
03:47:16 NULL
04:37:47 f
10:19:31 d
14:11:27 c
14:40:36 r
17:38:37 p
19:34:06 y
set session optimizer_switch=default;
set session join_cache_level=default;
DROP TABLE t1,t2;
--source include/have_innodb.inc
--disable_warnings
drop table if exists t1,t2;
--enable_warnings
--echo #
--echo # Bug #878769: valgrind complains when using join cache
--echo # to join an InnoDB table without primary key
--echo #
CREATE TABLE t1 (
col_int_key int(11), col_time_key time, col_varchar_key varchar(1),
KEY (col_int_key), KEY (col_varchar_key,col_int_key)
) ENGINE=InnoDB;
INSERT IGNORE INTO t1 VALUES
(7,'10:19:31','d'),(1,'14:40:36','r'),(7,'04:37:47','f'),(9,'19:34:06','y'),
(2,'00:00:00','m'),(4,'00:13:25','q'),(0,'03:47:16',NULL),(4,'01:41:48','d'),
(8,'00:00:00','g'),(NULL,'22:32:04','x'),(NULL,'16:44:14','f'),
(0,'17:38:37','p'),(NULL,'08:46:48','j'),(8,'14:11:27','c');
CREATE TABLE t2 (
col_int_nokey int(11), col_int_key int(11),
col_datetime_key datetime, col_datetime_nokey datetime,
col_varchar_key varchar(1), col_varchar_nokey varchar(1),
KEY (col_int_key), KEY (col_varchar_key,col_int_key)
);
INSERT IGNORE INTO t2 VALUES
(150,62,'2008-01-03 10:33:32','2008-01-03 10:33:32','v','v'),
(2,1,'2007-10-09 19:53:04','2007-10-09 19:53:04',NULL,NULL),
(5,0,'2001-11-08 21:02:12','2001-11-08 21:02:12','x','x'),
(3,7,'2003-04-01 00:00','2003-04-01 00:00','i','i'),
(1,7,'1900-01-01 00:00','1900-01-01 00:00:00','e','e'),
(NULL,7,'2005-04-04 01:21','2005-04-04 01:21','s','s'),
(2,1,'1900-01-01 00:00','1900-01-01 00:00','j','j'),
(8,0,'2004-04-28 21:44','2004-04-28 21:44','a','a'),
(6,8,'2001-04-18 00:00','2001-04-18 00:00:00','y','y'),
(8,1,'2008-12-18 19:39:55','2008-12-18 19:39:55',NULL,NULL),
(3,1,'2000-08-01 12:19:39','2000-08-01 12:19:39','r','r'),
(3,9,'2004-09-25 21:29:06','2004-09-25 21:29:06','v','v');
set session optimizer_switch='mrr=on,mrr_sort_keys=on';
set session join_cache_level=6;
EXPLAIN
SELECT t1.col_time_key, t1.col_varchar_key
FROM t2 STRAIGHT_JOIN t1 ON t1.col_int_key = t2.col_int_key
GROUP BY 1,2;
SELECT t1.col_time_key, t1.col_varchar_key
FROM t2 STRAIGHT_JOIN t1 ON t1.col_int_key = t2.col_int_key
GROUP BY 1,2;
set session optimizer_switch=default;
set session join_cache_level=default;
DROP TABLE t1,t2;
......@@ -848,7 +848,8 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs,
if (h_idx->primary_key_is_clustered())
{
uint pk= h_idx->get_table()->s->primary_key;
saved_pk_length= h_idx->get_table()->key_info[pk].key_length;
if (pk != MAX_KEY)
saved_pk_length= h_idx->get_table()->key_info[pk].key_length;
}
KEY *used_index= &h_idx->get_table()->key_info[h_idx->active_index];
......
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