[Commits] Rev 3582: Fixed LP bug #1058071 (mdev-564). in file:///home/igor/maria/maria-5.3-bug1058071/

Igor Babaev igor at askmonty.org
Sun Sep 30 08:44:14 EEST 2012


At file:///home/igor/maria/maria-5.3-bug1058071/

------------------------------------------------------------
revno: 3582
revision-id: igor at askmonty.org-20120930054413-dctiy92utxev623y
parent: knielsen at knielsen-hq.org-20120928075443-8bygto4wb3pj0nvs
committer: Igor Babaev <igor at askmonty.org>
branch nick: maria-5.3-bug1058071
timestamp: Sat 2012-09-29 22:44:13 -0700
message:
  Fixed LP bug #1058071 (mdev-564).
  In some rare cases when the value of the system variable join_buffer_size
  was set to a number less than 256 the function JOIN_CACHE::set_constants 
  determined the size of an offset in the join buffer equal to 1 though
  the minimal join buffer required more than 256 bytes. This could cause
  a crash of the server when records from the join buffer were read.  
-------------- next part --------------
=== modified file 'mysql-test/r/join_cache.result'
--- a/mysql-test/r/join_cache.result	2012-04-02 17:41:54 +0000
+++ b/mysql-test/r/join_cache.result	2012-09-30 05:44:13 +0000
@@ -5586,4 +5586,54 @@
 set join_cache_level=default;
 set optimizer_switch=@tmp_optimizer_switch;
 DROP TABLE t1,t2,t3;
+#
+# Bug #1058071: LEFT JOIN using blobs 
+# (mdev-564)    when join buffer size is small 
+#
+CREATE TABLE t1 (
+col269 decimal(31,10) unsigned DEFAULT NULL,
+col280 multipoint DEFAULT NULL,
+col281 tinyint(1) DEFAULT NULL,
+col282 time NOT NULL,
+col284 datetime DEFAULT NULL,
+col286 date DEFAULT NULL,
+col287 datetime DEFAULT NULL,
+col288 decimal(30,29) DEFAULT NULL,
+col291 time DEFAULT NULL,
+col292 time DEFAULT NULL
+) ENGINE=Aria;
+INSERT INTO t1 VALUES
+(0.0,PointFromText('POINT(9 0)'),0,'11:24:05','2013-04-14 21:30:28',NULL,'2011-12-20 06:00:34',9.9,'13:04:39',NULL),
+(0.0,NULL,127,'05:43:12','2012-09-05 06:15:27','2027-01-01','2011-10-29 10:48:29',0.0,'06:24:05','11:33:37'),
+(0.0,NULL,127,'12:54:41','2013-01-12 11:32:58','2011-11-03','2013-01-03 02:00:34',00,'11:54:15','20:19:15'),
+(0.0,PointFromText('POINT(9 0)'),0,'19:48:07','2012-07-16 15:45:25','2012-03-25','2013-09-07 17:21:52',0.5,'17:36:54','21:24:19'),
+(0.0,PointFromText('POINT(9 0)'),0,'03:43:48','2012-09-28 00:00:00','2012-06-26','2011-11-16 05:01:09',00,'01:25:42','19:30:06'),
+(0.0,LineStringFromText('LINESTRING(0 0,9 9,0 0,9 0,0 0)'),127,'11:33:21','2012-03-31 10:29:22','2012-10-10','2012-04-21 19:21:06',NULL,'05:13:22','09:48:34'),
+(NULL,PointFromText('POINT(9 0)'),127,'00:00:00','0000-00-00','2012-04-04 21:26:12','2013-03-04',0.0,'12:54:30',NULL),
+(NULL,PointFromText('POINT(9 0)'),1,'00:00:00','2013-05-01 22:37:49','2013-06-26','2012-09-22 17:31:03',0.0,'08:09:57','11:15:36');
+Warnings:
+Note	1265	Data truncated for column 'col286' at row 7
+CREATE TABLE t2 (b int) ENGINE=Aria;
+INSERT INTO t2 VALUES (NULL);
+CREATE TABLE t3 (c int) ENGINE=Aria;
+INSERT INTO t3 VALUES (NULL);
+set @tmp_optimizer_switch=@@optimizer_switch;
+set optimizer_switch = 'outer_join_with_cache=on,join_cache_incremental=on';
+set join_buffer_size=128;
+Warnings:
+Warning	1292	Truncated incorrect join_buffer_size value: '128'
+EXPLAIN
+SELECT 1 AS c FROM t1 NATURAL LEFT JOIN t2 LEFT OUTER JOIN t3 ON 1
+GROUP BY elt(t1.col282,1,t1.col280);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	8	Using temporary; Using filesort
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
+SELECT 1 AS c FROM t1 NATURAL LEFT JOIN t2 LEFT OUTER JOIN t3 ON 1
+GROUP BY elt(t1.col282,1,t1.col280);
+c
+1
+set join_buffer_size=default;
+set optimizer_switch=@tmp_optimizer_switch;
+DROP table t1,t2,t3;
 set @@optimizer_switch=@save_optimizer_switch;

