[Commits] Rev 2819: Fixed bug #52394 / LP bug #623209. in file:///home/igor/maria/maria-5.3-mwl128-bugs/

igor at askmonty.org igor at askmonty.org
Wed Sep 22 02:42:00 EEST 2010


At file:///home/igor/maria/maria-5.3-mwl128-bugs/

------------------------------------------------------------
revno: 2819
revision-id: igor at askmonty.org-20100921234153-cvokxpi8wqq5m1dn
parent: igor at askmonty.org-20100903001603-t6l2k9cjei985zs6
committer: Igor Babaev <igor at askmonty.org>
branch nick: maria-5.3-mwl128-bugs
timestamp: Tue 2010-09-21 16:41:53 -0700
message:
  Fixed bug #52394 / LP bug #623209.
  When an incremental join cache is used to join a table whose
  fields are not referenced anywhere in the query the association
  pointer to the last record in the such cache can be the same
  as the pointer to the end of the buffer. 
  The function JOIN_CACHE_BKA::get_next_key must take into 
  consideration this when iterating over the keys of the records
  from the join buffer. 
  The assertion in JOIN_TAB_SCAN_MRR::next also must take this
  into consideration.
  Borrowed a slightly changed test case from a patch attached to the
  bug #52394.
-------------- next part --------------
=== modified file 'mysql-test/r/join_cache.result' (properties changed: +x to -x)
--- a/mysql-test/r/join_cache.result	2010-08-31 16:34:21 +0000
+++ b/mysql-test/r/join_cache.result	2010-09-21 23:41:53 +0000
@@ -5174,3 +5174,31 @@
 set join_cache_level=default;
 drop table t1,t2,t3;
 set @@optimizer_switch=@save_optimizer_switch;
+#
+# Bug #52394:  using join buffer for 3 table join with ref access 
+# LP #623209: and no references to the columns of the middle table
+#
+set join_cache_level=6;
+CREATE TABLE t1 (a int(11), b varchar(1));
+INSERT INTO t1 VALUES (6,'r'),(27,'o');
+CREATE TABLE t2(a int);
+INSERT INTO t2 VALUES(1),(2),(3),(4),(5);
+CREATE TABLE t3 (a int(11) primary key, b varchar(1));
+INSERT INTO t3 VALUES
+(14,'d'),(15,'z'),(16,'e'),(17,'h'),(18,'b'),(19,'s'),(20,'e'),
+(21,'j'),(22,'e'),(23,'f'),(24,'v'),(25,'x'),(26,'m'),(27,'o');
+EXPLAIN
+SELECT t3.a FROM t1,t2,t3 WHERE t1.a = t3.a AND t1.b = t3.b;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	5	Using join buffer
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t1.a	1	Using where; Using join buffer
+SELECT t3.a FROM t1,t2,t3 WHERE t1.a = t3.a AND t1.b = t3.b;
+a
+27
+27
+27
+27
+27
+DROP TABLE t1,t2,t3;
+set join_cache_level=default;

=== modified file 'mysql-test/t/join_cache.test'
--- a/mysql-test/t/join_cache.test	2010-08-31 16:34:21 +0000
+++ b/mysql-test/t/join_cache.test	2010-09-21 23:41:53 +0000
@@ -1956,3 +1956,31 @@
 drop table t1,t2,t3;
 
 set @@optimizer_switch=@save_optimizer_switch;
+
+--echo #
+--echo # Bug #52394:  using join buffer for 3 table join with ref access 
+--echo # LP #623209: and no references to the columns of the middle table
+--echo #
+
+
+set join_cache_level=6;
+
+CREATE TABLE t1 (a int(11), b varchar(1));
+INSERT INTO t1 VALUES (6,'r'),(27,'o');
+
+CREATE TABLE t2(a int);
+INSERT INTO t2 VALUES(1),(2),(3),(4),(5);
+
+CREATE TABLE t3 (a int(11) primary key, b varchar(1));
+INSERT INTO t3 VALUES
+(14,'d'),(15,'z'),(16,'e'),(17,'h'),(18,'b'),(19,'s'),(20,'e'),
+(21,'j'),(22,'e'),(23,'f'),(24,'v'),(25,'x'),(26,'m'),(27,'o');
+
+EXPLAIN
+SELECT t3.a FROM t1,t2,t3 WHERE t1.a = t3.a AND t1.b = t3.b;
+SELECT t3.a FROM t1,t2,t3 WHERE t1.a = t3.a AND t1.b = t3.b;
+
+DROP TABLE t1,t2,t3;
+
+set join_cache_level=default;
+

=== modified file 'sql/sql_join_cache.cc'
--- a/sql/sql_join_cache.cc	2010-09-03 00:16:03 +0000
+++ b/sql/sql_join_cache.cc	2010-09-21 23:41:53 +0000
@@ -3391,8 +3391,12 @@
   uint rc= join_tab->table->file->multi_range_read_next(ptr) ? -1 : 0;
   if (!rc)
   {
+    /* 
+      If a record in in an incremental cache contains no fields then the
+      association for the last record in cache will be equal to cache->end_pos
+    */ 
     DBUG_ASSERT(cache->buff <= (uchar *) (*ptr) &&
-                (uchar *) (*ptr) < cache->end_pos);
+                (uchar *) (*ptr) <= cache->end_pos);
     update_virtual_fields(join_tab->table);
   }
   return rc;
@@ -3728,12 +3732,12 @@
   uchar *init_pos;
   JOIN_CACHE *cache;
   
-  if (pos > last_rec_pos || !records)
-    return 0;
-
   /* Any record in a BKA cache is prepended with its length */
   DBUG_ASSERT(with_length);
    
+  if ((pos+size_of_rec_len) > last_rec_pos || !records)
+    return 0;
+
   /* Read the length of the record */
   rec_len= get_rec_length(pos);
   pos+= size_of_rec_len; 



More information about the commits mailing list