Skip to content

Commit b8d1398

Browse files
committed
MDEV-10397: Server crashes in key_copy with join_cache_level > 2 and join on BIT fields
For BIT field null_bit is not set to 0 even for a field defined as NOT NULL. So now in the function TABLE::create_key_part_by_field, if the bit field is not nullable then the null_bit is explicitly set to 0
1 parent 9b53e54 commit b8d1398

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

mysql-test/r/join_outer.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,5 +2339,18 @@ Warnings:
23392339
Note 1003 select `test`.`t1`.`col1` AS `col1`,`test`.`t2`.`col1` AS `col1`,`test`.`t2`.`col3` AS `col3` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`col2` = `test`.`t1`.`col1`)) where (`f1`(`test`.`t2`.`col3`,0) = 0)
23402340
DROP FUNCTION f1;
23412341
DROP TABLE t1,t2;
2342+
#
2343+
# MDEV-10397: Server crashes in key_copy with join_cache_level > 2 and join on BIT fields
2344+
#
2345+
CREATE TABLE t1 (b1 BIT NOT NULL);
2346+
INSERT INTO t1 VALUES (0),(1);
2347+
CREATE TABLE t2 (b2 BIT NOT NULL);
2348+
INSERT INTO t2 VALUES (0),(1);
2349+
SET SESSION JOIN_CACHE_LEVEL = 3;
2350+
SELECT t1.b1+'0' , t2.b2 + '0' FROM t1 LEFT JOIN t2 ON b1 = b2;
2351+
t1.b1+'0' t2.b2 + '0'
2352+
0 0
2353+
1 1
2354+
DROP TABLE t1, t2;
23422355
# end of 5.5 tests
23432356
SET optimizer_switch=@save_optimizer_switch;

mysql-test/r/join_outer_jcl6.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,19 @@ Warnings:
23502350
Note 1003 select `test`.`t1`.`col1` AS `col1`,`test`.`t2`.`col1` AS `col1`,`test`.`t2`.`col3` AS `col3` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`col2` = `test`.`t1`.`col1`)) where (`f1`(`test`.`t2`.`col3`,0) = 0)
23512351
DROP FUNCTION f1;
23522352
DROP TABLE t1,t2;
2353+
#
2354+
# MDEV-10397: Server crashes in key_copy with join_cache_level > 2 and join on BIT fields
2355+
#
2356+
CREATE TABLE t1 (b1 BIT NOT NULL);
2357+
INSERT INTO t1 VALUES (0),(1);
2358+
CREATE TABLE t2 (b2 BIT NOT NULL);
2359+
INSERT INTO t2 VALUES (0),(1);
2360+
SET SESSION JOIN_CACHE_LEVEL = 3;
2361+
SELECT t1.b1+'0' , t2.b2 + '0' FROM t1 LEFT JOIN t2 ON b1 = b2;
2362+
t1.b1+'0' t2.b2 + '0'
2363+
0 0
2364+
1 1
2365+
DROP TABLE t1, t2;
23532366
# end of 5.5 tests
23542367
SET optimizer_switch=@save_optimizer_switch;
23552368
set join_cache_level=default;

mysql-test/t/join_outer.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,20 @@ DROP FUNCTION f1;
18811881

18821882
DROP TABLE t1,t2;
18831883

1884+
--echo #
1885+
--echo # MDEV-10397: Server crashes in key_copy with join_cache_level > 2 and join on BIT fields
1886+
--echo #
1887+
1888+
CREATE TABLE t1 (b1 BIT NOT NULL);
1889+
INSERT INTO t1 VALUES (0),(1);
1890+
1891+
CREATE TABLE t2 (b2 BIT NOT NULL);
1892+
INSERT INTO t2 VALUES (0),(1);
1893+
1894+
SET SESSION JOIN_CACHE_LEVEL = 3;
1895+
SELECT t1.b1+'0' , t2.b2 + '0' FROM t1 LEFT JOIN t2 ON b1 = b2;
1896+
DROP TABLE t1, t2;
1897+
18841898
--echo # end of 5.5 tests
18851899

18861900
SET optimizer_switch=@save_optimizer_switch;

sql/table.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5987,6 +5987,14 @@ void TABLE::create_key_part_by_field(KEY_PART_INFO *key_part_info,
59875987
might be reused.
59885988
*/
59895989
key_part_info->store_length= key_part_info->length;
5990+
/*
5991+
For BIT fields null_bit is not set to 0 even if the field is defined
5992+
as NOT NULL, look at Field_bit::Field_bit
5993+
*/
5994+
if (!field->real_maybe_null())
5995+
{
5996+
key_part_info->null_bit= 0;
5997+
}
59905998

59915999
/*
59926000
The total store length of the key part is the raw length of the field +

0 commit comments

Comments
 (0)