=== modified file 'mysql-test/r/select.result'
--- a/mysql-test/r/select.result	2012-05-07 18:14:37 +0000
+++ b/mysql-test/r/select.result	2012-09-30 05:44:13 +0000
@@ -4817,7 +4817,7 @@
 INSERT INTO t5 VALUES (20),(5);
 CREATE TABLE t6(f1 int);
 INSERT INTO t6 VALUES (9),(7);
-SET SESSION join_buffer_size = 2048;
+SET SESSION join_buffer_size = 2176;
 EXPLAIN
 SELECT STRAIGHT_JOIN * FROM t2, (t1 LEFT JOIN (t3,t4) ON t1.f1 = t4.f1), t5, t6;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
@@ -4831,50 +4831,50 @@
 f1	f1	f1	f1	f2	f1	f1
 3	9	NULL	NULL	NULL	20	9
 7	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	5	7
-18	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	7
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	9
-7	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	7
-18	9	NULL	NULL	NULL	5	7
-3	9	NULL	NULL	NULL	20	9
-7	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	5	7
-18	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	7
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	9
-7	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	9
+7	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	5	7
+7	9	NULL	NULL	NULL	5	7
+18	9	NULL	NULL	NULL	5	7
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	5	7
+7	9	NULL	NULL	NULL	5	7
+18	9	NULL	NULL	NULL	5	7
+3	9	NULL	NULL	NULL	5	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	9
+7	9	NULL	NULL	NULL	20	9
+18	9	NULL	NULL	NULL	20	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	5	7
+18	9	NULL	NULL	NULL	5	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	7
+3	9	NULL	NULL	NULL	5	7
 7	9	NULL	NULL	NULL	5	7
 18	9	NULL	NULL	NULL	5	7
 SET SESSION join_buffer_size = DEFAULT;

=== modified file 'mysql-test/r/select_jcl6.result'
--- a/mysql-test/r/select_jcl6.result	2012-05-07 18:14:37 +0000
+++ b/mysql-test/r/select_jcl6.result	2012-09-30 05:44:13 +0000
@@ -4828,7 +4828,7 @@
 INSERT INTO t5 VALUES (20),(5);
 CREATE TABLE t6(f1 int);
 INSERT INTO t6 VALUES (9),(7);
-SET SESSION join_buffer_size = 2048;
+SET SESSION join_buffer_size = 2176;
 EXPLAIN
 SELECT STRAIGHT_JOIN * FROM t2, (t1 LEFT JOIN (t3,t4) ON t1.f1 = t4.f1), t5, t6;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
@@ -4843,48 +4843,48 @@
 3	9	NULL	NULL	NULL	20	9
 7	9	NULL	NULL	NULL	20	9
 18	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	5	7
-18	9	NULL	NULL	NULL	5	7
-3	9	NULL	NULL	NULL	20	9
-7	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	5	7
-18	9	NULL	NULL	NULL	5	7
-3	9	NULL	NULL	NULL	20	9
-7	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	5	7
-18	9	NULL	NULL	NULL	5	7
-3	9	NULL	NULL	NULL	20	9
-7	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	9
+7	9	NULL	NULL	NULL	20	9
+18	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	9
+7	9	NULL	NULL	NULL	20	9
+18	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	9
+7	9	NULL	NULL	NULL	20	9
+18	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	5	7
+7	9	NULL	NULL	NULL	5	7
+18	9	NULL	NULL	NULL	5	7
+3	9	NULL	NULL	NULL	5	7
+7	9	NULL	NULL	NULL	5	7
+18	9	NULL	NULL	NULL	5	7
+3	9	NULL	NULL	NULL	5	7
+7	9	NULL	NULL	NULL	5	7
+18	9	NULL	NULL	NULL	5	7
 3	9	NULL	NULL	NULL	5	7
 7	9	NULL	NULL	NULL	5	7
 18	9	NULL	NULL	NULL	5	7

=== modified file 'mysql-test/r/select_pkeycache.result'
--- a/mysql-test/r/select_pkeycache.result	2012-05-07 18:14:37 +0000
+++ b/mysql-test/r/select_pkeycache.result	2012-09-30 05:44:13 +0000
@@ -4817,7 +4817,7 @@
 INSERT INTO t5 VALUES (20),(5);
 CREATE TABLE t6(f1 int);
 INSERT INTO t6 VALUES (9),(7);
