List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:May 6 2011 11:53am
Subject:bzr push into mysql-5.5 branch (alexander.nozdrin:3495 to 3497) Bug#11848763
View as plain text  
 3497 Alexander Nozdrin	2011-05-06
      Patch for Bug#11848763 / 60025
      (SUBSTRING inside a stored function works too slow).
      
      The user-visible problem was that the server started to consume memory if a
      stored-routine of some sort is executed subsequently. The memory was freed
      only after the corresponding connection was closed.
      
      Technically, the problem was that the memory needed for temporary string
      conversions was allocated on the connection ("persistent") memory root,
      instead of statement one.
      
      The root cause of this problem was the incorrect patch for Bug 55744.
      That patch wrongly fixed a crash in prepared-statement-mode introduced by
      another patch. The patch for Bug 55744 used wrong condition to check if
      prepared statement mode is active (or whether the connection-scoped or
      statement-scoped memory root should be used). The thing is that for
      prepared statements such conversions should be done in the connection
      memory root, so that that the transformations of item-tree were correctly
      remembered in the PREPARE-phase.
      
      The fix is to use proper condition to detect prepared-statement-mode and
      use proper memory root.

    modified:
      sql/item.cc
 3496 Alexander Nozdrin	2011-05-06
      Preliminary patch for Bug#11848763 / 60025
      (SUBSTRING inside a stored function works too slow).
      
      Background:
        - THD classes derives from Query_arena, thus inherits the 'state'
          attribute and related operations (is_stmt_prepare() & co).
      
        - Although these operations are available in THD, they must not
          be used. THD has its own attribute to point to the active
          Query_arena -- stmt_arena.
      
        - So, instead of using thd->is_stmt_prepare(),
          thd->stmt_arena->is_stmt_prepare() must be used. This was the root
          cause of Bug 60025.
      
      This patch enforces the proper way of calling those operations.
      is_stmt_prepare() & co are declared as private operations
      in THD (thus, they are hidden from being called on THD instance).
      
      The patch tries to minimize changes in 5.5.

    modified:
      sql/item.cc
      sql/item_cmpfunc.cc
      sql/item_func.cc
      sql/item_row.cc
      sql/item_strfunc.cc
      sql/sql_class.h
 3495 Magnus Blåudd	2011-05-06
      Add --with-debug=full support to BUILD/* scripts, this option has been lost
      between 5.1 and 5.5, it's purpose is to set the compiler flags in a way that
      does not optimize away the call stack(i.e don't use any -OX flags at all)

    modified:
      BUILD/SETUP.sh
=== modified file 'sql/item.cc'
--- a/sql/item.cc	2011-04-08 13:15:23 +0000
+++ b/sql/item.cc	2011-05-06 11:41:24 +0000
@@ -581,7 +581,7 @@ void Item::rename(char *new_name)
 
 Item* Item::transform(Item_transformer transformer, uchar *arg)
 {
-  DBUG_ASSERT(!current_thd->is_stmt_prepare());
+  DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
 
   return (this->*transformer)(arg);
 }
@@ -1781,14 +1781,17 @@ bool agg_item_set_converter(DTCollation
   }
 
   THD *thd= current_thd;
-  Query_arena *arena, backup;
   bool res= FALSE;
   uint i;
+
   /*
     In case we're in statement prepare, create conversion item
     in its memory: it will be reused on each execute.
   */
