List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:January 28 2008 2:42pm
Subject:bk commit into 5.1 tree (anozdrin:1.2662) BUG#32538
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of anozdrin.  When anozdrin does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-01-28 16:42:53+03:00, anozdrin@quad. +7 -0
  Fix for Bug#32538: View definition picks up character set,
  but not collation.
  
  The problem here was that text literals in a view were always
  dumped with character set introducer. That lead to loosing
  collation information.
  
  The fix is to dump character set introducer only if it was
  in the original query.

  mysql-test/r/ddl_i18n_koi8r.result@stripped, 2008-01-28 16:42:51+03:00, anozdrin@quad. +3 -3
    Update result file.

  mysql-test/r/ddl_i18n_utf8.result@stripped, 2008-01-28 16:42:51+03:00, anozdrin@quad. +3 -3
    Update result file.

  mysql-test/r/view.result@stripped, 2008-01-28 16:42:51+03:00, anozdrin@quad. +49 -3
    Update result file.

  mysql-test/t/view.test@stripped, 2008-01-28 16:42:52+03:00, anozdrin@quad. +67 -2
    Add a test case for Bug#32538.

  sql/item.cc@stripped, 2008-01-28 16:42:52+03:00, anozdrin@quad. +1 -1
    Do not dump character set introducer if it was not specified
    explicitly in the original query.

  sql/item.h@stripped, 2008-01-28 16:42:52+03:00, anozdrin@quad. +16 -0
    Add 'cs_specified' property to Item_string.

  sql/sql_yacc.yy@stripped, 2008-01-28 16:42:52+03:00, anozdrin@quad. +30 -13
    Set Item_string::cs_specified property to TRUE
    when character set introducer is explicitly specified.

diff -Nrup a/mysql-test/r/ddl_i18n_koi8r.result b/mysql-test/r/ddl_i18n_koi8r.result
--- a/mysql-test/r/ddl_i18n_koi8r.result	2008-01-28 16:20:13 +03:00
+++ b/mysql-test/r/ddl_i18n_koi8r.result	2008-01-28 16:42:51 +03:00
@@ -22,7 +22,7 @@ CREATE VIEW v3 AS SELECT _utf8'тест'
 
 SHOW CREATE VIEW v1|
 View	Create View	character_set_client	collation_connection
-v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select _koi8r'' AS `c1`,`t1`.`` AS `c2` from `t1`	koi8r	koi8r_general_ci
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select '' AS `c1`,`t1`.`` AS `c2` from `t1`	koi8r	koi8r_general_ci
 
 SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
@@ -74,7 +74,7 @@ set names koi8r|
 
 SHOW CREATE VIEW v1|
 View	Create View	character_set_client	collation_connection
-v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select _koi8r'' AS `c1`,`t1`.`` AS `c2` from `t1`	koi8r	koi8r_general_ci
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select '' AS `c1`,`t1`.`` AS `c2` from `t1`	koi8r	koi8r_general_ci
 
 SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
@@ -131,7 +131,7 @@ set names koi8r|
 
 SHOW CREATE VIEW v1|
 View	Create View	character_set_client	collation_connection
-v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select _koi8r'' AS `c1`,`t1`.`` AS `c2` from `t1`	koi8r	koi8r_general_ci
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select '' AS `c1`,`t1`.`` AS `c2` from `t1`	koi8r	koi8r_general_ci
 
 SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
diff -Nrup a/mysql-test/r/ddl_i18n_utf8.result b/mysql-test/r/ddl_i18n_utf8.result
--- a/mysql-test/r/ddl_i18n_utf8.result	2008-01-28 16:20:13 +03:00
+++ b/mysql-test/r/ddl_i18n_utf8.result	2008-01-28 16:42:51 +03:00
@@ -22,7 +22,7 @@ CREATE VIEW v3 AS SELECT _koi8r''|
 
 SHOW CREATE VIEW v1|
 View	Create View	character_set_client	collation_connection