-SET SESSION join_buffer_size = 2048;
+SET SESSION join_buffer_size = 2176;
 EXPLAIN
 SELECT STRAIGHT_JOIN * FROM t2, (t1 LEFT JOIN (t3,t4) ON t1.f1 = t4.f1), t5, t6;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
@@ -4831,50 +4831,50 @@
 f1	f1	f1	f1	f2	f1	f1
 3	9	NULL	NULL	NULL	20	9
 7	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	5	7
-18	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	7
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	9
-7	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	7
-18	9	NULL	NULL	NULL	5	7
-3	9	NULL	NULL	NULL	20	9
-7	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	5	9
-7	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	5	7
-18	9	NULL	NULL	NULL	20	9
-3	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	7
-3	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	5	9
-3	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	7
-3	9	NULL	NULL	NULL	5	7
-7	9	NULL	NULL	NULL	20	9
-18	9	NULL	NULL	NULL	20	9
-7	9	NULL	NULL	NULL	20	7
-18	9	NULL	NULL	NULL	20	7
-7	9	NULL	NULL	NULL	5	9
-18	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	9
+7	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	5	7
+7	9	NULL	NULL	NULL	5	7
+18	9	NULL	NULL	NULL	5	7
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	5	7
+7	9	NULL	NULL	NULL	5	7
+18	9	NULL	NULL	NULL	5	7
+3	9	NULL	NULL	NULL	5	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	9
+3	9	NULL	NULL	NULL	20	9
+7	9	NULL	NULL	NULL	20	9
+18	9	NULL	NULL	NULL	20	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	20	7
+3	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	20	7
+18	9	NULL	NULL	NULL	20	7
+7	9	NULL	NULL	NULL	5	7
+18	9	NULL	NULL	NULL	5	9
+3	9	NULL	NULL	NULL	5	9
+7	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	9
+18	9	NULL	NULL	NULL	5	7
+3	9	NULL	NULL	NULL	5	7
 7	9	NULL	NULL	NULL	5	7
 18	9	NULL	NULL	NULL	5	7
 SET SESSION join_buffer_size = DEFAULT;

=== modified file 'mysql-test/t/join_cache.test'
--- a/mysql-test/t/join_cache.test	2012-02-22 08:38:28 +0000
+++ b/mysql-test/t/join_cache.test	2012-09-30 05:44:13 +0000
@@ -3587,5 +3587,54 @@
 
 DROP TABLE t1,t2,t3;
 
+--echo #
+--echo # Bug #1058071: LEFT JOIN using blobs 
+--echo # (mdev-564)    when join buffer size is small 
+--echo #
+
+CREATE TABLE t1 (
+  col269 decimal(31,10) unsigned DEFAULT NULL,
+  col280 multipoint DEFAULT NULL,
+  col281 tinyint(1) DEFAULT NULL,
+  col282 time NOT NULL,
+  col284 datetime DEFAULT NULL,
+  col286 date DEFAULT NULL,
+  col287 datetime DEFAULT NULL,
+  col288 decimal(30,29) DEFAULT NULL,
+  col291 time DEFAULT NULL,
+  col292 time DEFAULT NULL
+) ENGINE=Aria;
+
+INSERT INTO t1 VALUES
+(0.0,PointFromText('POINT(9 0)'),0,'11:24:05','2013-04-14 21:30:28',NULL,'2011-12-20 06:00:34',9.9,'13:04:39',NULL),
+(0.0,NULL,127,'05:43:12','2012-09-05 06:15:27','2027-01-01','2011-10-29 10:48:29',0.0,'06:24:05','11:33:37'),
+(0.0,NULL,127,'12:54:41','2013-01-12 11:32:58','2011-11-03','2013-01-03 02:00:34',00,'11:54:15','20:19:15'),
+(0.0,PointFromText('POINT(9 0)'),0,'19:48:07','2012-07-16 15:45:25','2012-03-25','2013-09-07 17:21:52',0.5,'17:36:54','21:24:19'),
+(0.0,PointFromText('POINT(9 0)'),0,'03:43:48','2012-09-28 00:00:00','2012-06-26','2011-11-16 05:01:09',00,'01:25:42','19:30:06'),
+(0.0,LineStringFromText('LINESTRING(0 0,9 9,0 0,9 0,0 0)'),127,'11:33:21','2012-03-31 10:29:22','2012-10-10','2012-04-21 19:21:06',NULL,'05:13:22','09:48:34'),
+(NULL,PointFromText('POINT(9 0)'),127,'00:00:00','0000-00-00','2012-04-04 21:26:12','2013-03-04',0.0,'12:54:30',NULL),
+(NULL,PointFromText('POINT(9 0)'),1,'00:00:00','2013-05-01 22:37:49','2013-06-26','2012-09-22 17:31:03',0.0,'08:09:57','11:15:36');
+
+CREATE TABLE t2 (b int) ENGINE=Aria;
+INSERT INTO t2 VALUES (NULL);
+CREATE TABLE t3 (c int) ENGINE=Aria;
+INSERT INTO t3 VALUES (NULL);
+
+set @tmp_optimizer_switch=@@optimizer_switch;
+set optimizer_switch = 'outer_join_with_cache=on,join_cache_incremental=on';
+set join_buffer_size=128;
+
+EXPLAIN
+SELECT 1 AS c FROM t1 NATURAL LEFT JOIN t2 LEFT OUTER JOIN t3 ON 1
+  GROUP BY elt(t1.col282,1,t1.col280);
+
+SELECT 1 AS c FROM t1 NATURAL LEFT JOIN t2 LEFT OUTER JOIN t3 ON 1
+  GROUP BY elt(t1.col282,1,t1.col280);
+
+set join_buffer_size=default;
+set optimizer_switch=@tmp_optimizer_switch;
+
+DROP table t1,t2,t3;
+
 # this must be the last command in the file
 set @@optimizer_switch=@save_optimizer_switch;

