Commit 1c0bd60d authored by unknown's avatar unknown

Bug#34358: Cannot find specified bit row in partitioned table

Problem was incorrect data length in the key_restore function
resulting in overwriting the search key.

Solution, remove one byte in length if uneven bits are used.


mysql-test/r/partition_datatype.result:
  Bug#34358: Cannot find specified bit row
  
  Updated result file
mysql-test/t/partition_datatype.test:
  Bug#34358: Cannot find specified bit row
  
  Updated test file
  (corrected a few errors and added a test case for the bug)
sql/key.cc:
  Bug34358: error in key_restore for bit fields with uneven bits
  
  When uneven bits exist, it has special treatment for the uneven bits
  but does use the same byte again when copying the rest of
  the key_part.
parent 629b355b
......@@ -30,22 +30,22 @@ a
2
drop table t1;
create table t1 (a float not null) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
insert into t1 values (0.5);
select * from t1 where a = 0.5;
a
0.5
drop table t1;
create table t1 (a double not null) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
insert into t1 values (0.5);
select * from t1 where a = 0.5;
a
2.1
0.5
drop table t1;
create table t1 (a decimal not null) partition by key (a);
create table t1 (a decimal(4,2) not null) partition by key (a);
insert into t1 values (2.1);
Warnings:
Note 1265 Data truncated for column 'a' at row 1
select * from t1 where a = 2.1;
a
2.10
drop table t1;
create table t1 (a date not null) partition by key (a);
insert into t1 values ('2001-01-01');
......@@ -156,22 +156,22 @@ a
2
drop table t1;
create table t1 (a float) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
insert into t1 values (0.5);
select * from t1 where a = 0.5;
a
0.5
drop table t1;
create table t1 (a double) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
insert into t1 values (0.5);
select * from t1 where a = 0.5;
a
2.1
0.5
drop table t1;
create table t1 (a decimal) partition by key (a);
create table t1 (a decimal(4,2)) partition by key (a);
insert into t1 values (2.1);
Warnings:
Note 1265 Data truncated for column 'a' at row 1
select * from t1 where a = 2.1;
a
2.10
drop table t1;
create table t1 (a date) partition by key (a);
insert into t1 values ('2001-01-01');
......@@ -254,25 +254,41 @@ drop table t1;
create table t1 (a varchar(65531)) partition by key (a);
insert into t1 values ('bbbb');
insert into t1 values ('aaaa');
select * from t1 where a = 'aaa%';
select * from t1 where a = 'aaaa';
a
aaaa
select * from t1 where a like 'aaa%';
a
aaaa
select * from t1 where a = 'bbbb';
a
bbbb
drop table t1;
create table t1 (a varchar(65532)) partition by key (a);
insert into t1 values ('bbbb');
insert into t1 values ('aaaa');
select * from t1 where a = 'aaa%';
select * from t1 where a = 'aaaa';
a
aaaa
select * from t1 where a like 'aaa%';
a
aaaa
select * from t1 where a = 'bbbb';
a
bbbb
drop table t1;
create table t1 (a varchar(65533) not null) partition by key (a);
insert into t1 values ('bbbb');
insert into t1 values ('aaaa');
select * from t1 where a = 'aaa%';
select * from t1 where a = 'aaaa';
a
aaaa
select * from t1 where a like 'aaa%';
a
aaaa
select * from t1 where a = 'bbbb';
a
bbbb
drop table t1;
create table t1 (a varchar(65533)) partition by key (a);
ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs
......@@ -280,3 +296,17 @@ create table t1 (a varchar(65534) not null) partition by key (a);
ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs
create table t1 (a varchar(65535)) partition by key (a);
ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs
create table t1 (a bit(27), primary key (a)) engine=myisam
partition by hash (a)
(partition p0, partition p1, partition p2);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bit(27) NOT NULL DEFAULT '\0\0\0\0',
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (a) (PARTITION p0 ENGINE = MyISAM, PARTITION p1 ENGINE = MyISAM, PARTITION p2 ENGINE = MyISAM) */
insert into t1 values (1),(4),(7),(10),(13),(16),(19),(22),(25),(28),(31),(34);
select hex(a) from t1 where a = 7;
hex(a)
7
drop table t1;
......@@ -37,14 +37,14 @@ insert into t1 values (2);
select * from t1 where a = 2;
drop table t1;
create table t1 (a float not null) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
insert into t1 values (0.5);
select * from t1 where a = 0.5;
drop table t1;
create table t1 (a double not null) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
insert into t1 values (0.5);
select * from t1 where a = 0.5;
drop table t1;
create table t1 (a decimal not null) partition by key (a);
create table t1 (a decimal(4,2) not null) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
drop table t1;
......@@ -126,14 +126,14 @@ insert into t1 values (2);
select * from t1 where a = 2;
drop table t1;
create table t1 (a float) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
insert into t1 values (0.5);
select * from t1 where a = 0.5;
drop table t1;
create table t1 (a double) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
insert into t1 values (0.5);
select * from t1 where a = 0.5;
drop table t1;
create table t1 (a decimal) partition by key (a);
create table t1 (a decimal(4,2)) partition by key (a);
insert into t1 values (2.1);
select * from t1 where a = 2.1;
drop table t1;
......@@ -192,18 +192,23 @@ drop table t1;
create table t1 (a varchar(65531)) partition by key (a);
insert into t1 values ('bbbb');
insert into t1 values ('aaaa');
select * from t1 where a = 'aaa%';
select * from t1 where a = 'aaaa';
select * from t1 where a like 'aaa%';
select * from t1 where a = 'bbbb';
drop table t1;
create table t1 (a varchar(65532)) partition by key (a);
insert into t1 values ('bbbb');
insert into t1 values ('aaaa');
select * from t1 where a = 'aaa%';
select * from t1 where a = 'aaaa';
select * from t1 where a like 'aaa%';
select * from t1 where a = 'bbbb';
drop table t1;
create table t1 (a varchar(65533) not null) partition by key (a);
insert into t1 values ('bbbb');
insert into t1 values ('aaaa');
select * from t1 where a = 'aaa%';
select * from t1 where a = 'aaaa';
select * from t1 where a like 'aaa%';
select * from t1 where a = 'bbbb';
drop table t1;
-- error ER_TOO_BIG_ROWSIZE
create table t1 (a varchar(65533)) partition by key (a);
......@@ -211,3 +216,14 @@ create table t1 (a varchar(65533)) partition by key (a);
create table t1 (a varchar(65534) not null) partition by key (a);
-- error ER_TOO_BIG_ROWSIZE
create table t1 (a varchar(65535)) partition by key (a);
#
# Bug#34358: error in key_restore for bitfields with uneven bits
#
create table t1 (a bit(27), primary key (a)) engine=myisam
partition by hash (a)
(partition p0, partition p1, partition p2);
show create table t1;
insert into t1 values (1),(4),(7),(10),(13),(16),(19),(22),(25),(28),(31),(34);
select hex(a) from t1 where a = 7;
drop table t1;
......@@ -168,6 +168,7 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
}
for (key_part= key_info->key_part ; (int) key_length > 0 ; key_part++)
{
uchar used_uneven_bits= 0;
if (key_part->null_bit)
{
if (*from_key++)
......@@ -186,6 +187,8 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
set_rec_bits(bits, to_record + key_part->null_offset +
(key_part->null_bit == 128),
field->bit_ofs, field->bit_len);
/* we have now used the byte with 'uneven' bits */
used_uneven_bits= 1;
}
}
if (key_part->key_part_flag & HA_BLOB_PART)
......@@ -222,7 +225,9 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
else
{
length= min(key_length, key_part->length);
memcpy(to_record + key_part->offset, from_key, (size_t) length);
/* skip the byte with 'uneven' bits, if used */
memcpy(to_record + key_part->offset, from_key + used_uneven_bits
, (size_t) length - used_uneven_bits);
}
from_key+= length;
key_length-= length;
......
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