List:Commits« Previous MessageNext Message »
From:Guilhem Bichot Date:May 13 2011 9:10am
Subject:[Resend] bzr commit into mysql-trunk branch (guilhem.bichot:3304)
Bug#12546331
View as plain text  
[This commit e-mail is a repeat.]

#At file:///home/mysql_src/bzrrepos_new/mysql-next-mr-opt-backporting-wl4800/ based on
revid:guilhem.bichot@stripped

 3304 Guilhem Bichot	2011-05-13
      Fix for Bug#12546331 - SEGFAULT IN SUBSELECT_INDEXSUBQUERY_ENGINE::PRINT WITH
OPTIMIZER TRACE
      Need to prevent JOIN free-ing too early as we need it when printing
      the expanded query.
      Note that there are, other places of code, some similar ad-hoc logic
      "if this is EXPLAIN then do/don't do this to <data structure>".
      I am not changing yet those other places to
      "if this is EXPLAIN or opt trace is enabled then do/don't do this to <data
structure>",
      until proven to cause a bug; because I would like optimizer trace to affect the
query as
      least as possible.
     @ sql/sql_base.cc
        In the existing code, in EXPLAIN SELECT, we don't cleanup JOINs
        right after materializing derived tables, but only when the statement ends.
        We need to do the same in SELECT when optimizer trace is enabled.
        In the bug's scenario, the steps below happen in order:
        - derived tables are materialized (open_and_lock_tables() ->
mysql_handle_derived())
        - at the end of this materialization, JOIN::destroy() is called
        (by mysql_derived_cleanup()); this makes subquery engines have
        no table (their tab->table becomes NULL)
        - JOIN::prepare() is called, which calls opt_trace_print_expanded_query(),
        which calls subselect_indexsubquery_engine::print() which does
        str->append(tab->table->s->table_name.str,
tab->table->s->table_name.length);
        and crashes (tab->table == NULL).
        With this fix, JOIN::destroy() happens later, as in EXPLAIN.
     @ sql/sql_select.cc
        fix for compiler warning: "thd" is not needed.

    modified:
      mysql-test/include/optimizer_trace2.inc
      mysql-test/r/optimizer_trace2_no_prot.result
      mysql-test/r/optimizer_trace2_ps_prot.result
      sql/sql_base.cc
      sql/sql_select.cc
=== modified file 'mysql-test/include/optimizer_trace2.inc'
--- a/mysql-test/include/optimizer_trace2.inc	2011-05-04 20:53:28 +0000
+++ b/mysql-test/include/optimizer_trace2.inc	2011-05-13 09:09:34 +0000
@@ -288,3 +288,82 @@ insert into t1 values (''), ('');
 select concat(concat(_latin1'->',f1),_latin1'<-') from t1;
 select * from information_schema.optimizer_trace;
 drop table t1;
+
+--echo
+--echo # Bug#12546331 - SEGFAULT IN SUBSELECT_INDEXSUBQUERY_ENGINE::PRINT WITH OPTIMIZER
TRACE
+--echo
+
+CREATE TABLE t1 (  
+  col_int_nokey INT,  
+  col_int_key INT,  
+  col_varchar_key varchar(1),
+  KEY col_int_key (col_int_key),
+  KEY col_varchar_key (col_varchar_key,col_int_key)
+);
+
+INSERT INTO t1 VALUES
+  (NULL,8,'x'),
+  (8,7,'d'),
+  (1,1,'r'),
+  (9,7,'f'),
+  (4,9,'y'),
+  (3,NULL,'u'),
+  (2,1,'m'),
+  (NULL,9,NULL),
+  (2,2,'o'),
+  (NULL,9,'w'),
+  (6,2,'m'),
+  (7,4,'q'),
+  (2,0,NULL),
+  (5,4,'d'),
+  (7,8,'g'),
+  (6,NULL,'x'),
+  (6,NULL,'f'),
+  (2,0,'p'),
+  (9,NULL,'j'),
+  (6,8,'c')
+;
+
+CREATE TABLE t2 (
+  col_int_nokey INT,
+  col_int_key INT,
+  col_varchar_key varchar(1),
+  KEY col_int_key (col_int_key),
+  KEY col_varchar_key (col_varchar_key,col_int_key)
+);
+
+INSERT INTO t2 VALUES
+  (2,4,'v'),
+  (150,62,'v'),
+  (NULL,7,'c'),
+  (2,1,NULL),
+  (5,0,'x'),
+  (3,7,'i'),
+  (1,7,'e'),
+  (4,1,'p'),
+  (NULL,7,'s'),
+  (2,1,'j'),
+  (6,5,'z'),
+  (6,2,'c'),
+  (8,0,'a'),
+  (2,1,'q'),
+  (6,8,'y'),
+  (8,1,NULL),
+  (3,1,'r'),
+  (3,9,'v'),
+  (9,1,NULL),
+  (6,5,'r')
+;
+
+SELECT col_int_nokey
+FROM (
+  SELECT *
+  FROM t2
+  WHERE col_varchar_key > 'a'
+    OR ( 7 , 5 ) NOT IN (
+      SELECT col_int_nokey , col_int_key
+      FROM t1 )
+  ) AS alias1;
+
+DROP TABLE t1;
+DROP TABLE t2;

