Skip to content

Commit 8897b50

Browse files
committed
MDEV-11525 Assertion `cp + len <= buff + buff_size' failed in JOIN_CACHE::write_record_data
Workaround for join_cache + index on vcols + keyread bug. Initialize the record to avoid caching garbage in non-read fields. A proper fix (do not cache non-read fields at all) is done in 10.2 in commits 5d7607f..8d99166
1 parent eef2101 commit 8897b50

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

mysql-test/suite/vcol/r/vcol_select_myisam.result

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,112 @@ Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1`
295295
SELECT * FROM t1 NATURAL JOIN t2;
296296
b a
297297
DROP TABLE t1,t2;
298+
create table t1 (
299+
pk integer auto_increment,
300+
bi integer not null,
301+
vi integer generated always as (bi) persistent,
302+
bc varchar(1) not null,
303+
vc varchar(2) generated always as (concat(bc, bc)) persistent,
304+
primary key (pk),
305+
key (vi, vc));
306+
insert t1 (bi, bc) values (0, 'x'), (0, 'n'), (1, 'w'), (7, 's'), (0, 'a'), (4, 'd'), (1, 'w'), (1, 'j'), (1, 'm'), (4, 'k'), (7, 't'), (4, 'k'), (2, 'e'), (0, 'i'), (1, 't'), (6, 'z'), (3, 'c'), (6, 'i'), (8, 'v');
307+
create table t2 (
308+
pk integer auto_increment,
309+
bi integer not null,
310+
vi integer generated always as (bi) persistent,
311+
bc varchar(257) not null,
312+
vc varchar(2) generated always as (concat(bc, bc)) persistent,
313+
primary key (pk),
314+
key (vi, vc));
315+
insert t2 (bi, bc) values (1, 'c'), (8, 'm'), (9, 'd'), (6, 'y'), (1, 't'), (6, 'd'), (2, 's'), (4, 'r'), (8, 'm'), (4, 'b'), (4, 'x'), (7, 'g'), (4, 'p'), (1, 'q'), (9, 'w'), (4, 'd'), (8, 'e'), (4, 'b'), (8, 'y');
316+
explain # should be using join buffer
317+
select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc));
318+
id select_type table type possible_keys key key_len ref rows Extra
319+
1 SIMPLE t2 index NULL vi 10 NULL 19 Using index
320+
1 SIMPLE t1 ALL NULL NULL NULL NULL 19 Using where; Using join buffer (flat, BNL join)
321+
1 SIMPLE t3 index NULL PRIMARY 4 NULL 19 Using where; Using index; Using join buffer (incremental, BNL join)
322+
select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc));
323+
vi
324+
1
325+
1
326+
1
327+
1
328+
1
329+
1
330+
1
331+
1
332+
1
333+
1
334+
1
335+
1
336+
1
337+
1
338+
1
339+
1
340+
1
341+
1
342+
1
343+
1
344+
1
345+
1
346+
1
347+
1
348+
1
349+
1
350+
1
351+
1
352+
1
353+
1
354+
1
355+
1
356+
1
357+
2
358+
4
359+
4
360+
4
361+
4
362+
4
363+
4
364+
4
365+
4
366+
4
367+
4
368+
4
369+
4
370+
4
371+
4
372+
4
373+
4
374+
4
375+
4
376+
4
377+
4
378+
4
379+
4
380+
4
381+
4
382+
4
383+
4
384+
4
385+
4
386+
4
387+
4
388+
4
389+
4
390+
4
391+
4
392+
4
393+
4
394+
6
395+
6
396+
6
397+
6
398+
7
399+
7
400+
8
401+
8
402+
8
403+
8
404+
9
405+
9
406+
drop table t2,t1;

mysql-test/suite/vcol/t/vcol_select_myisam.test

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,35 @@ SELECT * FROM t1 NATURAL JOIN t2;
6868
SELECT * FROM t1 NATURAL JOIN t2;
6969

7070
DROP TABLE t1,t2;
71+
72+
#
73+
# MDEV-11525 Assertion `cp + len <= buff + buff_size' failed in JOIN_CACHE::write_record_data
74+
#
75+
76+
create table t1 (
77+
pk integer auto_increment,
78+
bi integer not null,
79+
vi integer generated always as (bi) persistent,
80+
bc varchar(1) not null,
81+
vc varchar(2) generated always as (concat(bc, bc)) persistent,
82+
primary key (pk),
83+
key (vi, vc));
84+
insert t1 (bi, bc) values (0, 'x'), (0, 'n'), (1, 'w'), (7, 's'), (0, 'a'), (4, 'd'), (1, 'w'), (1, 'j'), (1, 'm'), (4, 'k'), (7, 't'), (4, 'k'), (2, 'e'), (0, 'i'), (1, 't'), (6, 'z'), (3, 'c'), (6, 'i'), (8, 'v');
85+
create table t2 (
86+
pk integer auto_increment,
87+
bi integer not null,
88+
vi integer generated always as (bi) persistent,
89+
bc varchar(257) not null,
90+
vc varchar(2) generated always as (concat(bc, bc)) persistent,
91+
primary key (pk),
92+
key (vi, vc));
93+
insert t2 (bi, bc) values (1, 'c'), (8, 'm'), (9, 'd'), (6, 'y'), (1, 't'), (6, 'd'), (2, 's'), (4, 'r'), (8, 'm'), (4, 'b'), (4, 'x'), (7, 'g'), (4, 'p'), (1, 'q'), (9, 'w'), (4, 'd'), (8, 'e'), (4, 'b'), (8, 'y');
94+
explain # should be using join buffer
95+
select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc));
96+
--sorted_result
97+
select t2.vi from (t2 as t3 right join (t2 left join t1 on (t1.bi = t2.vi)) on (t1.vc = t2.vc));
98+
drop table t2,t1;
99+
100+
#
101+
# End of 5.5 tests
102+
#

sql/sql_join_cache.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ void JOIN_CACHE::create_remaining_fields()
589589
{
590590
MY_BITMAP *rem_field_set;
591591
TABLE *table= tab->table;
592+
#if MYSQL_VERSION_ID < 100204
593+
empty_record(table);
594+
#else
595+
#error remove
596+
#endif
592597

593598
if (all_read_fields)
594599
rem_field_set= table->read_set;

0 commit comments

Comments
 (0)