MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Ramil Kalimullin Date:May 15 2009 9:26am
Subject:bzr commit into mysql-5.1-bugteam branch (ramil:2874) Bug#44743
Bug#44766
View as plain text  
#At file:///home/ram/mysql/b44743-5.1-bugteam/ based on revid:mats@stripped

 2874 Ramil Kalimullin	2009-05-15
      Fix for bug#44743: Join in combination with concat does not always work
              bug#44766: valgrind error when using convert() in a subquery
      
      Problem: converting a string to some charset we didn't take into account
      that input and output buffers may be the same.
      
      Fix: reallocate output buffer in such cases.
     @ mysql-test/r/cast.result
        Fix for bug#44743: Join in combination with concat does not always work
                bug#44766: valgrind error when using convert() in a subquery
          - test result.
     @ mysql-test/r/func_concat.result
        Fix for bug#44743: Join in combination with concat does not always work
                bug#44766: valgrind error when using convert() in a subquery
          - test result.
     @ mysql-test/t/cast.test
        Fix for bug#44743: Join in combination with concat does not always work
                bug#44766: valgrind error when using convert() in a subquery
          - test case.
     @ mysql-test/t/func_concat.test
        Fix for bug#44743: Join in combination with concat does not always work
                bug#44766: valgrind error when using convert() in a subquery
          - test case.
     @ sql/sql_string.cc
        Fix for bug#44743: Join in combination with concat does not always work
                bug#44766: valgrind error when using convert() in a subquery
          - String::copy() - if the input string points to the output buffer,
            allocate the buffer anew.

    modified:
      mysql-test/r/cast.result
      mysql-test/r/func_concat.result
      mysql-test/t/cast.test
      mysql-test/t/func_concat.test
      sql/sql_string.cc
=== modified file 'mysql-test/r/cast.result'
--- a/mysql-test/r/cast.result	2008-01-10 10:37:54 +0000
+++ b/mysql-test/r/cast.result	2009-05-15 09:26:40 +0000
@@ -439,3 +439,16 @@ HOUR(NULL)	MINUTE(NULL)	SECOND(NULL)
 NULL	NULL	NULL
 DROP TABLE t1;
 End of 5.0 tests
+#
+#  Bug #44766: valgrind error when using convert() in a subquery
+#
+CREATE TABLE t1(a tinyint);
+INSERT INTO t1 VALUES (127);
+SELECT 1 FROM
+(
+SELECT CONVERT(t2.a USING UTF8) FROM t1, t1 t2 LIMIT 1
+) AS s LIMIT 1;
+1
+1
+DROP TABLE t1;
+End of 5.1 tests

=== modified file 'mysql-test/r/func_concat.result'
--- a/mysql-test/r/func_concat.result	2008-05-13 15:27:46 +0000
+++ b/mysql-test/r/func_concat.result	2009-05-15 09:26:40 +0000
@@ -89,3 +89,34 @@ c1	c2
 	First
 DROP TABLE t1;
 # End of 5.0 tests
+#
+# Bug #44743: Join in combination with concat does not always work
+#
+CREATE TABLE t1 (
+a VARCHAR(100) NOT NULL DEFAULT '0',
+b VARCHAR(2) NOT NULL DEFAULT '',
+c VARCHAR(2) NOT NULL DEFAULT '',
+d TEXT NOT NULL,
+PRIMARY KEY (a, b, c),
+KEY (a)
+) DEFAULT CHARSET=utf8;
+INSERT INTO t1 VALUES ('gui_A', 'a', 'b', 'str1'),
+('gui_AB', 'a', 'b', 'str2'), ('gui_ABC', 'a', 'b', 'str3');
+CREATE TABLE t2 (
+a VARCHAR(100) NOT NULL DEFAULT '',
+PRIMARY KEY (a)
+) DEFAULT CHARSET=latin1;
+INSERT INTO t2 VALUES ('A'), ('AB'), ('ABC');
+SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
+LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
+CONCAT('gui_', t2.a)	d
+gui_A	str1
+gui_AB	str2
+gui_ABC	str3
+EXPLAIN SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
+LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	index	NULL	PRIMARY	102	NULL	3	Using index
+1	SIMPLE	t1	eq_ref	PRIMARY,a	PRIMARY	318	func,const,const	1	
+DROP TABLE t1, t2;
+# End of 5.1 tests