-v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select _utf8'тест' AS `c1`,`t1`.`кол` AS `c2` from `t1`	utf8	utf8_general_ci
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select 'тест' AS `c1`,`t1`.`кол` AS `c2` from `t1`	utf8	utf8_general_ci
 
 SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
@@ -74,7 +74,7 @@ set names utf8|
 
 SHOW CREATE VIEW v1|
 View	Create View	character_set_client	collation_connection
-v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select _utf8'тест' AS `c1`,`t1`.`кол` AS `c2` from `t1`	utf8	utf8_general_ci
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select 'тест' AS `c1`,`t1`.`кол` AS `c2` from `t1`	utf8	utf8_general_ci
 
 SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
@@ -131,7 +131,7 @@ set names utf8|
 
 SHOW CREATE VIEW v1|
 View	Create View	character_set_client	collation_connection
-v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select _utf8'тест' AS `c1`,`t1`.`кол` AS `c2` from `t1`	utf8	utf8_general_ci
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select 'тест' AS `c1`,`t1`.`кол` AS `c2` from `t1`	utf8	utf8_general_ci
 
 SHOW CREATE VIEW v2|
 View	Create View	character_set_client	collation_connection
diff -Nrup a/mysql-test/r/view.result b/mysql-test/r/view.result
--- a/mysql-test/r/view.result	2008-01-19 20:59:07 +03:00
+++ b/mysql-test/r/view.result	2008-01-28 16:42:51 +03:00
@@ -3061,7 +3061,7 @@ TheEnd
 TheEnd
 SHOW CREATE VIEW v1;
 View	Create View	character_set_client	collation_connection
-v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select _latin1'The\ZEnd' AS `TheEnd`	latin1	latin1_swedish_ci
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select 'The\ZEnd' AS `TheEnd`	latin1	latin1_swedish_ci
 DROP VIEW v1;
 CREATE TABLE t1 (mydate DATETIME);
 INSERT INTO t1 VALUES
@@ -3613,7 +3613,9 @@ ERROR HY000: Field of view 'test.v1' und
 set @@sql_mode=@old_mode;
 drop view v1;
 drop table t1;
-End of 5.0 tests.
+# -----------------------------------------------------------------
+# -- End of 5.0 tests.
+# -----------------------------------------------------------------
 DROP DATABASE IF EXISTS `d-1`;
 CREATE DATABASE `d-1`;
 USE `d-1`;
@@ -3676,4 +3678,48 @@ DROP TABLE t1;
 
 # End of test case for Bug#26676.
 