=== modified file 'mysql-test/t/select.test'
--- a/mysql-test/t/select.test	2012-05-07 18:14:37 +0000
+++ b/mysql-test/t/select.test	2012-09-30 05:44:13 +0000
@@ -4126,7 +4126,7 @@
 CREATE TABLE t6(f1 int);
 INSERT INTO t6 VALUES (9),(7);
 
-SET SESSION join_buffer_size = 2048;
+SET SESSION join_buffer_size = 2176;
 
 EXPLAIN
 SELECT STRAIGHT_JOIN * FROM t2, (t1 LEFT JOIN (t3,t4) ON t1.f1 = t4.f1), t5, t6;

=== modified file 'sql/sql_join_cache.cc'
--- a/sql/sql_join_cache.cc	2012-08-28 09:51:01 +0000
+++ b/sql/sql_join_cache.cc	2012-09-30 05:44:13 +0000
@@ -680,7 +680,23 @@
   uint len= length + fields*sizeof(uint)+blobs*sizeof(uchar *) +
             (prev_cache ? prev_cache->get_size_of_rec_offset() : 0) +
             sizeof(ulong);
-  buff_size= max(join->thd->variables.join_buff_size, 2*len);
+  /* 
+    The values of  size_of_rec_ofs, size_of_rec_len, size_of_fld_ofs,
+     base_prefix_length, pack_length,  pack_length_with_blob_ptrs
+     will be recalculated later in this function when we get the estimate
+     for the actual value of the join buffer size.
+  */    
+  size_of_rec_ofs=  size_of_rec_len= size_of_fld_ofs= 4;
+  base_prefix_length= (with_length ? size_of_rec_len : 0) +
+                      (prev_cache ? prev_cache->get_size_of_rec_offset() : 0); 
+  pack_length= (with_length ? size_of_rec_len : 0) +
+               (prev_cache ? prev_cache->get_size_of_rec_offset() : 0) + 
+               length + fields*sizeof(uint);
+  pack_length_with_blob_ptrs= pack_length + blobs*sizeof(uchar *);
+  min_buff_size= 0;
+  min_records= 1;
+  buff_size= max(join->thd->variables.join_buff_size,
+                 get_min_join_buffer_size());
   size_of_rec_ofs= offset_size(buff_size);
   size_of_rec_len= blobs ? size_of_rec_ofs : offset_size(len); 
   size_of_fld_ofs= size_of_rec_len;
@@ -753,19 +769,24 @@
   if (!min_buff_size)
   {
     size_t len= 0;
+    size_t len_last= 0;
     for (JOIN_TAB *tab= start_tab; tab != join_tab; 
          tab= next_linear_tab(join, tab, WITHOUT_BUSH_ROOTS))
     {
       len+= tab->get_max_used_fieldlength();
+      len_last=+ tab->get_used_fieldlength();
     }
-    len+= get_record_max_affix_length() + get_max_key_addon_space_per_record();  
-    size_t min_sz= len*min_records;
+    size_t len_addon= get_record_max_affix_length() +
+                      get_max_key_addon_space_per_record();
+    len+= len_addon;
+    len_last+= len_addon;
+    size_t min_sz= len*(min_records-1) + len_last;
+    min_sz+= pack_length_with_blob_ptrs;
     size_t add_sz= 0;
     for (uint i=0; i < min_records; i++)
       add_sz+= join_tab_scan->aux_buffer_incr(i+1);
     avg_aux_buffer_incr= add_sz/min_records;
     min_sz+= add_sz;
-    min_sz+= pack_length_with_blob_ptrs;
     set_if_bigger(min_sz, 1);
     min_buff_size= min_sz;
   }



More information about the commits mailing list