=== modified file 'mysql-test/r/optimizer_trace2_no_prot.result'
--- a/mysql-test/r/optimizer_trace2_no_prot.result	2011-05-04 20:53:28 +0000
+++ b/mysql-test/r/optimizer_trace2_no_prot.result	2011-05-13 09:09:34 +0000
@@ -1913,3 +1913,96 @@ select concat(concat(_latin1'->',f1),_la
   ] /* steps */
 }	0	0
 drop table t1;
+
+# Bug#12546331 - SEGFAULT IN SUBSELECT_INDEXSUBQUERY_ENGINE::PRINT WITH OPTIMIZER TRACE
+
+CREATE TABLE t1 (  
+col_int_nokey INT,  
+col_int_key INT,  
+col_varchar_key varchar(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key,col_int_key)
+);
+INSERT INTO t1 VALUES
+(NULL,8,'x'),
+(8,7,'d'),
+(1,1,'r'),
+(9,7,'f'),
+(4,9,'y'),
+(3,NULL,'u'),
+(2,1,'m'),
+(NULL,9,NULL),
+(2,2,'o'),
+(NULL,9,'w'),
+(6,2,'m'),
+(7,4,'q'),
+(2,0,NULL),
+(5,4,'d'),
+(7,8,'g'),
+(6,NULL,'x'),
+(6,NULL,'f'),
+(2,0,'p'),
+(9,NULL,'j'),
+(6,8,'c')
+;
+CREATE TABLE t2 (
+col_int_nokey INT,
+col_int_key INT,
+col_varchar_key varchar(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key,col_int_key)
+);
+INSERT INTO t2 VALUES
+(2,4,'v'),
+(150,62,'v'),
+(NULL,7,'c'),
+(2,1,NULL),
+(5,0,'x'),
+(3,7,'i'),
+(1,7,'e'),
+(4,1,'p'),
+(NULL,7,'s'),
+(2,1,'j'),
+(6,5,'z'),
+(6,2,'c'),
+(8,0,'a'),
+(2,1,'q'),
+(6,8,'y'),
+(8,1,NULL),
+(3,1,'r'),
+(3,9,'v'),
+(9,1,NULL),
+(6,5,'r')
+;
+SELECT col_int_nokey
+FROM (
+SELECT *
+FROM t2
+WHERE col_varchar_key > 'a'
+    OR ( 7 , 5 ) NOT IN (
+SELECT col_int_nokey , col_int_key
+FROM t1 )
+) AS alias1;
+col_int_nokey
+2
+150
+NULL
+2
+5
+3
+1
+4
+NULL
+2
+6
+6
+8
+2
+6
+8
+3
+3
+9
+6
+DROP TABLE t1;
+DROP TABLE t2;

