← Back to team overview

maria-developers team mailing list archive

bzr commit into MariaDB 5.1, with Maria 1.5:maria branch (knielsen:2798)

 

#At lp:maria

 2798 knielsen@xxxxxxxxxxxxxxx	2010-03-09 [merge]
      Automerge for buildbot test
      modified:
        mysql-test/r/table_elim.result
        mysql-test/t/table_elim.test
        sql/handler.cc
        sql/set_var.cc
        sql/sql_plugin.cc
        sql/sql_plugin.h
        sql/sql_select.cc
        sql/table.cc

=== modified file 'mysql-test/r/table_elim.result'
--- a/mysql-test/r/table_elim.result	2010-02-18 12:03:52 +0000
+++ b/mysql-test/r/table_elim.result	2010-03-06 12:09:02 +0000
@@ -1,4 +1,4 @@
-drop table if exists t0, t1, t2, t3;
+drop table if exists t0, t1, t2, t3, t4, t5, t6;
 drop view if exists v1, v2;
 create table t1 (a int);
 insert into t1 values (0),(1),(2),(3);
@@ -464,3 +464,74 @@ t1 AS table3 ON (
 HAVING field1 < 216;
 field1
 DROP TABLE t1, t2;
+#
+# LPBUG#524025 Running RQG outer_join test leads to crash
+#
+CREATE TABLE t0 (
+pk int(11) NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t1 (
+col_int int(11) DEFAULT NULL,
+col_int_key int(11) DEFAULT NULL,
+pk int(11) NOT NULL AUTO_INCREMENT,
+col_varchar_10_latin1 varchar(10) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+INSERT INTO t1 VALUES (5,5,1,'t'), (NULL,NULL,2,'y');
+CREATE TABLE t2 (
+col_int int(11) DEFAULT NULL
+);
+INSERT INTO t2 VALUES (8), (4);
+CREATE TABLE t3 (
+pk int(11) NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (pk)
+);
+INSERT INTO t3 VALUES (1),(8);
+CREATE TABLE t4 (
+pk int(11) NOT NULL AUTO_INCREMENT,
+col_varchar_1024_latin1_key varchar(1024) DEFAULT NULL,
+col_int int(11) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+INSERT INTO t4 VALUES (1,'o',1), (2,'w',2);
+CREATE TABLE t5 (
+col_varchar_1024_utf8_key varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
+col_varchar_1024_latin1_key varchar(1024) DEFAULT NULL,
+col_varchar_10_utf8_key varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
+pk int(11) NOT NULL AUTO_INCREMENT,
+col_int_key int(11) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+INSERT INTO t5 VALUES ('k','a','z',1,2),('x','a','w',2,7);
+CREATE TABLE t6 (
+col_int int(11) DEFAULT NULL,
+col_int_key int(11) DEFAULT NULL
+);
+INSERT INTO t6 VALUES (6,1),(8,3);
+SELECT
+table3.col_int AS field1,
+table1.col_int AS field2,
+table1.col_int_key AS field3,
+table1.pk AS field4,
+table1.col_int AS field5,
+table2.col_int AS field6
+FROM
+t1 AS table1
+LEFT OUTER JOIN
+t4 AS table2
+LEFT JOIN t6 AS table3
+RIGHT JOIN t3 AS table4
+LEFT JOIN t5 AS table5 ON table4.pk = table5.pk
+LEFT JOIN t0 AS table6 ON table5.col_int_key = table6.pk
+ON table3.col_int_key = table5.pk
+ON table2.col_varchar_1024_latin1_key = table5.col_varchar_10_utf8_key
+LEFT JOIN t6 AS table7 ON table2.pk = table7.col_int
+ON table1.col_varchar_10_latin1 = table5.col_varchar_1024_latin1_key
+LEFT JOIN t2 AS table8 ON table3.col_int = table8.col_int
+WHERE
+table1.col_int_key < table2.pk
+HAVING
+field4 != 6;
+field1	field2	field3	field4	field5	field6
+drop table t0,t1,t2,t3,t4,t5,t6;

=== modified file 'mysql-test/t/table_elim.test'
--- a/mysql-test/t/table_elim.test	2010-02-18 12:03:52 +0000
+++ b/mysql-test/t/table_elim.test	2010-03-06 12:09:02 +0000
@@ -2,7 +2,7 @@
 # Table elimination (MWL#17) tests
 #
 --disable_warnings
-drop table if exists t0, t1, t2, t3;
+drop table if exists t0, t1, t2, t3, t4, t5, t6;
 drop view if exists v1, v2;
 --enable_warnings
 
@@ -387,3 +387,83 @@ HAVING field1 < 216;
 
 DROP TABLE t1, t2;
 
+
+--echo #
+--echo # LPBUG#524025 Running RQG outer_join test leads to crash
+--echo #
+
+CREATE TABLE t0 (
+  pk int(11) NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (pk)
+);
+
+CREATE TABLE t1 (
+  col_int int(11) DEFAULT NULL,
+  col_int_key int(11) DEFAULT NULL,
+  pk int(11) NOT NULL AUTO_INCREMENT,
+  col_varchar_10_latin1 varchar(10) DEFAULT NULL,
+  PRIMARY KEY (pk)
+);
+INSERT INTO t1 VALUES (5,5,1,'t'), (NULL,NULL,2,'y');
+
+CREATE TABLE t2 (
+  col_int int(11) DEFAULT NULL
+);
+INSERT INTO t2 VALUES (8), (4);
+
+CREATE TABLE t3 (
+  pk int(11) NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (pk)
+);
+INSERT INTO t3 VALUES (1),(8);
+
+CREATE TABLE t4 (
+  pk int(11) NOT NULL AUTO_INCREMENT,
+  col_varchar_1024_latin1_key varchar(1024) DEFAULT NULL,
+  col_int int(11) DEFAULT NULL,
+  PRIMARY KEY (pk)
+);
+INSERT INTO t4 VALUES (1,'o',1), (2,'w',2);
+
+CREATE TABLE t5 (
+  col_varchar_1024_utf8_key varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
+  col_varchar_1024_latin1_key varchar(1024) DEFAULT NULL,
+  col_varchar_10_utf8_key varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
+  pk int(11) NOT NULL AUTO_INCREMENT,
+  col_int_key int(11) DEFAULT NULL,
+  PRIMARY KEY (pk)
+);
+INSERT INTO t5 VALUES ('k','a','z',1,2),('x','a','w',2,7);
+
+CREATE TABLE t6 (
+  col_int int(11) DEFAULT NULL,
+  col_int_key int(11) DEFAULT NULL
+);
+INSERT INTO t6 VALUES (6,1),(8,3);
+ 
+SELECT
+  table3.col_int AS field1,
+  table1.col_int AS field2,
+  table1.col_int_key AS field3,
+  table1.pk AS field4,
+  table1.col_int AS field5,
+  table2.col_int AS field6
+FROM
+  t1 AS table1
+  LEFT OUTER JOIN
+  t4 AS table2
+  LEFT JOIN t6 AS table3
+  RIGHT JOIN t3 AS table4
+  LEFT JOIN t5 AS table5 ON table4.pk = table5.pk
+  LEFT JOIN t0 AS table6 ON table5.col_int_key = table6.pk
+  ON table3.col_int_key = table5.pk
+  ON table2.col_varchar_1024_latin1_key = table5.col_varchar_10_utf8_key
+  LEFT JOIN t6 AS table7 ON table2.pk = table7.col_int
+  ON table1.col_varchar_10_latin1 = table5.col_varchar_1024_latin1_key
+  LEFT JOIN t2 AS table8 ON table3.col_int = table8.col_int
+WHERE
+  table1.col_int_key < table2.pk
+HAVING
+  field4 != 6;
+
+drop table t0,t1,t2,t3,t4,t5,t6;

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2010-01-15 15:27:55 +0000
+++ b/sql/handler.cc	2010-03-08 13:57:32 +0000
@@ -82,7 +82,7 @@ static plugin_ref ha_default_plugin(THD 
 {
   if (thd->variables.table_plugin)
     return thd->variables.table_plugin;
-  return my_plugin_lock(thd, &global_system_variables.table_plugin);
+  return my_plugin_lock(thd, global_system_variables.table_plugin);
 }
 
 
@@ -163,13 +163,8 @@ plugin_ref ha_lock_engine(THD *thd, hand
 {
   if (hton)
   {
-    st_plugin_int **plugin= hton2plugin + hton->slot;
-    
-#ifdef DBUG_OFF
-    return my_plugin_lock(thd, plugin);
-#else
-    return my_plugin_lock(thd, &plugin);
-#endif
+    st_plugin_int *plugin= hton2plugin[hton->slot];
+    return my_plugin_lock(thd, plugin_int_to_ref(plugin));
   }
   return NULL;
 }

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2010-03-04 08:03:07 +0000
+++ b/sql/set_var.cc	2010-03-09 19:23:30 +0000
@@ -3858,7 +3858,7 @@ uchar *sys_var_thd_storage_engine::value
   LEX_STRING *engine_name;
   plugin_ref plugin= thd->variables.*offset;
   if (type == OPT_GLOBAL)
-    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
+    plugin= my_plugin_lock(thd, global_system_variables.*offset);
   hton= plugin_data(plugin, handlerton*);
   engine_name= hton_name(hton);
   result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
@@ -3879,7 +3879,7 @@ void sys_var_thd_storage_engine::set_def
   else
   {
     value= &(thd->variables.*offset);
-    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
+    new_value= my_plugin_lock(NULL, global_system_variables.*offset);
   }
   DBUG_ASSERT(new_value);
   old_value= *value;
@@ -3896,7 +3896,7 @@ bool sys_var_thd_storage_engine::update(
   old_value= *value;
   if (old_value != var->save_result.plugin)
   {
-    *value= my_plugin_lock(NULL, &var->save_result.plugin);
+    *value= my_plugin_lock(NULL, var->save_result.plugin);
     plugin_unlock(NULL, old_value);
   }
   return 0;

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2010-03-04 08:03:07 +0000
+++ b/sql/sql_plugin.cc	2010-03-09 19:23:30 +0000
@@ -19,14 +19,6 @@
 #define REPORT_TO_LOG  1
 #define REPORT_TO_USER 2
 
-#ifdef DBUG_OFF
-#define plugin_ref_to_int(A) A
-#define plugin_int_to_ref(A) A
-#else
-#define plugin_ref_to_int(A) (A ? A[0] : NULL)
-#define plugin_int_to_ref(A) &(A)
-#endif
-
 extern struct st_mysql_plugin *mysqld_builtins[];
 
 /**
@@ -630,7 +622,10 @@ static plugin_ref intern_plugin_lock(LEX
   {
     plugin_ref plugin;
 #ifdef DBUG_OFF
-    /* built-in plugins don't need ref counting */
+    /*
+      In optimized builds we don't do reference counting for built-in
+      (plugin->plugin_dl == 0) plugins.
+    */
     if (!pi->plugin_dl)
       DBUG_RETURN(pi);
 
@@ -658,13 +653,33 @@ static plugin_ref intern_plugin_lock(LEX
 }
 
 
-plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
+plugin_ref plugin_lock(THD *thd, plugin_ref ptr CALLER_INFO_PROTO)
 {
   LEX *lex= thd ? thd->lex : 0;
   plugin_ref rc;
   DBUG_ENTER("plugin_lock");
+
+#ifdef DBUG_OFF
+  /*
+    In optimized builds we don't do reference counting for built-in
+    (plugin->plugin_dl == 0) plugins.
+
+    Note that we access plugin->plugin_dl outside of LOCK_plugin, and for
+    dynamic plugins a 'plugin' could correspond to plugin that was unloaded
+    meanwhile!  But because st_plugin_int is always allocated on
+    plugin_mem_root, the pointer can never be invalid - the memory is never
+    freed.
+    Of course, the memory that 'plugin' points to can be overwritten by
+    another plugin being loaded, but plugin->plugin_dl can never change
+    from zero to non-zero or vice versa.
+    That is, it's always safe to check for plugin->plugin_dl==0 even
+    without a mutex.
+  */
+  if (! plugin_dlib(ptr))
+    DBUG_RETURN(ptr);
+#endif
   pthread_mutex_lock(&LOCK_plugin);
-  rc= my_intern_plugin_lock_ci(lex, *ptr);
+  rc= my_intern_plugin_lock_ci(lex, ptr);
   pthread_mutex_unlock(&LOCK_plugin);
   DBUG_RETURN(rc);
 }

=== modified file 'sql/sql_plugin.h'
--- a/sql/sql_plugin.h	2009-05-14 12:03:33 +0000
+++ b/sql/sql_plugin.h	2010-03-08 13:57:32 +0000
@@ -89,6 +89,8 @@ struct st_plugin_int
 */
 #ifdef DBUG_OFF
 typedef struct st_plugin_int *plugin_ref;
+#define plugin_ref_to_int(A) A
+#define plugin_int_to_ref(A) A
 #define plugin_decl(pi) ((pi)->plugin)
 #define plugin_dlib(pi) ((pi)->plugin_dl)
 #define plugin_data(pi,cast) ((cast)((pi)->data))
@@ -97,6 +99,8 @@ typedef struct st_plugin_int *plugin_ref
 #define plugin_equals(p1,p2) ((p1) == (p2))
 #else
 typedef struct st_plugin_int **plugin_ref;
+#define plugin_ref_to_int(A) (A ? A[0] : NULL)
+#define plugin_int_to_ref(A) &(A)
 #define plugin_decl(pi) ((pi)[0]->plugin)
 #define plugin_dlib(pi) ((pi)[0]->plugin_dl)
 #define plugin_data(pi,cast) ((cast)((pi)[0]->data))
@@ -120,7 +124,7 @@ extern bool plugin_is_ready(const LEX_ST
 #define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C ORIG_CALLER_INFO)
 #define my_plugin_lock(A,B) plugin_lock(A,B CALLER_INFO)
 #define my_plugin_lock_ci(A,B) plugin_lock(A,B ORIG_CALLER_INFO)
-extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO);
+extern plugin_ref plugin_lock(THD *thd, plugin_ref ptr CALLER_INFO_PROTO);
 extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name,
                                       int type CALLER_INFO_PROTO);
 extern void plugin_unlock(THD *thd, plugin_ref plugin);

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-03-04 08:03:07 +0000
+++ b/sql/sql_select.cc	2010-03-09 19:23:30 +0000
@@ -2581,6 +2581,7 @@ make_join_statistics(JOIN *join, TABLE_L
   JOIN_TAB *stat,*stat_end,*s,**stat_ref;
   KEYUSE *keyuse,*start_keyuse;
   table_map outer_join=0;
+  table_map no_rows_const_tables= 0;
   SARGABLE_PARAM *sargables= 0;
   JOIN_TAB *stat_vector[MAX_TABLES+1];
   DBUG_ENTER("make_join_statistics");
@@ -2641,6 +2642,7 @@ make_join_statistics(JOIN *join, TABLE_L
 #endif
       {						// Empty table
         s->dependent= 0;                        // Ignore LEFT JOIN depend.
+        no_rows_const_tables |= table->map;
 	set_position(join,const_count++,s,(KEYUSE*) 0);
 	continue;
       }
@@ -2677,6 +2679,7 @@ make_join_statistics(JOIN *join, TABLE_L
         !table->fulltext_searched && !join->no_const_tables)
     {
       set_position(join,const_count++,s,(KEYUSE*) 0);
+      no_rows_const_tables |= table->map;
     }
   }
   stat_vector[i]=0;
@@ -2722,9 +2725,10 @@ make_join_statistics(JOIN *join, TABLE_L
                             ~outer_join, join->select_lex, &sargables))
       goto error;
 
-  join->const_table_map= 0;
+  join->const_table_map= no_rows_const_tables;
   join->const_tables= const_count;
   eliminate_tables(join);
+  join->const_table_map &= ~no_rows_const_tables;
   const_count= join->const_tables;
   found_const_table_map= join->const_table_map;
 
@@ -11043,7 +11047,7 @@ create_internal_tmp_table_from_heap2(THD
   delete table->file;
   table->file=0;
   plugin_unlock(0, table->s->db_plugin);
-  share.db_plugin= my_plugin_lock(0, &share.db_plugin);
+  share.db_plugin= my_plugin_lock(0, share.db_plugin);
   new_table.s= table->s;                       // Keep old share
   *table= new_table;
   *table->s= share;

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2010-03-09 15:03:54 +0000
+++ b/sql/table.cc	2010-03-09 19:23:30 +0000
@@ -896,7 +896,7 @@ static int open_binary_frm(THD *thd, TAB
           replacing it with a globally locked version of tmp_plugin
         */
         plugin_unlock(NULL, share->db_plugin);
-        share->db_plugin= my_plugin_lock(NULL, &tmp_plugin);
+        share->db_plugin= my_plugin_lock(NULL, tmp_plugin);
         DBUG_PRINT("info", ("setting dbtype to '%.*s' (%d)",
                             str_db_type_length, next_chunk + 2,
                             ha_legacy_type(share->db_type())));