List:Commits« Previous MessageNext Message »
From:marc.alff Date:November 15 2007 12:14am
Subject:bk commit into 5.1 tree (malff:1.2610) BUG#27011
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of malff. When malff 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, 2007-11-14 17:14:40-07:00, malff@stripped. +7 -0
  Bug#27011 (Problem with prepared statement in iterations)
  
  NOT TO PUSH -- Debugging code to help investigation only, not a fix.
  
  This patch provide some very raw and brute force print utility,
  that was used to print the LEX structure during statement execution,
  in execute_command().
  
  Provided as-is to help developers to investigate, not a finished utility.

  configure.in@stripped, 2007-11-14 17:14:30-07:00, malff@stripped. +15 -0
    NOT TO PUSH -- Debugging code to help investigation only, not a fix.

  mysql-test/t/marc_27011.test@stripped, 2007-11-14 17:14:31-07:00, malff@stripped. +47 -0
    NOT TO PUSH -- Debugging code to help investigation only, not a fix.
    

  mysql-test/t/marc_27011.test@stripped, 2007-11-14 17:14:31-07:00, malff@stripped. +0 -0

  sql/DEV_DEBUG.cc@stripped, 2007-11-14 17:14:30-07:00, malff@stripped. +388 -0
    NOT TO PUSH -- Debugging code to help investigation only, not a fix.
    

  sql/DEV_DEBUG.cc@stripped, 2007-11-14 17:14:30-07:00, malff@stripped. +0 -0

  sql/DEV_DEBUG.h@stripped, 2007-11-14 17:14:30-07:00, malff@stripped. +79 -0
    NOT TO PUSH -- Debugging code to help investigation only, not a fix.
    

  sql/DEV_DEBUG.h@stripped, 2007-11-14 17:14:30-07:00, malff@stripped. +0 -0

  sql/DEV_DEBUG_ENTRY.h@stripped, 2007-11-14 17:14:30-07:00, malff@stripped. +8 -0
    NOT TO PUSH -- Debugging code to help investigation only, not a fix.
    

  sql/DEV_DEBUG_ENTRY.h@stripped, 2007-11-14 17:14:30-07:00, malff@stripped. +0 -0

  sql/Makefile.am@stripped, 2007-11-14 17:14:30-07:00, malff@stripped. +4 -2
    NOT TO PUSH -- Debugging code to help investigation only, not a fix.

  sql/sql_parse.cc@stripped, 2007-11-14 17:14:30-07:00, malff@stripped. +11 -1
    NOT TO PUSH -- Debugging code to help investigation only, not a fix.

diff -Nrup a/configure.in b/configure.in
--- a/configure.in	2007-10-29 13:00:27 -06:00
+++ b/configure.in	2007-11-14 17:14:30 -07:00
@@ -1658,6 +1658,21 @@ then
   fi
 fi
 
