summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varunraiko1803@gmail.com>2017-11-30 11:56:02 +0200
committerVarun Gupta <varunraiko1803@gmail.com>2017-11-30 11:56:02 +0200
commitb8d1398b1d061566ada0714fb2407cdd45ff42b2 (patch)
tree44138f54e7bd45680918dff097b196620a694316
parent9b53e541f03d74e2777e0d1e7618b6246b81c721 (diff)
downloadmariadb-git-b8d1398b1d061566ada0714fb2407cdd45ff42b2.tar.gz
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
-rw-r--r--mysql-test/r/join_outer.result13
-rw-r--r--mysql-test/r/join_outer_jcl6.result13
-rw-r--r--mysql-test/t/join_outer.test14
-rw-r--r--sql/table.cc8
4 files changed, 48 insertions, 0 deletions
diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result
index 5611b61a7b0..74580e67499 100644
--- a/mysql-test/r/join_outer.result
+++ b/mysql-test/r/join_outer.result
@@ -2339,5 +2339,18 @@ Warnings:
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)
DROP FUNCTION f1;
DROP TABLE t1,t2;
+#
+# MDEV-10397: Server crashes in key_copy with join_cache_level > 2 and join on BIT fields
+#
+CREATE TABLE t1 (b1 BIT NOT NULL);
+INSERT INTO t1 VALUES (0),(1);
+CREATE TABLE t2 (b2 BIT NOT NULL);
+INSERT INTO t2 VALUES (0),(1);
+SET SESSION JOIN_CACHE_LEVEL = 3;
+SELECT t1.b1+'0' , t2.b2 + '0' FROM t1 LEFT JOIN t2 ON b1 = b2;
+t1.b1+'0' t2.b2 + '0'
+0 0
+1 1
+DROP TABLE t1, t2;
# end of 5.5 tests
SET optimizer_switch=@save_optimizer_switch;
diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result
index 8a1ccc7d5e5..d46a4ee6c7a 100644
--- a/mysql-test/r/join_outer_jcl6.result
+++ b/mysql-test/r/join_outer_jcl6.result
@@ -2350,6 +2350,19 @@ Warnings:
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)
DROP FUNCTION f1;
DROP TABLE t1,t2;
+#
+# MDEV-10397: Server crashes in key_copy with join_cache_level > 2 and join on BIT fields
+#
+CREATE TABLE t1 (b1 BIT NOT NULL);
+INSERT INTO t1 VALUES (0),(1);
+CREATE TABLE t2 (b2 BIT NOT NULL);
+INSERT INTO t2 VALUES (0),(1);
+SET SESSION JOIN_CACHE_LEVEL = 3;
+SELECT t1.b1+'0' , t2.b2 + '0' FROM t1 LEFT JOIN t2 ON b1 = b2;
+t1.b1+'0' t2.b2 + '0'
+0 0
+1 1
+DROP TABLE t1, t2;
# end of 5.5 tests
SET optimizer_switch=@save_optimizer_switch;
set join_cache_level=default;
diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test
index 9645d8ad82a..896cc137e07 100644
--- a/mysql-test/t/join_outer.test
+++ b/mysql-test/t/join_outer.test
@@ -1881,6 +1881,20 @@ DROP FUNCTION f1;
DROP TABLE t1,t2;
+--echo #
+--echo # MDEV-10397: Server crashes in key_copy with join_cache_level > 2 and join on BIT fields
+--echo #
+
+CREATE TABLE t1 (b1 BIT NOT NULL);
+INSERT INTO t1 VALUES (0),(1);
+
+CREATE TABLE t2 (b2 BIT NOT NULL);
+INSERT INTO t2 VALUES (0),(1);
+
+SET SESSION JOIN_CACHE_LEVEL = 3;
+SELECT t1.b1+'0' , t2.b2 + '0' FROM t1 LEFT JOIN t2 ON b1 = b2;
+DROP TABLE t1, t2;
+
--echo # end of 5.5 tests
SET optimizer_switch=@save_optimizer_switch;
diff --git a/sql/table.cc b/sql/table.cc
index 9d52d5f87a2..fbcd91f5326 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -5987,6 +5987,14 @@ void TABLE::create_key_part_by_field(KEY_PART_INFO *key_part_info,
might be reused.
*/
key_part_info->store_length= key_part_info->length;
+ /*
+ For BIT fields null_bit is not set to 0 even if the field is defined
+ as NOT NULL, look at Field_bit::Field_bit
+ */
+ if (!field->real_maybe_null())
+ {
+ key_part_info->null_bit= 0;
+ }
/*
The total store length of the key part is the raw length of the field +