Commit 1387f389 authored by Mattias Jonsson's avatar Mattias Jonsson

Bug#56287: mysql5.1.50 crash when using Partition datetime in sub in query

When having a sub query in partitioned innodb one could
make the partitioning engine to search for a 'index_next_same'
on a partition that had not been initialized.

Problem was that the subselect function looks at table->status
which was not set in the partitioning handler when it skipped
scanning due to no matching partitions found.

Fixed by setting table->status = STATUS_NOT_FOUND when
there was no partitions to scan. (If there are partitions to
scan, it will be set in the partitions handler.)
parent 9bcdbff2
drop table if exists t1, t2; drop table if exists t1, t2;
# #
# Bug#56287: crash when using Partition datetime in sub in query
#
CREATE TABLE t1
(c1 bigint(20) unsigned NOT NULL AUTO_INCREMENT,
c2 varchar(40) not null default '',
c3 datetime not NULL,
PRIMARY KEY (c1,c3),
KEY partidx(c3))
ENGINE=InnoDB
PARTITION BY RANGE (TO_DAYS(c3))
(PARTITION p200912 VALUES LESS THAN (to_days('2010-01-01')),
PARTITION p201103 VALUES LESS THAN (to_days('2011-04-01')),
PARTITION p201912 VALUES LESS THAN MAXVALUE);
insert into t1(c2,c3) values ("Test row",'2010-01-01 00:00:00');
SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'test';
PARTITION_NAME TABLE_ROWS
p200912 0
p201103 1
p201912 0
SELECT count(*) FROM t1 p where c3 in
(select c3 from t1 t where t.c3 < date '2011-04-26 19:19:44'
and t.c3 > date '2011-04-26 19:18:44') ;
count(*)
0
DROP TABLE t1;
#
# Bug#51830: Incorrect partition pruning on range partition (regression) # Bug#51830: Incorrect partition pruning on range partition (regression)
# #
CREATE TABLE t1 (a INT NOT NULL) CREATE TABLE t1 (a INT NOT NULL)
......
...@@ -7,6 +7,30 @@ drop table if exists t1, t2; ...@@ -7,6 +7,30 @@ drop table if exists t1, t2;
let $MYSQLD_DATADIR= `SELECT @@datadir`; let $MYSQLD_DATADIR= `SELECT @@datadir`;
--echo #
--echo # Bug#56287: crash when using Partition datetime in sub in query
--echo #
CREATE TABLE t1
(c1 bigint(20) unsigned NOT NULL AUTO_INCREMENT,
c2 varchar(40) not null default '',
c3 datetime not NULL,
PRIMARY KEY (c1,c3),
KEY partidx(c3))
ENGINE=InnoDB
PARTITION BY RANGE (TO_DAYS(c3))
(PARTITION p200912 VALUES LESS THAN (to_days('2010-01-01')),
PARTITION p201103 VALUES LESS THAN (to_days('2011-04-01')),
PARTITION p201912 VALUES LESS THAN MAXVALUE);
insert into t1(c2,c3) values ("Test row",'2010-01-01 00:00:00');
SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'test';
SELECT count(*) FROM t1 p where c3 in
(select c3 from t1 t where t.c3 < date '2011-04-26 19:19:44'
and t.c3 > date '2011-04-26 19:18:44') ;
DROP TABLE t1;
--echo # --echo #
--echo # Bug#51830: Incorrect partition pruning on range partition (regression) --echo # Bug#51830: Incorrect partition pruning on range partition (regression)
--echo # --echo #
......
...@@ -4483,6 +4483,7 @@ int ha_partition::partition_scan_set_up(uchar * buf, bool idx_read_flag) ...@@ -4483,6 +4483,7 @@ int ha_partition::partition_scan_set_up(uchar * buf, bool idx_read_flag)
key not found. key not found.
*/ */
DBUG_PRINT("info", ("scan with no partition to scan")); DBUG_PRINT("info", ("scan with no partition to scan"));
table->status= STATUS_NOT_FOUND;
DBUG_RETURN(HA_ERR_END_OF_FILE); DBUG_RETURN(HA_ERR_END_OF_FILE);
} }
if (m_part_spec.start_part == m_part_spec.end_part) if (m_part_spec.start_part == m_part_spec.end_part)
...@@ -4507,6 +4508,7 @@ int ha_partition::partition_scan_set_up(uchar * buf, bool idx_read_flag) ...@@ -4507,6 +4508,7 @@ int ha_partition::partition_scan_set_up(uchar * buf, bool idx_read_flag)
if (start_part == MY_BIT_NONE) if (start_part == MY_BIT_NONE)
{ {
DBUG_PRINT("info", ("scan with no partition to scan")); DBUG_PRINT("info", ("scan with no partition to scan"));
table->status= STATUS_NOT_FOUND;
DBUG_RETURN(HA_ERR_END_OF_FILE); DBUG_RETURN(HA_ERR_END_OF_FILE);
} }
if (start_part > m_part_spec.start_part) if (start_part > m_part_spec.start_part)
......
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