+# If we should allow developer debug utilities
+AC_ARG_WITH(dev-debug,
+    AC_HELP_STRING([--with-dev-debug],[Enable developer debug utilities]),
+    [ with_dev_debug=$withval ],
+    [ with_dev_debug=no ])
+
+if test $with_debug != "no"
+then
+  if test "$with_dev_debug" = "yes"
+  then
+    AC_DEFINE([HAVE_DEV_DEBUG], [1],
+              [Enable developer debug utilities])
+  fi
+fi
+
 AC_ARG_WITH([fast-mutexes],
 	    AC_HELP_STRING([--with-fast-mutexes], 
 	    [Compile with fast mutexes (default is disabled)]),
diff -Nrup a/mysql-test/t/marc_27011.test b/mysql-test/t/marc_27011.test
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/mysql-test/t/marc_27011.test	2007-11-14 17:14:31 -07:00
@@ -0,0 +1,47 @@
+
+#
+# Bug#27011 (Problem with prepared statement in iterations)
+#
+
+--disable_warnings
+drop table if exists t_27011;
+drop view if exists v_27011;
+drop procedure if exists proc_27011;
+--enable_warnings
+
+create table t_27011(id int, name char(50));
+insert into t_27011 values
+  ((1), "Paris"),
+  ((2), "Denver"),
+  ((3), "Cupertino");
+
+DELIMITER |;
+
+CREATE PROCEDURE proc_27011()
+BEGIN
+  DECLARE item INT DEFAULT 1;
+  REPEAT
+    SET @stmt = CONCAT(
+      'CREATE VIEW v_27011 AS (SELECT * FROM t_27011 WHERE id = ',
+       item, ')');
+    SELECT @stmt;
+    PREPARE stmt1 FROM @stmt;
+    EXECUTE stmt1;
+    DEALLOCATE PREPARE stmt1;
+    SELECT * FROM v_27011;
+    DROP VIEW v_27011;
+    SET item = item + 1;
+  UNTIL item > 3
+  END REPEAT;
+END|
+
+DELIMITER ;|
+
+# Debugging helper, written to investigate
+SET SESSION debug="d,DEBUG_execute_command";
+
+call proc_27011();
+
+drop procedure proc_27011;
+
+
diff -Nrup a/sql/DEV_DEBUG.cc b/sql/DEV_DEBUG.cc
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/sql/DEV_DEBUG.cc	2007-11-14 17:14:30 -07:00
@@ -0,0 +1,388 @@
+
+#include "config.h"
+
+#ifdef HAVE_DEV_DEBUG
+
+#define private public
+#define protected public
+
+#include "mysql_priv.h"
+
+#undef private
+#undef protected
+
+#include "DEV_DEBUG.h"
+#include "DEV_DEBUG_ENTRY.h"
+
+// ============================================================================
+// DEBUG OUTPUT
+// ============================================================================
+
+void
+DEBUG_stdout_output::print(const char* line)
+{
+  fprintf(stdout, line);
+}
+
+DEBUG_file_output::DEBUG_file_output(const char* filename)
+{
+  m_file= fopen(filename, "a");
+}
+
+DEBUG_file_output::~DEBUG_file_output()
+{
+  fclose(m_file);
+}
+
+void
+DEBUG_file_output::print(const char* line)
+{
+  fprintf(m_file, line);
+}
+
+// ============================================================================
+// DEBUG FORMAT
+// ============================================================================
+
+void
+DEBUG_printer::start()
+{
+  m_tab= 0;
+  m_out->print("##################################################################\n");
+}
+
+void
+DEBUG_printer::end()
+{
+  m_out->print("##################################################################\n");
+}
+
+void
+DEBUG_printer::start_attr()
+{
+  m_tab++;
+}
+
+void
+DEBUG_printer::end_attr()
+{
+  m_tab--;
+}
+
+void
+DEBUG_printer::start_children()
+{
+  m_tab++;
+}
+
+void
+DEBUG_printer::end_children()
+{
+  m_tab--;
+}
+
+void
+DEBUG_printer::start_child(const char* class_name, const char* attr)
+{
+  print_tab();
+  m_out->print("- ");
+  m_out->print(class_name);
+  m_out->print("::");
+  m_out->print(attr);
+  m_out->print("\n");
+  m_tab++;
+}
+
+void
+DEBUG_printer::end_child()
+{
+  m_tab--;
+}
+
+void
+DEBUG_printer::print_tab()
+{
+  for (int i=0 ; i<m_tab; i++)
+    m_out->print("  ");
+}
+
+void
+DEBUG_printer::print_attr(const char* class_name, const char* attr)
+{
+  print_tab();
+  m_out->print("- ");
+  m_out->print(class_name);
+  m_out->print("::");
+  m_out->print(attr);
+  m_out->print(" = ");
+}
+
+void
+DEBUG_printer::print_null()
+{
+  print_tab();
+  m_out->print("NULL\n");
+}
+
+void
+DEBUG_printer::print_object(const char* class_name)
+{
+  print_tab();
+  m_out->print("OBJECT: ");
+  m_out->print(class_name);
+  m_out->print("\n");
+}
+
+void
+DEBUG_printer::print_attr_bool(const char* class_name, const char* attr, bool value)
+{
+  print_attr(class_name, attr);
+  m_out->print((value ? "TRUE" : "FALSE"));
+  m_out->print("\n");
+}
+
+void
+DEBUG_printer::print_attr_int(const char* class_name, const char* attr, int value)
+{
+  char buffer[20];
+  print_attr(class_name, attr);
+  sprintf(buffer, "%d", value);
+  m_out->print(buffer);
+  m_out->print("\n");
+}
+
+void
+DEBUG_printer::print_attr_string(const char* class_name, const char* attr, const char* value)
+{
+  print_attr(class_name, attr);
+  m_out->print(value);
+  m_out->print("\n");
+}
+
+// ============================================================================
+// APPLICATION OBJECTS
+// ============================================================================
+
+void
+DEBUG_printer::print_attr_sql_command(const char* class_name,
+                                      const char* attr,
+                                      enum_sql_command com)
+{
+  const char* text= NULL;
+  print_attr(class_name, attr);
+  switch(com)
+  {
+  case SQLCOM_SELECT:
+    text= "SQLCOM_SELECT";
+    break;
+  case SQLCOM_CALL:
+    text= "SQLCOM_CALL";
+    break;
+  case SQLCOM_SET_OPTION:
+    text= "SQLCOM_SET_OPTION";
+    break;
+  case SQLCOM_PREPARE:
+    text= "SQLCOM_PREPARE";
+    break;
+  case SQLCOM_EXECUTE:
+    text= "SQLCOM_EXECUTE";
+    break;
+  case SQLCOM_CREATE_VIEW:
+    text= "SQLCOM_CREATE_VIEW";
+    break;
+  case SQLCOM_DEALLOCATE_PREPARE:
+    text= "SQLCOM_DEALLOCATE_PREPARE";
+    break;
+  case SQLCOM_DROP_VIEW:
+    text= "SQLCOM_DROP_VIEW";
+    break;
+  case SQLCOM_DROP_PROCEDURE:
+    text= "SQLCOM_DROP_PROCEDURE";
+    break;
+  case SQLCOM_SHOW_WARNS:
+    text= "SQLCOM_SHOW_WARNS";
+    break;
+  default:
+    break;
+  }
+
+  if (text)
+  {
+    m_out->print(text);
+    m_out->print("\n");
+  }
+  else
+  {
+    char buffer[80];
+    sprintf(buffer, "TODO (value %d)\n", (int) com);
+    m_out->print(buffer);
+  }
+}
+
+void
+DEBUG_printer::print_attr_item_type(const char* class_name, const char* attr, Item::Type value)
+{
+  const char* text= NULL;
+  print_attr(class_name, attr);
+
+  switch(value)
+  {
+  case Item::FIELD_ITEM:
+    text= "FIELD_ITEM";
+    break;
+  case Item::FUNC_ITEM:
+    text= "FUNC_ITEM";
+    break;
+  default:
+    break;
+  }
+
+  if (text)
+  {
+    m_out->print(text);
+    m_out->print("\n");
+  }
+  else
+  {
+    char buffer[80];
+    sprintf(buffer, "TODO (value %d)\n", (int) value);
+    m_out->print(buffer);
+  }
+}
+
+void
+DEBUG_printer::print_THD(THD *thd)
+{
+  const char* class_name= "THD";
+
+  if (thd == NULL)
+  {
+    print_null();
+    return;
+  }
+
+  print_object(class_name);
+
+  start_attr();
+    print_attr_string(class_name, "query", thd->query);
+  end_attr();
+
+  start_children();
+  end_children();
+}
+void
+DEBUG_printer::print_LEX(LEX *lex)
+{
+  const char* class_name= "LEX";
+
+  if (lex == NULL)
+  {
+    print_null();
+    return;
+  }
+
+  print_object(class_name);
+  start_attr();
+    print_attr_sql_command(class_name, "sql_command", lex->sql_command);
+    switch(lex->sql_command)
+    {
+    case SQLCOM_SELECT:
+      print_attr_bool(class_name, "describe", lex->describe);
+      break;
+    default:
+      break;
+    }
+  end_attr();
+
+  start_children();
+    switch(lex->sql_command)
+    {
+    case SQLCOM_SELECT:
+      start_child(class_name, "select_lex");
+        print_SELECT_LEX(& lex->select_lex);
+      end_child();
+      break;
+    default:
+      break;
+    }
+  end_children();
+}
+
+void
+DEBUG_printer::print_SELECT_LEX(SELECT_LEX *select_lex)
+{
+  const char* class_name= "SELECT_LEX";
+  print_object(class_name);
+
+  start_attr();
+    print_attr_string(class_name, "db", select_lex->db);
+  end_attr();
+
+  start_children();
+    start_child(class_name, "where");
+      print_Item(select_lex->where);
+    end_child();
+  end_children();
+}
+
+void
+DEBUG_printer::print_Item(Item *item)
+{
+  const char* class_name= "Item";
+
+  if (item == NULL)
+  {
+    print_null();
+    return;
+  }
+
+  print_object(class_name);
+
+  start_attr();
+    print_attr_item_type(class_name, "type()", item->type());
+
+    String printed(500);
+    item->print(& printed);
+    printed.append('\0');
+    print_attr_string(class_name, "print()", printed.ptr());
+
+    print_attr_int(class_name, "rsize", item->rsize);
+    print_attr_string(class_name, "str_value", item->str_value.ptr());
+    print_attr_string(class_name, "name", item->name);
+    print_attr_string(class_name, "orig_name", item->orig_name);
+    print_attr_int(class_name, "max_length", item->max_length);
+    print_attr_int(class_name, "name_length", item->name_length);
+    print_attr_int(class_name, "marker", item->marker);
+    print_attr_int(class_name, "decimals", item->decimals);
+    print_attr_bool(class_name, "maybe_null", item->maybe_null);
+    print_attr_bool(class_name, "null_value", item->null_value);
+    print_attr_bool(class_name, "unsigned_flag", item->unsigned_flag);
+    print_attr_bool(class_name, "with_sum_func", item->with_sum_func);
+    print_attr_bool(class_name, "fixed", item->fixed);
+    print_attr_bool(class_name, "is_autogenerated_name", item->is_autogenerated_name);
+    print_attr_bool(class_name, "with_subselect", item->with_subselect);
+  end_attr();
+
+  start_children();
+  end_children();
+
+
+}
+
+// ============================================================================
+// ENTRY POINTS
+// ============================================================================
+
+void DEBUG_execute_command(LEX* lex)
+{
+  DEBUG_file_output out("/tmp/foo.log");
+  DEBUG_printer printer(& out);
+
+  printer.start();
+  printer.print_THD(lex->thd);
+  printer.print_LEX(lex);
+  printer.end();
+}
+
+#endif
+
diff -Nrup a/sql/DEV_DEBUG.h b/sql/DEV_DEBUG.h
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/sql/DEV_DEBUG.h	2007-11-14 17:14:30 -07:00
@@ -0,0 +1,79 @@
+
+#ifndef DEV_DEBUG_H
+#define DEV_DEBUG_H
+
+class DEBUG_output
+{
+public:
+  DEBUG_output() {}
+  virtual ~DEBUG_output() {}
+
+  virtual void print(const char* line) = 0 ;
+};
+
+class DEBUG_stdout_output : public DEBUG_output
+{
+public:
+  DEBUG_stdout_output() {}
+  virtual ~DEBUG_stdout_output() {}
+
+  virtual void print(const char* line);
+};
+
+class DEBUG_file_output : public DEBUG_output
+{
+public:
+  DEBUG_file_output(const char* filename);
+  virtual ~DEBUG_file_output();
+
+  virtual void print(const char* line);
+private:
+  FILE *m_file;
+};
+
+class DEBUG_printer
+{
+public:
+  DEBUG_printer(DEBUG_output *output)
+    : m_out(output), m_tab(0)
+  {}
+
+  ~DEBUG_printer() {}
+
+  void start();
+  void end();
+
+  void start_attr();
+  void end_attr();
+
+  void start_children();
+  void end_children();
+
+  void start_child(const char* class_name, const char* attr);
+  void end_child();
+
+  void print_null();
+  void print_object(const char* class_name);
+  void print_attr_bool(const char* class_name, const char* attr, bool value);
+  void print_attr_int(const char* class_name, const char* attr, int value);
+  void print_attr_string(const char* class_name, const char* attr, const char* value);
+  void print_attr_sql_command(const char* class_name, const char* attr, enum_sql_command com);
+  void print_attr_item_type(const char* class_name, const char* attr, Item::Type value);
+
+  void print_THD(THD* thd);
+  void print_LEX(LEX* lex);
+  void print_SELECT_LEX(SELECT_LEX* select_lex);
+  void print_Item(Item* item);
+
+private:
+  void print_tab();
+  void print_attr(const char* class_name, const char* attr);
+
+private:
+  DEBUG_output *m_out;
+  int m_tab;
+};
+
+
+#endif
+
diff -Nrup a/sql/DEV_DEBUG_ENTRY.h b/sql/DEV_DEBUG_ENTRY.h
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/sql/DEV_DEBUG_ENTRY.h	2007-11-14 17:14:30 -07:00
@@ -0,0 +1,8 @@
+
+#ifndef DEV_DEBUG_ENTRY_H
+#define DEV_DEBUG_ENTRY_H
+
+extern void DEBUG_execute_command(LEX* lex);
+
+#endif
+
diff -Nrup a/sql/Makefile.am b/sql/Makefile.am
--- a/sql/Makefile.am	2007-08-30 17:23:07 -06:00
+++ b/sql/Makefile.am	2007-11-14 17:14:30 -07:00
@@ -74,7 +74,8 @@ noinst_HEADERS =	item.h item_func.h item
 			sql_plugin.h authors.h \
 			event_data_objects.h event_scheduler.h \
 			sql_partition.h partition_info.h partition_element.h \
-			contributors.h sql_servers.h
+			contributors.h sql_servers.h \
+			DEV_DEBUG.h
 
 mysqld_SOURCES =	sql_lex.cc sql_handler.cc sql_partition.cc \
 			item.cc item_sum.cc item_buff.cc item_func.cc \
@@ -117,7 +118,8 @@ mysqld_SOURCES =	sql_lex.cc sql_handler.
                         event_queue.cc event_db_repository.cc events.cc \
 			sql_plugin.cc sql_binlog.cc \
 			sql_builtin.cc sql_tablespace.cc partition_info.cc \
-			sql_servers.cc
+			sql_servers.cc \
+			DEV_DEBUG.cc
 
 nodist_mysqld_SOURCES =	mini_client_errors.c pack.c client.c my_time.c my_user.c 
 
diff -Nrup a/sql/sql_parse.cc b/sql/sql_parse.cc
--- a/sql/sql_parse.cc	2007-11-01 16:48:11 -06:00
+++ b/sql/sql_parse.cc	2007-11-14 17:14:30 -07:00
@@ -28,6 +28,10 @@
 #include "events.h"
 #include "sql_trigger.h"
 
+#ifdef HAVE_DEV_DEBUG
+#include "DEV_DEBUG_ENTRY.h"
+#endif
+
 /**
   @defgroup Runtime_Environment Runtime Environment
   @{
@@ -1852,7 +1856,13 @@ mysql_execute_command(THD *thd)
   status_var_increment(thd->status_var.com_stat[lex->sql_command]);
 
   DBUG_ASSERT(thd->transaction.stmt.modified_non_trans_table == FALSE);
-  
+
+#ifdef HAVE_DEV_DEBUG
+  {
+    DBUG_EXECUTE_IF("DEBUG_execute_command", DEBUG_execute_command(lex); );
+  }
+#endif
+
   switch (lex->sql_command) {
   case SQLCOM_SHOW_EVENTS:
     if ((res= check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0,
Thread
bk commit into 5.1 tree (malff:1.2610) BUG#27011marc.alff15 Nov