=== modified file 'mysql-test/t/cast.test'
--- a/mysql-test/t/cast.test	2008-01-10 10:37:54 +0000
+++ b/mysql-test/t/cast.test	2009-05-15 09:26:40 +0000
@@ -269,3 +269,18 @@ SELECT HOUR(NULL),
 DROP TABLE t1;
 
 --echo End of 5.0 tests
+
+--echo #
+--echo #  Bug #44766: valgrind error when using convert() in a subquery
+--echo #
+
+CREATE TABLE t1(a tinyint);
+INSERT INTO t1 VALUES (127);
+SELECT 1 FROM
+(
+ SELECT CONVERT(t2.a USING UTF8) FROM t1, t1 t2 LIMIT 1
+) AS s LIMIT 1;
+DROP TABLE t1;
+
+
+--echo End of 5.1 tests

=== modified file 'mysql-test/t/func_concat.test'
--- a/mysql-test/t/func_concat.test	2008-05-13 15:27:46 +0000
+++ b/mysql-test/t/func_concat.test	2009-05-15 09:26:40 +0000
@@ -78,3 +78,37 @@ SELECT * FROM t1 WHERE CONCAT(c1,' ',c2)
 DROP TABLE t1;
 
 --echo # End of 5.0 tests
+
+
+--echo #
+--echo # Bug #44743: Join in combination with concat does not always work
+--echo #
+CREATE TABLE t1 (
+  a VARCHAR(100) NOT NULL DEFAULT '0',
+  b VARCHAR(2) NOT NULL DEFAULT '',
+  c VARCHAR(2) NOT NULL DEFAULT '',
+  d TEXT NOT NULL,
+  PRIMARY KEY (a, b, c),
+  KEY (a)
+) DEFAULT CHARSET=utf8;
+
+INSERT INTO t1 VALUES ('gui_A', 'a', 'b', 'str1'),
+  ('gui_AB', 'a', 'b', 'str2'), ('gui_ABC', 'a', 'b', 'str3');
+
+CREATE TABLE t2 (
+  a VARCHAR(100) NOT NULL DEFAULT '',
+  PRIMARY KEY (a)
+) DEFAULT CHARSET=latin1;
+
+INSERT INTO t2 VALUES ('A'), ('AB'), ('ABC');
+
+SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
+  LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
+
+EXPLAIN SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
+  LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
+
+DROP TABLE t1, t2;
+
+
+--echo # End of 5.1 tests

=== modified file 'sql/sql_string.cc'
--- a/sql/sql_string.cc	2009-03-24 13:58:52 +0000
+++ b/sql/sql_string.cc	2009-05-15 09:26:40 +0000
@@ -328,6 +328,16 @@ bool String::copy(const char *str, uint3
 		  CHARSET_INFO *from_cs, CHARSET_INFO *to_cs, uint *errors)
 {
   uint32 offset;
+  /*
+    If the input string "str" points to the buffer "Ptr" force the following
+    code to allocate a buffer over again and not to free the "str".
+  */
+  if (str == Ptr)
+  {
+    alloced= FALSE;
+    Alloced_length= 0;
+    Ptr= NULL;
+  }
   if (!needs_conversion(arg_length, from_cs, to_cs, &offset))
   {
     *errors= 0;


Attachment: [text/bzr-bundle] bzr/ramil@mysql.com-20090515092640-llol0gq7ntwep8zo.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (ramil:2874) Bug#44743Bug#44766Ramil Kalimullin15 May