-End of 5.1 tests.
+# -----------------------------------------------------------------
+# -- Bug#32538: View definition picks up character set, but not collation
+# -----------------------------------------------------------------
+
+DROP VIEW IF EXISTS v1;
+
+SET collation_connection = latin1_general_ci;
+CREATE VIEW v1 AS SELECT _latin1 'text1' AS c1, 'text2' AS c2;
+
+SELECT COLLATION(c1), COLLATION(c2) FROM v1;
+COLLATION(c1)	COLLATION(c2)
+latin1_swedish_ci	latin1_general_ci
+
+SHOW CREATE VIEW v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1`
AS select _latin1'text1' AS `c1`,'text2' AS `c2`	latin1	latin1_general_ci
+
+SELECT * FROM v1 WHERE c1 = 'text1';
+ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and
(latin1_general_ci,COERCIBLE) for operation '='
+
+SELECT * FROM v1 WHERE c2 = 'text2';
+c1	c2
+text1	text2
+
+use test;
+SET names latin1;
+
+SELECT COLLATION(c1), COLLATION(c2) FROM v1;
+COLLATION(c1)	COLLATION(c2)
+latin1_swedish_ci	latin1_general_ci
+
+SELECT * FROM v1 WHERE c1 = 'text1';
+c1	c2
+text1	text2
+
+SELECT * FROM v1 WHERE c2 = 'text2';
+ERROR HY000: Illegal mix of collations (latin1_general_ci,COERCIBLE) and
(latin1_swedish_ci,COERCIBLE) for operation '='
+
+DROP VIEW v1;
+
+# -- End of test case for Bug#32538.
+
+# -----------------------------------------------------------------
+# -- End of 5.1 tests.
+# -----------------------------------------------------------------
diff -Nrup a/mysql-test/t/view.test b/mysql-test/t/view.test
--- a/mysql-test/t/view.test	2008-01-19 21:09:20 +03:00
+++ b/mysql-test/t/view.test	2008-01-28 16:42:52 +03:00
@@ -3468,7 +3468,9 @@ set @@sql_mode=@old_mode;
 drop view v1;
 drop table t1;
 
---echo End of 5.0 tests.
+--echo # -----------------------------------------------------------------
+--echo # -- End of 5.0 tests.
+--echo # -----------------------------------------------------------------
 
 #
 # Bug#21370 View renaming lacks tablename_to_filename encoding
@@ -3540,4 +3542,67 @@ DROP TABLE t1;
 --echo # End of test case for Bug#26676.
 --echo
 
---echo End of 5.1 tests.
+###########################################################################
+
+--echo # -----------------------------------------------------------------
+--echo # -- Bug#32538: View definition picks up character set, but not collation
+--echo # -----------------------------------------------------------------
+--echo
+
+--disable_warnings
+DROP VIEW IF EXISTS v1;
+--enable_warnings
+
+--echo
+
+SET collation_connection = latin1_general_ci;
+CREATE VIEW v1 AS SELECT _latin1 'text1' AS c1, 'text2' AS c2;
+
+--echo
+
+SELECT COLLATION(c1), COLLATION(c2) FROM v1;
+
+--echo
+
+SHOW CREATE VIEW v1;
+
+--echo
+
+--error ER_CANT_AGGREGATE_2COLLATIONS
+SELECT * FROM v1 WHERE c1 = 'text1';
+
+--echo
+
+SELECT * FROM v1 WHERE c2 = 'text2';
+
+--echo
+
+use test;
+SET names latin1;
+
+--echo
+
+SELECT COLLATION(c1), COLLATION(c2) FROM v1;
+
+--echo
+
+SELECT * FROM v1 WHERE c1 = 'text1';
+
+--echo
+
+--error ER_CANT_AGGREGATE_2COLLATIONS
+SELECT * FROM v1 WHERE c2 = 'text2';
+
+--echo
+
+DROP VIEW v1;
+
+--echo
+--echo # -- End of test case for Bug#32538.
+--echo
+
+###########################################################################
+
+--echo # -----------------------------------------------------------------
+--echo # -- End of 5.1 tests.
+--echo # -----------------------------------------------------------------
diff -Nrup a/sql/item.cc b/sql/item.cc
--- a/sql/item.cc	2008-01-28 16:20:13 +03:00
+++ b/sql/item.cc	2008-01-28 16:42:52 +03:00
@@ -2307,7 +2307,7 @@ void Item_string::print(String *str)
   THD *thd= current_thd;
   bool dump_utf8_query= thd->get_dump_utf8_query();
 
-  if (!dump_utf8_query)
+  if (!dump_utf8_query && is_cs_specified())
   {
     str->append('_');
     str->append(collation.collation->csname);
diff -Nrup a/sql/item.h b/sql/item.h
--- a/sql/item.h	2007-12-13 14:57:03 +03:00
+++ b/sql/item.h	2008-01-28 16:42:52 +03:00
@@ -1842,6 +1842,7 @@ public:
   Item_string(const char *str,uint length,
               CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
               uint repertoire= MY_REPERTOIRE_UNICODE30)
+    : m_cs_specified(FALSE)
   {
     str_value.set_or_copy_aligned(str, length, cs);
     collation.set(cs, dv, repertoire);
@@ -1860,6 +1861,7 @@ public:
   }
   /* Just create an item and do not fill string representation */
   Item_string(CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
+    : m_cs_specified(FALSE)
   {
     collation.set(cs, dv);
     max_length= 0;
@@ -1870,6 +1872,7 @@ public:
   Item_string(const char *name_par, const char *str, uint length,
               CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
               uint repertoire= MY_REPERTOIRE_UNICODE30)
+    : m_cs_specified(FALSE)
   {
     str_value.set_or_copy_aligned(str, length, cs);
     collation.set(cs, dv, repertoire);
@@ -1923,6 +1926,19 @@ public:
   // to prevent drop fixed flag (no need parent cleanup call)
   void cleanup() {}
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+
+  inline bool is_cs_specified() const
+  {
+    return m_cs_specified;
+  }
+
+  inline void set_cs_specified(bool cs_specified)
+  {
+    m_cs_specified= cs_specified;
+  }
+
+private:
+  bool m_cs_specified;
 };
 
 
diff -Nrup a/sql/sql_yacc.yy b/sql/sql_yacc.yy
--- a/sql/sql_yacc.yy	2008-01-28 16:20:14 +03:00
+++ b/sql/sql_yacc.yy	2008-01-28 16:42:52 +03:00
@@ -9745,8 +9745,11 @@ text_literal:
           }
         | UNDERSCORE_CHARSET TEXT_STRING
           {
-            $$= new Item_string($2.str, $2.length, $1);
-            ((Item_string*) $$)->set_repertoire_from_value();
+            Item_string *str= new Item_string($2.str, $2.length, $1);
+            str->set_repertoire_from_value();
+            str->set_cs_specified(TRUE);
+
+            $$= str;
           }
         | text_literal TEXT_STRING_literal
           {
@@ -9849,15 +9852,22 @@ literal:
             String *str= tmp ?
               tmp->quick_fix_field(), tmp->val_str((String*) 0) :
               (String*) 0;
-            $$= new Item_string(NULL, /* name will be set in select_item */
-                                str ? str->ptr() : "",
-                                str ? str->length() : 0,
-                                $1);
-            if (!$$ || !$$->check_well_formed_result(&$$->str_value, TRUE))
+
+            Item_string *item_str=
+              new Item_string(NULL, /* name will be set in select_item */
+                              str ? str->ptr() : "",
+                              str ? str->length() : 0,
+                              $1);
+            if (!item_str ||
+                !item_str->check_well_formed_result(&item_str->str_value,
TRUE))
             {
               MYSQL_YYABORT;
             }
-            ((Item_string *) $$)->set_repertoire_from_value();
+
+            item_str->set_repertoire_from_value();
+            item_str->set_cs_specified(TRUE);
+
+            $$= item_str;
           }
         | UNDERSCORE_CHARSET BIN_NUM
           {
@@ -9869,14 +9879,21 @@ literal:
             String *str= tmp ?
               tmp->quick_fix_field(), tmp->val_str((String*) 0) :
               (String*) 0;
-            $$= new Item_string(NULL, /* name will be set in select_item */
-                                str ? str->ptr() : "",
-                                str ? str->length() : 0,
-                                $1);
-            if (!$$ || !$$->check_well_formed_result(&$$->str_value, TRUE))
+
+            Item_string *item_str=
+              new Item_string(NULL, /* name will be set in select_item */
+                              str ? str->ptr() : "",
+                              str ? str->length() : 0,
+                              $1);
+            if (!item_str ||
+                !item_str->check_well_formed_result(&item_str->str_value,
TRUE))
             {
               MYSQL_YYABORT;
             }
+
+            item_str->set_cs_specified(TRUE);
+
+            $$= item_str;
           }
         | DATE_SYM text_literal { $$ = $2; }
         | TIME_SYM text_literal { $$ = $2; }
Thread
bk commit into 5.1 tree (anozdrin:1.2662) BUG#32538Alexander Nozdrin28 Jan