Skip to content

Commit fdda817

Browse files
committed
MDEV-34580: Assertion `(key_part->key_part_flag & 4) == 0' failed key_hashnr
Remove an assert added by fix for MDEV-34417. BNL-H join can be used with prefix keys. This happens when there are real prefix indexes on the equi-join columns (although it probably doesn't make a lot of sense). Anyway, remove the assert. The code receives properly truncated key values for hashing/comparison so it can handle them just fine.
1 parent c038b3c commit fdda817

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

mysql-test/main/join_cache.result

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6420,3 +6420,23 @@ DROP TABLE t1,t2,t3;
64206420
#
64216421
# End of 10.4 tests
64226422
#
6423+
#
6424+
# MDEV-34580: Assertion `(key_part->key_part_flag & 4) == 0' failed key_hashnr
6425+
#
6426+
SET join_cache_level=3;
6427+
CREATE TABLE t1 ( a TIMESTAMP , b varchar(100), c varchar(10) ) ;
6428+
INSERT INTO t1 (b,c) VALUES ('GHOBS','EMLCG'),('t','p');
6429+
CREATE TABLE t2 (a varchar(100), b varchar(100), c varchar(10) , KEY b (b(66))) ;
6430+
insert into t2 select seq, seq, seq from seq_1_to_20;
6431+
explain
6432+
SELECT t1.a FROM t1 JOIN t2 ON t1.b = t2.b ;
6433+
id select_type table type possible_keys key key_len ref rows Extra
6434+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
6435+
1 SIMPLE t2 hash_ALL b #hash#b 69 test.t1.b 20 Using where; Using join buffer (flat, BNLH join)
6436+
SELECT t1.a FROM t1 JOIN t2 ON t1.b = t2.b ;
6437+
a
6438+
set join_cache_level=default;
6439+
DROP TABLE t1, t2;
6440+
#
6441+
# End of 10.5 tests
6442+
#

mysql-test/main/join_cache.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,3 +4300,25 @@ DROP TABLE t1,t2,t3;
43004300
--echo #
43014301
--echo # End of 10.4 tests
43024302
--echo #
4303+
4304+
--echo #
4305+
--echo # MDEV-34580: Assertion `(key_part->key_part_flag & 4) == 0' failed key_hashnr
4306+
--echo #
4307+
--source include/have_sequence.inc
4308+
SET join_cache_level=3;
4309+
4310+
CREATE TABLE t1 ( a TIMESTAMP , b varchar(100), c varchar(10) ) ;
4311+
INSERT INTO t1 (b,c) VALUES ('GHOBS','EMLCG'),('t','p');
4312+
4313+
CREATE TABLE t2 (a varchar(100), b varchar(100), c varchar(10) , KEY b (b(66))) ;
4314+
insert into t2 select seq, seq, seq from seq_1_to_20;
4315+
4316+
explain
4317+
SELECT t1.a FROM t1 JOIN t2 ON t1.b = t2.b ;
4318+
SELECT t1.a FROM t1 JOIN t2 ON t1.b = t2.b ;
4319+
4320+
set join_cache_level=default;
4321+
DROP TABLE t1, t2;
4322+
--echo #
4323+
--echo # End of 10.5 tests
4324+
--echo #

sql/key.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,12 @@ ulong key_hashnr(KEY *key_info, uint used_key_parts, const uchar *key)
755755
if (is_string)
756756
{
757757
/*
758-
Prefix keys are not possible in BNLH joins.
759-
Use the whole string to calculate the hash.
758+
Surprisingly, BNL-H joins may use prefix keys. This may happen
759+
when there is a real index on the column used in equi-join.
760+
761+
In this case, the passed key tuple is already a prefix, no
762+
special handling is required.
760763
*/
761-
DBUG_ASSERT((key_part->key_part_flag & HA_PART_KEY_SEG) == 0);
762764
cs->hash_sort(pos+pack_length, length, &nr, &nr2);
763765
key+= pack_length;
764766
}
@@ -862,10 +864,10 @@ bool key_buf_cmp(KEY *key_info, uint used_key_parts,
862864
if (is_string)
863865
{
864866
/*
865-
Prefix keys are not possible in BNLH joins.
866-
Compare whole strings.
867+
Surprisingly, BNL-H joins may use prefix keys. This may happen
868+
when there is a real index on the column used in equi-join.
869+
In this case, we get properly truncated prefixes here.
867870
*/
868-
DBUG_ASSERT((key_part->key_part_flag & HA_PART_KEY_SEG) == 0);
869871
if (cs->strnncollsp(pos1 + pack_length, length1,
870872
pos2 + pack_length, length2))
871873
return true;

0 commit comments

Comments
 (0)