=== modified file 'mysql-test/r/optimizer_trace2_ps_prot.result'
--- a/mysql-test/r/optimizer_trace2_ps_prot.result	2011-05-04 20:53:28 +0000
+++ b/mysql-test/r/optimizer_trace2_ps_prot.result	2011-05-13 09:09:34 +0000
@@ -1933,3 +1933,96 @@ select concat(concat(_latin1'->',f1),_la
   ] /* steps */
 }	0	0
 drop table t1;
+
+# Bug#12546331 - SEGFAULT IN SUBSELECT_INDEXSUBQUERY_ENGINE::PRINT WITH OPTIMIZER TRACE
+
+CREATE TABLE t1 (  
+col_int_nokey INT,  
+col_int_key INT,  
+col_varchar_key varchar(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key,col_int_key)
+);
+INSERT INTO t1 VALUES
+(NULL,8,'x'),
+(8,7,'d'),
+(1,1,'r'),
+(9,7,'f'),
+(4,9,'y'),
+(3,NULL,'u'),
+(2,1,'m'),
+(NULL,9,NULL),
+(2,2,'o'),
+(NULL,9,'w'),
+(6,2,'m'),
+(7,4,'q'),
+(2,0,NULL),
+(5,4,'d'),
+(7,8,'g'),
+(6,NULL,'x'),
+(6,NULL,'f'),
+(2,0,'p'),
+(9,NULL,'j'),
+(6,8,'c')
+;
+CREATE TABLE t2 (
+col_int_nokey INT,
+col_int_key INT,
+col_varchar_key varchar(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key,col_int_key)
+);
+INSERT INTO t2 VALUES
+(2,4,'v'),
+(150,62,'v'),
+(NULL,7,'c'),
+(2,1,NULL),
+(5,0,'x'),
+(3,7,'i'),
+(1,7,'e'),
+(4,1,'p'),
+(NULL,7,'s'),
+(2,1,'j'),
+(6,5,'z'),
+(6,2,'c'),
+(8,0,'a'),
+(2,1,'q'),
+(6,8,'y'),
+(8,1,NULL),
+(3,1,'r'),
+(3,9,'v'),
+(9,1,NULL),
+(6,5,'r')
+;
+SELECT col_int_nokey
+FROM (
+SELECT *
+FROM t2
+WHERE col_varchar_key > 'a'
+    OR ( 7 , 5 ) NOT IN (
+SELECT col_int_nokey , col_int_key
+FROM t1 )
+) AS alias1;
+col_int_nokey
+2
+150
+NULL
+2
+5
+3
+1
+4
+NULL
+2
+6
+6
+8
+2
+6
+8
+3
+3
+9
+6
+DROP TABLE t1;
+DROP TABLE t2;

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2011-05-06 12:58:06 +0000
+++ b/sql/sql_base.cc	2011-05-13 09:09:34 +0000
@@ -5496,7 +5496,15 @@ bool open_and_lock_tables(THD *thd, TABL
       mysql_handle_derived(thd->lex, &mysql_derived_cleanup);
       goto err;
     }
-    if (!thd->lex->describe)
+    if (!(thd->lex->describe
+#ifdef OPTIMIZER_TRACE
+          /*
+            Printing the expanded query in optimizer trace requires
+            non-destroyed JOINs for subquery engines.
+          */
+          || thd->opt_trace.support_I_S()
+#endif
+          ))
       mysql_handle_derived(thd->lex, &mysql_derived_cleanup);
   }
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-05-06 12:58:06 +0000
+++ b/sql/sql_select.cc	2011-05-13 09:09:34 +0000
@@ -14345,7 +14345,6 @@ void Optimize_table_order::advance_sj_st
                       double *current_record_count, double *current_read_time, 
                       POSITION *loose_scan_pos)
 {
-  THD * const thd= join->thd;
   Opt_trace_context * const trace= &thd->opt_trace;
   TABLE_LIST *const emb_sj_nest= new_join_tab->emb_sj_nest;
   POSITION   *const pos= join->positions + idx;


Attachment: [text/bzr-bundle] bzr/guilhem.bichot@oracle.com-20110513090934-rcd7n1vmm3hwazh1.bundle
Thread
[Resend] bzr commit into mysql-trunk branch (guilhem.bichot:3304)Bug#12546331Guilhem Bichot13 May