-  arena= thd->activate_stmt_arena_if_needed(&backup);
+  Query_arena backup;
+  Query_arena *arena= thd->stmt_arena->is_stmt_prepare() ?
+                      thd->activate_stmt_arena_if_needed(&backup) :
+                      NULL;
 
   for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
   {
@@ -1845,7 +1848,7 @@ bool agg_item_set_converter(DTCollation
       been created in prepare. In this case register the change for
       rollback.
     */
-    if (thd->is_stmt_prepare())
+    if (thd->stmt_arena->is_stmt_prepare())
       *arg= conv;
     else
       thd->change_item_tree(arg, conv);
@@ -6965,7 +6968,7 @@ int Item_default_value::save_in_field(Fi
 
 Item *Item_default_value::transform(Item_transformer transformer, uchar *args)
 {
-  DBUG_ASSERT(!current_thd->is_stmt_prepare());
+  DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
 
   /*
     If the value of arg is NULL, then this object represents a constant,

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2011-05-06 08:27:04 +0000
+++ b/sql/item_cmpfunc.cc	2011-05-06 11:39:40 +0000
@@ -4345,7 +4345,7 @@ bool Item_cond::walk(Item_processor proc
 
 Item *Item_cond::transform(Item_transformer transformer, uchar *arg)
 {
-  DBUG_ASSERT(!current_thd->is_stmt_prepare());
+  DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
 
   List_iterator<Item> li(list);
   Item *item;
@@ -5718,7 +5718,7 @@ bool Item_equal::walk(Item_processor pro
 
 Item *Item_equal::transform(Item_transformer transformer, uchar *arg)
 {
-  DBUG_ASSERT(!current_thd->is_stmt_prepare());
+  DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
 
   List_iterator<Item_field> it(fields);
   Item *item;

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2011-05-06 08:27:04 +0000
+++ b/sql/item_func.cc	2011-05-06 11:39:40 +0000
@@ -293,7 +293,7 @@ void Item_func::traverse_cond(Cond_trave
 
 Item *Item_func::transform(Item_transformer transformer, uchar *argument)
 {
-  DBUG_ASSERT(!current_thd->is_stmt_prepare());
+  DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
 
   if (arg_count)
   {

=== modified file 'sql/item_row.cc'
--- a/sql/item_row.cc	2011-03-08 17:39:25 +0000
+++ b/sql/item_row.cc	2011-05-06 11:39:40 +0000
@@ -170,7 +170,7 @@ bool Item_row::walk(Item_processor proce
 
 Item *Item_row::transform(Item_transformer transformer, uchar *arg)
 {
-  DBUG_ASSERT(!current_thd->is_stmt_prepare());
+  DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
 
   for (uint i= 0; i < arg_count; i++)
   {

=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc	2011-04-08 13:15:23 +0000
+++ b/sql/item_strfunc.cc	2011-05-06 11:39:40 +0000
@@ -2536,7 +2536,7 @@ String *Item_func_make_set::val_str(Stri
 
 Item *Item_func_make_set::transform(Item_transformer transformer, uchar *arg)
 {
-  DBUG_ASSERT(!current_thd->is_stmt_prepare());
+  DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
 
   Item *new_item= item->transform(transformer, arg);
   if (!new_item)

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2011-04-15 12:02:22 +0000
+++ b/sql/sql_class.h	2011-05-06 11:39:40 +0000
@@ -655,15 +655,10 @@ public:
   virtual ~Query_arena() {};
 
   inline bool is_stmt_prepare() const { return state == INITIALIZED; }
-  inline bool is_first_sp_execute() const
-  { return state == INITIALIZED_FOR_SP; }
   inline bool is_stmt_prepare_or_first_sp_execute() const
   { return (int)state < (int)PREPARED; }
   inline bool is_stmt_prepare_or_first_stmt_execute() const
   { return (int)state <= (int)PREPARED; }
-  inline bool is_first_stmt_execute() const { return state == PREPARED; }
-  inline bool is_stmt_execute() const
-  { return state == PREPARED || state == EXECUTED; }
   inline bool is_conventional() const
   { return state == CONVENTIONAL_EXECUTION; }
 
@@ -1434,6 +1429,19 @@ extern "C" void my_message_sql(uint erro
 class THD :public Statement,
            public Open_tables_state
 {
+private:
+  inline bool is_stmt_prepare() const
+  { DBUG_ASSERT(0); return Statement::is_stmt_prepare(); }
+
+  inline bool is_stmt_prepare_or_first_sp_execute() const
+  { DBUG_ASSERT(0); return Statement::is_stmt_prepare_or_first_sp_execute(); }
+
+  inline bool is_stmt_prepare_or_first_stmt_execute() const
+  { DBUG_ASSERT(0); return Statement::is_stmt_prepare_or_first_stmt_execute(); }
+
+  inline bool is_conventional() const
+  { DBUG_ASSERT(0); return Statement::is_conventional(); }
+
 public:
   MDL_context mdl_context;
 

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5 branch (alexander.nozdrin:3495 to 3497) Bug#11848763Alexander Nozdrin6 May