← Back to team overview

maria-developers team mailing list archive

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

 

#At lp:maria

 2693 knielsen@xxxxxxxxxxxxxxx	2009-04-08
      Fix Valgrind errors seen in buildbot.
      
      Fix mysql-test-run.pl to not terminate early when warnings in error logs are detected during
      server shutdown. Instead, give a nice summary report at the end of the failures.
      
      Fix code to make 100% sure no failures will go undetected.
      
      Revert earlier wrong change.
      
      Fix race with port allocation semaphore file permissions.
      
      Adjust testsuite to copy with new PBXT engine now in the tree. The PBXT engine causes an
      extra table to appear in the INFORMATION_SCHEMA. This causes different output for a few
      test cases.
      added:
        mysql-test/include/have_pbxt.inc
        mysql-test/r/information_schema_all_engines.result
        mysql-test/t/information_schema_all_engines.test
      modified:
        dbug/dbug.c
        include/my_global.h
        mysql-test/extra/rpl_tests/rpl_auto_increment.test
        mysql-test/lib/mtr_report.pm
        mysql-test/lib/mtr_unique.pm
        mysql-test/mysql-test-run.pl
        mysql-test/r/information_schema.result
        mysql-test/r/information_schema_db.result
        mysql-test/r/innodb-autoinc.result
        mysql-test/r/mysqlshow.result
        mysql-test/suite/rpl/r/rpl_auto_increment.result
        mysql-test/t/information_schema.test
        mysql-test/t/information_schema_db.test
        mysql-test/t/innodb-autoinc.test
        mysql-test/t/mysqlshow.test
        mysql-test/valgrind.supp
        sql/mysqld.cc
        sql/set_var.cc
        sql/sql_select.cc
        sql/sql_string.h
        storage/archive/azio.c

per-file messages:
  dbug/dbug.c
    If DbugParse() is called multiple times, the stack->keywords for the
    top stack frame could be overwritten without being freed, causing a
    memory leak reported by Valgrind.
  include/my_global.h
    Add useful macro for different values when Valgrind (HAVE_purify) and not.
  mysql-test/extra/rpl_tests/rpl_auto_increment.test
    Omit pbxt variables from show variables output.
  mysql-test/include/have_pbxt.inc
    Add facility to disable test if PBXT engine is not available.
  mysql-test/lib/mtr_report.pm
    Give a nice summary report at the end of tests of any warnings seen in logs during
    server shutdowns.
  mysql-test/lib/mtr_unique.pm
    Move chmod 777 to greatly reduce the risk of leaving the port semaphore file unaccessible
    bu other users.
  mysql-test/mysql-test-run.pl
    Don't abort in case of warnings detected, instead give a nice summary report.
    
    Fix code to make 100% sure no failures will go undetected.
    
    Revert earlier wrong change when master disconnects early.
  mysql-test/r/information_schema.result
    Omit PBXT INFORMATION_SCHEMA table from output.
    Move part of test to information_schema_all_engines.
  mysql-test/r/information_schema_all_engines.result
    New file for information_schema tests that depend on which engines are available.
  mysql-test/r/information_schema_db.result
    Move part of test to information_schema_all_engines.
  mysql-test/r/innodb-autoinc.result
    Omit pbxt variables from show variables output.
  mysql-test/r/mysqlshow.result
    Move part of test to information_schema_all_engines.
  mysql-test/suite/rpl/r/rpl_auto_increment.result
    Omit pbxt variables from show variables output.
  mysql-test/t/information_schema.test
    Omit PBXT INFORMATION_SCHEMA table from output.
    Move part of test to information_schema_all_engines.
  mysql-test/t/information_schema_all_engines.test
    New file for information_schema tests that depend on which engines are available.
  mysql-test/t/information_schema_db.test
    Move part of test to information_schema_all_engines.
  mysql-test/t/innodb-autoinc.test
    Omit pbxt variables from show variables output.
  mysql-test/t/mysqlshow.test
    Move part of test to information_schema_all_engines.
  mysql-test/valgrind.supp
    Add variant suppression (different system library versions).
    Add suppression for problem with inet_ntoa().
  sql/mysqld.cc
    Fix missing DBUG_RETURN.
    Fix uninitialised thd->connect_utime, likely introduced by pool_of_threads.
  sql/set_var.cc
    Fix one-byte buffer overflow in several places.
    Fix unsafe use of String::c_ptr() of stack-allocated String buffer.
  sql/sql_select.cc
    Silence valgrind warning due to GCC bug.
  sql/sql_string.h
    Document potential problem with String::c_ptr() and String() constructor with caller-supplied buffer.
  storage/archive/azio.c
    Silence Valgrind false warning for libz.
=== modified file 'dbug/dbug.c'
--- a/dbug/dbug.c	2009-03-22 12:16:09 +0000
+++ b/dbug/dbug.c	2009-04-08 16:55:26 +0000
@@ -506,6 +506,9 @@ int DbugParse(CODE_STATE *cs, const char
   rel= control[0] == '+' || control[0] == '-';
   if ((!rel || (!stack->out_file && !stack->next)))
   {
+    /* If overwriting previous state, be sure to free old to avoid leak. */
+    if (stack->out_file)
+      FreeState(cs, stack, 0);
     stack->flags= 0;
     stack->delay= 0;
     stack->maxdepth= 0;
@@ -1648,10 +1651,12 @@ static void FreeState(CODE_STATE *cs, st
     FreeList(state->processes);
   if (!is_shared(state, p_functions))
     FreeList(state->p_functions);
-  if (!is_shared(state, out_file))
+  if (!is_shared(state, out_file) &&
+      state->out_file != stderr && state->out_file != stdout)
     DBUGCloseFile(cs, state->out_file);
   (void) fflush(cs->stack->out_file);
-  if (state->prof_file)
+  if (state->prof_file &&
+      state->prof_file != stderr && state->prof_file != stdout)
     DBUGCloseFile(cs, state->prof_file);
   if (free_state)
     free((void*) state);

=== modified file 'include/my_global.h'
--- a/include/my_global.h	2009-02-19 09:01:25 +0000
+++ b/include/my_global.h	2009-04-08 16:55:26 +0000
@@ -569,6 +569,12 @@ int	__void__;
 #define PURIFY_OR_LINT_INIT(var)
 #endif
 
+#ifdef HAVE_purify
+#define IF_PURIFY(A,B) (A)
+#else
+#define IF_PURIFY(A,B) (B)
+#endif
+
 #if !defined(HAVE_UINT)
 #undef HAVE_UINT
 #define HAVE_UINT

=== modified file 'mysql-test/extra/rpl_tests/rpl_auto_increment.test'
--- a/mysql-test/extra/rpl_tests/rpl_auto_increment.test	2009-01-14 08:27:32 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_auto_increment.test	2009-04-08 16:55:26 +0000
@@ -34,7 +34,7 @@ connection master;
 drop table t1;
 
 set @@session.auto_increment_increment=100, @@session.auto_increment_offset=10;
-show variables like "%auto_inc%";
+show variables like "auto_inc%";
 
 eval create table t1 (a int not null auto_increment, primary key (a)) engine=$engine_type2;
 # Insert with 2 insert statements to get better testing of logging

=== added file 'mysql-test/include/have_pbxt.inc'
--- a/mysql-test/include/have_pbxt.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/have_pbxt.inc	2009-04-08 16:55:26 +0000
@@ -0,0 +1,4 @@
+disable_query_log;
+--require r/true.require
+select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'pbxt';
+enable_query_log;

=== modified file 'mysql-test/lib/mtr_report.pm'
--- a/mysql-test/lib/mtr_report.pm	2009-02-19 09:01:25 +0000
+++ b/mysql-test/lib/mtr_report.pm	2009-04-08 16:55:26 +0000
@@ -187,8 +187,10 @@ sub mtr_report_test ($) {
 }
 
 
-sub mtr_report_stats ($) {
+sub mtr_report_stats ($$$) {
+  my $fail= shift;
   my $tests= shift;
+  my $extra_warnings= shift;
 
   # ----------------------------------------------------------------------
   # Find out how we where doing
@@ -325,10 +327,27 @@ sub mtr_report_stats ($) {
     print "All $tot_tests tests were successful.\n\n";
   }
 
+  if (@$extra_warnings)
+  {
+    print <<MSG;
+Errors/warnings were found in logfiles during server shutdown after running the
+following sequence(s) of tests:
+MSG
+    print "    $_\n" for @$extra_warnings;
+  }
+
   if ( $tot_failed != 0 || $found_problems)
   {
     mtr_error("there were failing test cases");
   }
+  elsif (@$extra_warnings)
+  {
+    mtr_error("There were errors/warnings in server logs after running test cases.");
+  }
+  elsif ($fail)
+  {
+    mtr_error("Test suite failure, see messages above for possible cause(s).");
+  }
 }
 
 

=== modified file 'mysql-test/lib/mtr_unique.pm'
--- a/mysql-test/lib/mtr_unique.pm	2009-02-19 09:01:25 +0000
+++ b/mysql-test/lib/mtr_unique.pm	2009-04-08 16:55:26 +0000
@@ -62,13 +62,14 @@ sub mtr_get_unique_id($$) {
     die 'lock file is a symbolic link';
   }
 
-  chmod 0777, "$file.sem";
   open SEM, ">", "$file.sem" or die "can't write to $file.sem";
+  chmod 0777, "$file.sem";
   flock SEM, LOCK_EX or die "can't lock $file.sem";
   if(! -e $file) {
     open FILE, ">", $file or die "can't create $file";
     close FILE;
   }
+  chmod 0777, $file;
 
   msg("HAVE THE LOCK");
 
@@ -76,7 +77,6 @@ sub mtr_get_unique_id($$) {
     die 'lock file is a symbolic link';
   }
 
-  chmod 0777, $file;
   open FILE, "+<", $file or die "can't open $file";
   #select undef,undef,undef,0.2;
   seek FILE, 0, 0;
@@ -136,6 +136,7 @@ sub mtr_release_unique_id($) {
   }
 
   open SEM, ">", "$file.sem" or die "can't write to $file.sem";
+  chmod 0777, "$file.sem";
   flock SEM, LOCK_EX or die "can't lock $file.sem";
 
   msg("HAVE THE LOCK");
@@ -148,6 +149,7 @@ sub mtr_release_unique_id($) {
     open FILE, ">", $file or die "can't create $file";
     close FILE;
   }
+  chmod 0777, "$file.sem";
   open FILE, "+<", $file or die "can't open $file";
   #select undef,undef,undef,0.2;
   seek FILE, 0, 0;

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2009-04-03 08:09:55 +0000
+++ b/mysql-test/mysql-test-run.pl	2009-04-08 16:55:26 +0000
@@ -357,7 +357,8 @@ sub main {
   mtr_print_thick_line();
   mtr_print_header();
 
-  my ($completed, $fail)= run_test_server($server, $tests, $opt_parallel);
+  my ($fail, $completed, $extra_warnings)=
+    run_test_server($server, $tests, $opt_parallel);
 
   # Send Ctrl-C to any children still running
   kill("INT", keys(%children));
@@ -393,10 +394,6 @@ sub main {
     mtr_error("Not all tests completed");
   }
 
-  if ($fail) {
-    mtr_error("Test suite failure.");
-  }
-
   mtr_print_line();
 
   if ( $opt_gcov ) {
@@ -404,7 +401,7 @@ sub main {
 		 $opt_gcov_msg, $opt_gcov_err);
   }
 
-  mtr_report_stats($completed);
+  mtr_report_stats($fail, $completed, $extra_warnings);
 
   exit(0);
 }
@@ -416,7 +413,8 @@ sub run_test_server ($$$) {
   my $num_saved_cores= 0;  # Number of core files saved in vardir/log/ so far.
   my $num_saved_datadir= 0;  # Number of datadirs saved in vardir/log/ so far.
   my $num_failed_test= 0; # Number of tests failed so far
-  my $test_failure= 0;
+  my $test_failure= 0;    # Set true if test suite failed
+  my $extra_warnings= []; # Warnings found during server shutdowns
 
   # Scheduler variables
   my $max_ndb= $childs / 2;
@@ -450,7 +448,7 @@ sub run_test_server ($$$) {
 	  $s->remove($sock);
 	  if (--$childs == 0){
 	    $suite_timeout_proc->kill();
-	    return ($completed, $test_failure);
+	    return ($test_failure, $completed, $extra_warnings);
 	  }
 	  next;
 	}
@@ -519,14 +517,14 @@ sub run_test_server ($$$) {
 	      # Test has failed, force is off
 	      $suite_timeout_proc->kill();
 	      push(@$completed, $result);
-	      return ($completed, 1);
+	      return (1, $completed, $extra_warnings);
 	    }
 	    elsif ($opt_max_test_fail > 0 and
 		   $num_failed_test >= $opt_max_test_fail) {
 	      $suite_timeout_proc->kill();
 	      mtr_report("Too many tests($num_failed_test) failed!",
 			 "Terminating...");
-	      return (undef, 1);
+	      return (1, $completed, $extra_warnings);
 	    }
 	    $num_failed_test++;
 	  }
@@ -580,13 +578,14 @@ sub run_test_server ($$$) {
 	elsif ($line eq 'WARNINGS'){
           my $fake_test= My::Test::read_test($sock);
           my $test_list= join (" ", @{$fake_test->{testnames}});
+          push @$extra_warnings, $test_list;
           mtr_report("***Warnings generated in error logs during shutdown ".
                      "after running tests: $test_list");
           $test_failure= 1;
           if ( !$opt_force ) {
             # Test failure due to warnings, force is off
             $suite_timeout_proc->kill();
-            return ($completed, 1);
+            return (1, $completed, $extra_warnings);
           }
         } else {
 	  mtr_error("Unknown response: '$line' from client");
@@ -666,7 +665,7 @@ sub run_test_server ($$$) {
     if ( ! $suite_timeout_proc->wait_one(0) )
     {
       mtr_report("Test suite timeout! Terminating...");
-      return (undef, 1);
+      return (1, $completed, $extra_warnings);
     }
   }
 }
@@ -758,7 +757,9 @@ sub run_worker ($) {
     }
   }
 
-  die "Internal error: should not reach this place.";
+  stop_all_servers();
+
+  exit(1);
 }
 
 

=== modified file 'mysql-test/r/information_schema.result'
--- a/mysql-test/r/information_schema.result	2009-02-15 10:58:34 +0000
+++ b/mysql-test/r/information_schema.result	2009-04-08 16:55:26 +0000
@@ -40,7 +40,8 @@ create view v1 (c) as
 SELECT table_name FROM information_schema.TABLES
 WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND
 table_name<>'ndb_binlog_index' AND
-table_name<>'ndb_apply_status';
+table_name<>'ndb_apply_status' AND
+NOT (table_schema = 'INFORMATION_SCHEMA' AND table_name LIKE 'PBXT_%');
 select * from v1;
 c
 CHARACTER_SETS
@@ -850,10 +851,6 @@ VIEWS	TABLE_NAME	select
 delete from mysql.user where user='mysqltest_4';
 delete from mysql.db where user='mysqltest_4';
 flush privileges;
-SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND table_name<>'ndb_binlog_index' AND table_name<>'ndb_apply_status' GROUP BY TABLE_SCHEMA;
-table_schema	count(*)
-information_schema	28
-mysql	22
 create table t1 (i int, j int);
 create trigger trg1 before insert on t1 for each row
 begin
@@ -1224,92 +1221,6 @@ f1()
 DROP FUNCTION f1;
 DROP PROCEDURE p1;
 DROP USER mysql_bug20230@localhost;
-SELECT t.table_name, c1.column_name
-FROM information_schema.tables t
-INNER JOIN
-information_schema.columns c1
-ON t.table_schema = c1.table_schema AND
-t.table_name = c1.table_name
-WHERE t.table_schema = 'information_schema' AND
-c1.ordinal_position =
-( SELECT COALESCE(MIN(c2.ordinal_position),1)
-FROM information_schema.columns c2
-WHERE c2.table_schema = t.table_schema AND
-c2.table_name = t.table_name AND
-c2.column_name LIKE '%SCHEMA%'
-        );
-table_name	column_name
-CHARACTER_SETS	CHARACTER_SET_NAME
-COLLATIONS	COLLATION_NAME
-COLLATION_CHARACTER_SET_APPLICABILITY	COLLATION_NAME
-COLUMNS	TABLE_SCHEMA
-COLUMN_PRIVILEGES	TABLE_SCHEMA
-ENGINES	ENGINE
-EVENTS	EVENT_SCHEMA
-FILES	TABLE_SCHEMA
-GLOBAL_STATUS	VARIABLE_NAME
-GLOBAL_VARIABLES	VARIABLE_NAME
-KEY_COLUMN_USAGE	CONSTRAINT_SCHEMA
-PARTITIONS	TABLE_SCHEMA
-PLUGINS	PLUGIN_NAME
-PROCESSLIST	ID
-PROFILING	QUERY_ID
-REFERENTIAL_CONSTRAINTS	CONSTRAINT_SCHEMA
-ROUTINES	ROUTINE_SCHEMA
-SCHEMATA	SCHEMA_NAME
-SCHEMA_PRIVILEGES	TABLE_SCHEMA
-SESSION_STATUS	VARIABLE_NAME
-SESSION_VARIABLES	VARIABLE_NAME
-STATISTICS	TABLE_SCHEMA
-TABLES	TABLE_SCHEMA
-TABLE_CONSTRAINTS	CONSTRAINT_SCHEMA
-TABLE_PRIVILEGES	TABLE_SCHEMA
-TRIGGERS	TRIGGER_SCHEMA
-USER_PRIVILEGES	GRANTEE
-VIEWS	TABLE_SCHEMA
-SELECT t.table_name, c1.column_name
-FROM information_schema.tables t
-INNER JOIN
-information_schema.columns c1
-ON t.table_schema = c1.table_schema AND
-t.table_name = c1.table_name
-WHERE t.table_schema = 'information_schema' AND
-c1.ordinal_position =
-( SELECT COALESCE(MIN(c2.ordinal_position),1)
-FROM information_schema.columns c2
-WHERE c2.table_schema = 'information_schema' AND
-c2.table_name = t.table_name AND
-c2.column_name LIKE '%SCHEMA%'
-        );
-table_name	column_name
-CHARACTER_SETS	CHARACTER_SET_NAME
-COLLATIONS	COLLATION_NAME
-COLLATION_CHARACTER_SET_APPLICABILITY	COLLATION_NAME
-COLUMNS	TABLE_SCHEMA
-COLUMN_PRIVILEGES	TABLE_SCHEMA
-ENGINES	ENGINE
-EVENTS	EVENT_SCHEMA
-FILES	TABLE_SCHEMA
-GLOBAL_STATUS	VARIABLE_NAME
-GLOBAL_VARIABLES	VARIABLE_NAME
-KEY_COLUMN_USAGE	CONSTRAINT_SCHEMA
-PARTITIONS	TABLE_SCHEMA
-PLUGINS	PLUGIN_NAME
-PROCESSLIST	ID
-PROFILING	QUERY_ID
-REFERENTIAL_CONSTRAINTS	CONSTRAINT_SCHEMA
-ROUTINES	ROUTINE_SCHEMA
-SCHEMATA	SCHEMA_NAME
-SCHEMA_PRIVILEGES	TABLE_SCHEMA
-SESSION_STATUS	VARIABLE_NAME
-SESSION_VARIABLES	VARIABLE_NAME
-STATISTICS	TABLE_SCHEMA
-TABLES	TABLE_SCHEMA
-TABLE_CONSTRAINTS	CONSTRAINT_SCHEMA
-TABLE_PRIVILEGES	TABLE_SCHEMA
-TRIGGERS	TRIGGER_SCHEMA
-USER_PRIVILEGES	GRANTEE
-VIEWS	TABLE_SCHEMA
 SELECT MAX(table_name) FROM information_schema.tables WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test');
 MAX(table_name)
 VIEWS
@@ -1355,55 +1266,6 @@ table_name
 t1
 t2
 drop table t1,t2;
-select 1 as f1 from information_schema.tables  where "CHARACTER_SETS"=
-(select cast(table_name as char)  from information_schema.tables
-order by table_name limit 1) limit 1;
-f1
-1
-select t.table_name, group_concat(t.table_schema, '.', t.table_name),
-count(*) as num1
-from information_schema.tables t
-inner join information_schema.columns c1
-on t.table_schema = c1.table_schema AND t.table_name = c1.table_name
-where t.table_schema = 'information_schema' and
-c1.ordinal_position =
-(select isnull(c2.column_type) -
-isnull(group_concat(c2.table_schema, '.', c2.table_name)) +
-count(*) as num
-from information_schema.columns c2 where
-c2.table_schema='information_schema' and
-(c2.column_type = 'varchar(7)' or c2.column_type = 'varchar(20)')
-group by c2.column_type order by num limit 1)
-group by t.table_name order by num1, t.table_name;
-table_name	group_concat(t.table_schema, '.', t.table_name)	num1
-CHARACTER_SETS	information_schema.CHARACTER_SETS	1
-COLLATIONS	information_schema.COLLATIONS	1
-COLLATION_CHARACTER_SET_APPLICABILITY	information_schema.COLLATION_CHARACTER_SET_APPLICABILITY	1
-COLUMNS	information_schema.COLUMNS	1
-COLUMN_PRIVILEGES	information_schema.COLUMN_PRIVILEGES	1
-ENGINES	information_schema.ENGINES	1
-EVENTS	information_schema.EVENTS	1
-FILES	information_schema.FILES	1
-GLOBAL_STATUS	information_schema.GLOBAL_STATUS	1
-GLOBAL_VARIABLES	information_schema.GLOBAL_VARIABLES	1
-KEY_COLUMN_USAGE	information_schema.KEY_COLUMN_USAGE	1
-PARTITIONS	information_schema.PARTITIONS	1
-PLUGINS	information_schema.PLUGINS	1
-PROCESSLIST	information_schema.PROCESSLIST	1
-PROFILING	information_schema.PROFILING	1
-REFERENTIAL_CONSTRAINTS	information_schema.REFERENTIAL_CONSTRAINTS	1
-ROUTINES	information_schema.ROUTINES	1
-SCHEMATA	information_schema.SCHEMATA	1
-SCHEMA_PRIVILEGES	information_schema.SCHEMA_PRIVILEGES	1
-SESSION_STATUS	information_schema.SESSION_STATUS	1
-SESSION_VARIABLES	information_schema.SESSION_VARIABLES	1
-STATISTICS	information_schema.STATISTICS	1
-TABLES	information_schema.TABLES	1
-TABLE_CONSTRAINTS	information_schema.TABLE_CONSTRAINTS	1
-TABLE_PRIVILEGES	information_schema.TABLE_PRIVILEGES	1
-TRIGGERS	information_schema.TRIGGERS	1
-USER_PRIVILEGES	information_schema.USER_PRIVILEGES	1
-VIEWS	information_schema.VIEWS	1
 create table t1(f1 int);
 create view v1 as select f1+1 as a from t1;
 create table t2 (f1 int, f2 int);

=== added file 'mysql-test/r/information_schema_all_engines.result'
--- a/mysql-test/r/information_schema_all_engines.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/information_schema_all_engines.result	2009-04-08 16:55:26 +0000
@@ -0,0 +1,248 @@
+use INFORMATION_SCHEMA;
+show tables;
+Tables_in_information_schema
+CHARACTER_SETS
+COLLATIONS
+COLLATION_CHARACTER_SET_APPLICABILITY
+COLUMNS
+COLUMN_PRIVILEGES
+ENGINES
+EVENTS
+FILES
+GLOBAL_STATUS
+GLOBAL_VARIABLES
+KEY_COLUMN_USAGE
+PARTITIONS
+PLUGINS
+PROCESSLIST
+PROFILING
+REFERENTIAL_CONSTRAINTS
+ROUTINES
+SCHEMATA
+SCHEMA_PRIVILEGES
+SESSION_STATUS
+SESSION_VARIABLES
+STATISTICS
+TABLES
+TABLE_CONSTRAINTS
+TABLE_PRIVILEGES
+TRIGGERS
+USER_PRIVILEGES
+VIEWS
+PBXT_STATISTICS
+SELECT t.table_name, c1.column_name
+FROM information_schema.tables t
+INNER JOIN
+information_schema.columns c1
+ON t.table_schema = c1.table_schema AND
+t.table_name = c1.table_name
+WHERE t.table_schema = 'information_schema' AND
+c1.ordinal_position =
+( SELECT COALESCE(MIN(c2.ordinal_position),1)
+FROM information_schema.columns c2
+WHERE c2.table_schema = t.table_schema AND
+c2.table_name = t.table_name AND
+c2.column_name LIKE '%SCHEMA%'
+        );
+table_name	column_name
+CHARACTER_SETS	CHARACTER_SET_NAME
+COLLATIONS	COLLATION_NAME
+COLLATION_CHARACTER_SET_APPLICABILITY	COLLATION_NAME
+COLUMNS	TABLE_SCHEMA
+COLUMN_PRIVILEGES	TABLE_SCHEMA
+ENGINES	ENGINE
+EVENTS	EVENT_SCHEMA
+FILES	TABLE_SCHEMA
+GLOBAL_STATUS	VARIABLE_NAME
+GLOBAL_VARIABLES	VARIABLE_NAME
+KEY_COLUMN_USAGE	CONSTRAINT_SCHEMA
+PARTITIONS	TABLE_SCHEMA
+PLUGINS	PLUGIN_NAME
+PROCESSLIST	ID
+PROFILING	QUERY_ID
+REFERENTIAL_CONSTRAINTS	CONSTRAINT_SCHEMA
+ROUTINES	ROUTINE_SCHEMA
+SCHEMATA	SCHEMA_NAME
+SCHEMA_PRIVILEGES	TABLE_SCHEMA
+SESSION_STATUS	VARIABLE_NAME
+SESSION_VARIABLES	VARIABLE_NAME
+STATISTICS	TABLE_SCHEMA
+TABLES	TABLE_SCHEMA
+TABLE_CONSTRAINTS	CONSTRAINT_SCHEMA
+TABLE_PRIVILEGES	TABLE_SCHEMA
+TRIGGERS	TRIGGER_SCHEMA
+USER_PRIVILEGES	GRANTEE
+VIEWS	TABLE_SCHEMA
+PBXT_STATISTICS	ID
+SELECT t.table_name, c1.column_name
+FROM information_schema.tables t
+INNER JOIN
+information_schema.columns c1
+ON t.table_schema = c1.table_schema AND
+t.table_name = c1.table_name
+WHERE t.table_schema = 'information_schema' AND
+c1.ordinal_position =
+( SELECT COALESCE(MIN(c2.ordinal_position),1)
+FROM information_schema.columns c2
+WHERE c2.table_schema = 'information_schema' AND
+c2.table_name = t.table_name AND
+c2.column_name LIKE '%SCHEMA%'
+        );
+table_name	column_name
+CHARACTER_SETS	CHARACTER_SET_NAME
+COLLATIONS	COLLATION_NAME
+COLLATION_CHARACTER_SET_APPLICABILITY	COLLATION_NAME
+COLUMNS	TABLE_SCHEMA
+COLUMN_PRIVILEGES	TABLE_SCHEMA
+ENGINES	ENGINE
+EVENTS	EVENT_SCHEMA
+FILES	TABLE_SCHEMA
+GLOBAL_STATUS	VARIABLE_NAME
+GLOBAL_VARIABLES	VARIABLE_NAME
+KEY_COLUMN_USAGE	CONSTRAINT_SCHEMA
+PARTITIONS	TABLE_SCHEMA
+PLUGINS	PLUGIN_NAME
+PROCESSLIST	ID
+PROFILING	QUERY_ID
+REFERENTIAL_CONSTRAINTS	CONSTRAINT_SCHEMA
+ROUTINES	ROUTINE_SCHEMA
+SCHEMATA	SCHEMA_NAME
+SCHEMA_PRIVILEGES	TABLE_SCHEMA
+SESSION_STATUS	VARIABLE_NAME
+SESSION_VARIABLES	VARIABLE_NAME
+STATISTICS	TABLE_SCHEMA
+TABLES	TABLE_SCHEMA
+TABLE_CONSTRAINTS	CONSTRAINT_SCHEMA
+TABLE_PRIVILEGES	TABLE_SCHEMA
+TRIGGERS	TRIGGER_SCHEMA
+USER_PRIVILEGES	GRANTEE
+VIEWS	TABLE_SCHEMA
+PBXT_STATISTICS	ID
+select 1 as f1 from information_schema.tables  where "CHARACTER_SETS"=
+(select cast(table_name as char)  from information_schema.tables
+order by table_name limit 1) limit 1;
+f1
+1
+select t.table_name, group_concat(t.table_schema, '.', t.table_name),
+count(*) as num1
+from information_schema.tables t
+inner join information_schema.columns c1
+on t.table_schema = c1.table_schema AND t.table_name = c1.table_name
+where t.table_schema = 'information_schema' and
+c1.ordinal_position =
+(select isnull(c2.column_type) -
+isnull(group_concat(c2.table_schema, '.', c2.table_name)) +
+count(*) as num
+from information_schema.columns c2 where
+c2.table_schema='information_schema' and
+(c2.column_type = 'varchar(7)' or c2.column_type = 'varchar(20)')
+group by c2.column_type order by num limit 1)
+group by t.table_name order by num1, t.table_name;
+table_name	group_concat(t.table_schema, '.', t.table_name)	num1
+CHARACTER_SETS	information_schema.CHARACTER_SETS	1
+COLLATIONS	information_schema.COLLATIONS	1
+COLLATION_CHARACTER_SET_APPLICABILITY	information_schema.COLLATION_CHARACTER_SET_APPLICABILITY	1
+COLUMNS	information_schema.COLUMNS	1
+COLUMN_PRIVILEGES	information_schema.COLUMN_PRIVILEGES	1
+ENGINES	information_schema.ENGINES	1
+EVENTS	information_schema.EVENTS	1
+FILES	information_schema.FILES	1
+GLOBAL_STATUS	information_schema.GLOBAL_STATUS	1
+GLOBAL_VARIABLES	information_schema.GLOBAL_VARIABLES	1
+KEY_COLUMN_USAGE	information_schema.KEY_COLUMN_USAGE	1
+PARTITIONS	information_schema.PARTITIONS	1
+PBXT_STATISTICS	information_schema.PBXT_STATISTICS	1
+PLUGINS	information_schema.PLUGINS	1
+PROCESSLIST	information_schema.PROCESSLIST	1
+PROFILING	information_schema.PROFILING	1
+REFERENTIAL_CONSTRAINTS	information_schema.REFERENTIAL_CONSTRAINTS	1
+ROUTINES	information_schema.ROUTINES	1
+SCHEMATA	information_schema.SCHEMATA	1
+SCHEMA_PRIVILEGES	information_schema.SCHEMA_PRIVILEGES	1
+SESSION_STATUS	information_schema.SESSION_STATUS	1
+SESSION_VARIABLES	information_schema.SESSION_VARIABLES	1
+STATISTICS	information_schema.STATISTICS	1
+TABLES	information_schema.TABLES	1
+TABLE_CONSTRAINTS	information_schema.TABLE_CONSTRAINTS	1
+TABLE_PRIVILEGES	information_schema.TABLE_PRIVILEGES	1
+TRIGGERS	information_schema.TRIGGERS	1
+USER_PRIVILEGES	information_schema.USER_PRIVILEGES	1
+VIEWS	information_schema.VIEWS	1
+Database: information_schema
++---------------------------------------+
+|                Tables                 |
++---------------------------------------+
+| CHARACTER_SETS                        |
+| COLLATIONS                            |
+| COLLATION_CHARACTER_SET_APPLICABILITY |
+| COLUMNS                               |
+| COLUMN_PRIVILEGES                     |
+| ENGINES                               |
+| EVENTS                                |
+| FILES                                 |
+| GLOBAL_STATUS                         |
+| GLOBAL_VARIABLES                      |
+| KEY_COLUMN_USAGE                      |
+| PARTITIONS                            |
+| PLUGINS                               |
+| PROCESSLIST                           |
+| PROFILING                             |
+| REFERENTIAL_CONSTRAINTS               |
+| ROUTINES                              |
+| SCHEMATA                              |
+| SCHEMA_PRIVILEGES                     |
+| SESSION_STATUS                        |
+| SESSION_VARIABLES                     |
+| STATISTICS                            |
+| TABLES                                |
+| TABLE_CONSTRAINTS                     |
+| TABLE_PRIVILEGES                      |
+| TRIGGERS                              |
+| USER_PRIVILEGES                       |
+| VIEWS                                 |
+| PBXT_STATISTICS                       |
++---------------------------------------+
+Database: INFORMATION_SCHEMA
++---------------------------------------+
+|                Tables                 |
++---------------------------------------+
+| CHARACTER_SETS                        |
+| COLLATIONS                            |
+| COLLATION_CHARACTER_SET_APPLICABILITY |
+| COLUMNS                               |
+| COLUMN_PRIVILEGES                     |
+| ENGINES                               |
+| EVENTS                                |
+| FILES                                 |
+| GLOBAL_STATUS                         |
+| GLOBAL_VARIABLES                      |
+| KEY_COLUMN_USAGE                      |
+| PARTITIONS                            |
+| PLUGINS                               |
+| PROCESSLIST                           |
+| PROFILING                             |
+| REFERENTIAL_CONSTRAINTS               |
+| ROUTINES                              |
+| SCHEMATA                              |
+| SCHEMA_PRIVILEGES                     |
+| SESSION_STATUS                        |
+| SESSION_VARIABLES                     |
+| STATISTICS                            |
+| TABLES                                |
+| TABLE_CONSTRAINTS                     |
+| TABLE_PRIVILEGES                      |
+| TRIGGERS                              |
+| USER_PRIVILEGES                       |
+| VIEWS                                 |
+| PBXT_STATISTICS                       |
++---------------------------------------+
+Wildcard: inf_rmation_schema
++--------------------+
+|     Databases      |
++--------------------+
+| information_schema |
++--------------------+
+SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND table_name<>'ndb_binlog_index' AND table_name<>'ndb_apply_status' GROUP BY TABLE_SCHEMA;
+table_schema	count(*)
+information_schema	29
+mysql	22

=== modified file 'mysql-test/r/information_schema_db.result'
--- a/mysql-test/r/information_schema_db.result	2008-10-02 10:08:15 +0000
+++ b/mysql-test/r/information_schema_db.result	2009-04-08 16:55:26 +0000
@@ -2,37 +2,6 @@ drop table if exists t1,t2;
 drop view if exists v1,v2;
 drop function if exists f1;
 drop function if exists f2;
-use INFORMATION_SCHEMA;
-show tables;
-Tables_in_information_schema
-CHARACTER_SETS
-COLLATIONS
-COLLATION_CHARACTER_SET_APPLICABILITY
-COLUMNS
-COLUMN_PRIVILEGES
-ENGINES
-EVENTS
-FILES
-GLOBAL_STATUS
-GLOBAL_VARIABLES
-KEY_COLUMN_USAGE
-PARTITIONS
-PLUGINS
-PROCESSLIST
-PROFILING
-REFERENTIAL_CONSTRAINTS
-ROUTINES
-SCHEMATA
-SCHEMA_PRIVILEGES
-SESSION_STATUS
-SESSION_VARIABLES
-STATISTICS
-TABLES
-TABLE_CONSTRAINTS
-TABLE_PRIVILEGES
-TRIGGERS
-USER_PRIVILEGES
-VIEWS
 show tables from INFORMATION_SCHEMA like 'T%';
 Tables_in_information_schema (T%)
 TABLES

=== modified file 'mysql-test/r/innodb-autoinc.result'
--- a/mysql-test/r/innodb-autoinc.result	2008-12-19 00:28:51 +0000
+++ b/mysql-test/r/innodb-autoinc.result	2009-04-08 16:55:26 +0000
@@ -197,7 +197,7 @@ c1	c2
 5	9
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	100
 auto_increment_offset	10
@@ -230,7 +230,7 @@ c1
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	1
 auto_increment_offset	1
@@ -269,7 +269,7 @@ c1
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	1
 auto_increment_offset	1
@@ -282,7 +282,7 @@ SELECT * FROM t1;
 c1
 -1
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	100
 auto_increment_offset	10
@@ -315,7 +315,7 @@ c1
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	1
 auto_increment_offset	1
@@ -330,7 +330,7 @@ SELECT * FROM t1;
 c1
 1
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	100
 auto_increment_offset	10
@@ -370,7 +370,7 @@ c1
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	1
 auto_increment_offset	1
@@ -385,7 +385,7 @@ SELECT * FROM t1;
 c1
 1
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	100
 auto_increment_offset	10
@@ -419,7 +419,7 @@ c1
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	1
 auto_increment_offset	1
@@ -434,7 +434,7 @@ c1
 1
 9223372036854775794
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=2, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	2
 auto_increment_offset	10
@@ -452,7 +452,7 @@ c1
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	1
 auto_increment_offset	1
@@ -467,7 +467,7 @@ c1
 1
 18446744073709551603
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=2, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	2
 auto_increment_offset	10
@@ -485,7 +485,7 @@ c1
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	1
 auto_increment_offset	1
@@ -500,7 +500,7 @@ c1
 1
 18446744073709551603
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=5, @@SESSION.AUTO_INCREMENT_OFFSET=7;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	5
 auto_increment_offset	7
@@ -514,7 +514,7 @@ c1
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	1
 auto_increment_offset	1
@@ -533,7 +533,7 @@ c1
 -9223372036854775806
 1
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=3, @@SESSION.AUTO_INCREMENT_OFFSET=3;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	3
 auto_increment_offset	3
@@ -550,7 +550,7 @@ c1
 DROP TABLE t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	1
 auto_increment_offset	1
@@ -568,7 +568,7 @@ SET @@SESSION.AUTO_INCREMENT_INCREMENT=1
 Warnings:
 Warning	1292	Truncated incorrect auto_increment_increment value: '1152921504606846976'
 Warning	1292	Truncated incorrect auto_increment_offset value: '1152921504606846976'
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 Variable_name	Value
 auto_increment_increment	65535
 auto_increment_offset	65535

=== modified file 'mysql-test/r/mysqlshow.result'
--- a/mysql-test/r/mysqlshow.result	2007-04-27 20:45:01 +0000
+++ b/mysql-test/r/mysqlshow.result	2009-04-08 16:55:26 +0000
@@ -75,76 +75,4 @@ Database: test
 2 rows in set.
 
 DROP TABLE t1, t2;
-Database: information_schema
-+---------------------------------------+
-|                Tables                 |
-+---------------------------------------+
-| CHARACTER_SETS                        |
-| COLLATIONS                            |
-| COLLATION_CHARACTER_SET_APPLICABILITY |
-| COLUMNS                               |
-| COLUMN_PRIVILEGES                     |
-| ENGINES                               |
-| EVENTS                                |
-| FILES                                 |
-| GLOBAL_STATUS                         |
-| GLOBAL_VARIABLES                      |
-| KEY_COLUMN_USAGE                      |
-| PARTITIONS                            |
-| PLUGINS                               |
-| PROCESSLIST                           |
-| PROFILING                             |
-| REFERENTIAL_CONSTRAINTS               |
-| ROUTINES                              |
-| SCHEMATA                              |
-| SCHEMA_PRIVILEGES                     |
-| SESSION_STATUS                        |
-| SESSION_VARIABLES                     |
-| STATISTICS                            |
-| TABLES                                |
-| TABLE_CONSTRAINTS                     |
-| TABLE_PRIVILEGES                      |
-| TRIGGERS                              |
-| USER_PRIVILEGES                       |
-| VIEWS                                 |
-+---------------------------------------+
-Database: INFORMATION_SCHEMA
-+---------------------------------------+
-|                Tables                 |
-+---------------------------------------+
-| CHARACTER_SETS                        |
-| COLLATIONS                            |
-| COLLATION_CHARACTER_SET_APPLICABILITY |
-| COLUMNS                               |
-| COLUMN_PRIVILEGES                     |
-| ENGINES                               |
-| EVENTS                                |
-| FILES                                 |
-| GLOBAL_STATUS                         |
-| GLOBAL_VARIABLES                      |
-| KEY_COLUMN_USAGE                      |
-| PARTITIONS                            |
-| PLUGINS                               |
-| PROCESSLIST                           |
-| PROFILING                             |
-| REFERENTIAL_CONSTRAINTS               |
-| ROUTINES                              |
-| SCHEMATA                              |
-| SCHEMA_PRIVILEGES                     |
-| SESSION_STATUS                        |
-| SESSION_VARIABLES                     |
-| STATISTICS                            |
-| TABLES                                |
-| TABLE_CONSTRAINTS                     |
-| TABLE_PRIVILEGES                      |
-| TRIGGERS                              |
-| USER_PRIVILEGES                       |
-| VIEWS                                 |
-+---------------------------------------+
-Wildcard: inf_rmation_schema
-+--------------------+
-|     Databases      |
-+--------------------+
-| information_schema |
-+--------------------+
 End of 5.0 tests

=== modified file 'mysql-test/suite/rpl/r/rpl_auto_increment.result'
--- a/mysql-test/suite/rpl/r/rpl_auto_increment.result	2009-01-14 08:27:32 +0000
+++ b/mysql-test/suite/rpl/r/rpl_auto_increment.result	2009-04-08 16:55:26 +0000
@@ -37,7 +37,7 @@ a	b
 32	6
 drop table t1;
 set @@session.auto_increment_increment=100, @@session.auto_increment_offset=10;
-show variables like "%auto_inc%";
+show variables like "auto_inc%";
 Variable_name	Value
 auto_increment_increment	100
 auto_increment_offset	10

=== modified file 'mysql-test/t/information_schema.test'
--- a/mysql-test/t/information_schema.test	2009-01-23 12:22:05 +0000
+++ b/mysql-test/t/information_schema.test	2009-04-08 16:55:26 +0000
@@ -41,7 +41,8 @@ create view v1 (c) as
  SELECT table_name FROM information_schema.TABLES
   WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND
         table_name<>'ndb_binlog_index' AND
-        table_name<>'ndb_apply_status';
+        table_name<>'ndb_apply_status' AND
+	NOT (table_schema = 'INFORMATION_SCHEMA' AND table_name LIKE 'PBXT_%');
 select * from v1;
 
 select c,table_name from v1 
@@ -529,13 +530,6 @@ delete from mysql.db where user='mysqlte
 flush privileges;
 
 #
-# Bug #9404  information_schema: Weird error messages
-# with SELECT SUM() ... GROUP BY queries
-#
-SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND table_name<>'ndb_binlog_index' AND table_name<>'ndb_apply_status' GROUP BY TABLE_SCHEMA;
-
-
-#
 # TRIGGERS table test
 #
 create table t1 (i int, j int);
@@ -898,39 +892,6 @@ DROP PROCEDURE p1;
 DROP USER mysql_bug20230@localhost;
 
 #
-# Bug#18925: subqueries with MIN/MAX functions on INFORMARTION_SCHEMA 
-#
-
-SELECT t.table_name, c1.column_name
-  FROM information_schema.tables t
-       INNER JOIN
-       information_schema.columns c1
-       ON t.table_schema = c1.table_schema AND
-          t.table_name = c1.table_name
-  WHERE t.table_schema = 'information_schema' AND
-        c1.ordinal_position =
-        ( SELECT COALESCE(MIN(c2.ordinal_position),1)
-            FROM information_schema.columns c2
-            WHERE c2.table_schema = t.table_schema AND
-                  c2.table_name = t.table_name AND
-                  c2.column_name LIKE '%SCHEMA%'
-        );
-SELECT t.table_name, c1.column_name
-  FROM information_schema.tables t
-       INNER JOIN
-       information_schema.columns c1
-       ON t.table_schema = c1.table_schema AND
-          t.table_name = c1.table_name
-  WHERE t.table_schema = 'information_schema' AND
-        c1.ordinal_position =
-        ( SELECT COALESCE(MIN(c2.ordinal_position),1)
-            FROM information_schema.columns c2
-            WHERE c2.table_schema = 'information_schema' AND
-                  c2.table_name = t.table_name AND
-                  c2.column_name LIKE '%SCHEMA%'
-        );
-
-#
 # Bug#21231: query with a simple non-correlated subquery over
 #            INFORMARTION_SCHEMA.TABLES 
 #
@@ -1007,29 +968,6 @@ drop table t1,t2;
 
 
 #
-# Bug#24630  Subselect query crashes mysqld
-#
-select 1 as f1 from information_schema.tables  where "CHARACTER_SETS"=
-(select cast(table_name as char)  from information_schema.tables
- order by table_name limit 1) limit 1;
-
-select t.table_name, group_concat(t.table_schema, '.', t.table_name),
-       count(*) as num1
-from information_schema.tables t
-inner join information_schema.columns c1
-on t.table_schema = c1.table_schema AND t.table_name = c1.table_name
-where t.table_schema = 'information_schema' and
-        c1.ordinal_position =
-        (select isnull(c2.column_type) -
-         isnull(group_concat(c2.table_schema, '.', c2.table_name)) +
-         count(*) as num
-         from information_schema.columns c2 where
-         c2.table_schema='information_schema' and
-         (c2.column_type = 'varchar(7)' or c2.column_type = 'varchar(20)')
-          group by c2.column_type order by num limit 1)
-group by t.table_name order by num1, t.table_name;
-
-#
 # Bug#28266 IS_UPDATABLE field on VIEWS table in I_S database is wrong
 #
 create table t1(f1 int);

=== added file 'mysql-test/t/information_schema_all_engines.test'
--- a/mysql-test/t/information_schema_all_engines.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/information_schema_all_engines.test	2009-04-08 16:55:26 +0000
@@ -0,0 +1,79 @@
+# This file contains tests moved from information_schema.test and
+# information_schema_db.test whose results depends on which engines are
+# available (since these engines inject tables into INFORMATION_SCHEMA).
+
+--source include/not_embedded.inc
+--source include/have_pbxt.inc
+
+use INFORMATION_SCHEMA;
+--replace_result Tables_in_INFORMATION_SCHEMA Tables_in_information_schema
+show tables;
+
+#
+# Bug#18925: subqueries with MIN/MAX functions on INFORMARTION_SCHEMA 
+#
+
+SELECT t.table_name, c1.column_name
+  FROM information_schema.tables t
+       INNER JOIN
+       information_schema.columns c1
+       ON t.table_schema = c1.table_schema AND
+          t.table_name = c1.table_name
+  WHERE t.table_schema = 'information_schema' AND
+        c1.ordinal_position =
+        ( SELECT COALESCE(MIN(c2.ordinal_position),1)
+            FROM information_schema.columns c2
+            WHERE c2.table_schema = t.table_schema AND
+                  c2.table_name = t.table_name AND
+                  c2.column_name LIKE '%SCHEMA%'
+        );
+SELECT t.table_name, c1.column_name
+  FROM information_schema.tables t
+       INNER JOIN
+       information_schema.columns c1
+       ON t.table_schema = c1.table_schema AND
+          t.table_name = c1.table_name
+  WHERE t.table_schema = 'information_schema' AND
+        c1.ordinal_position =
+        ( SELECT COALESCE(MIN(c2.ordinal_position),1)
+            FROM information_schema.columns c2
+            WHERE c2.table_schema = 'information_schema' AND
+                  c2.table_name = t.table_name AND
+                  c2.column_name LIKE '%SCHEMA%'
+        );
+
+#
+# Bug#24630  Subselect query crashes mysqld
+#
+select 1 as f1 from information_schema.tables  where "CHARACTER_SETS"=
+(select cast(table_name as char)  from information_schema.tables
+ order by table_name limit 1) limit 1;
+
+select t.table_name, group_concat(t.table_schema, '.', t.table_name),
+       count(*) as num1
+from information_schema.tables t
+inner join information_schema.columns c1
+on t.table_schema = c1.table_schema AND t.table_name = c1.table_name
+where t.table_schema = 'information_schema' and
+        c1.ordinal_position =
+        (select isnull(c2.column_type) -
+         isnull(group_concat(c2.table_schema, '.', c2.table_name)) +
+         count(*) as num
+         from information_schema.columns c2 where
+         c2.table_schema='information_schema' and
+         (c2.column_type = 'varchar(7)' or c2.column_type = 'varchar(20)')
+          group by c2.column_type order by num limit 1)
+group by t.table_name order by num1, t.table_name;
+
+#
+# Bug #19147: mysqlshow INFORMATION_SCHEMA does not work
+#
+--exec $MYSQL_SHOW information_schema
+--exec $MYSQL_SHOW INFORMATION_SCHEMA
+--exec $MYSQL_SHOW inf_rmation_schema
+
+#
+# Bug #9404  information_schema: Weird error messages
+# with SELECT SUM() ... GROUP BY queries
+#
+SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND table_name<>'ndb_binlog_index' AND table_name<>'ndb_apply_status' GROUP BY TABLE_SCHEMA;

=== modified file 'mysql-test/t/information_schema_db.test'
--- a/mysql-test/t/information_schema_db.test	2008-10-02 09:37:07 +0000
+++ b/mysql-test/t/information_schema_db.test	2009-04-08 16:55:26 +0000
@@ -11,9 +11,6 @@ drop function if exists f1;
 drop function if exists f2;
 --enable_warnings
 
-use INFORMATION_SCHEMA;
---replace_result Tables_in_INFORMATION_SCHEMA Tables_in_information_schema
-show tables;
 --replace_result 'Tables_in_INFORMATION_SCHEMA (T%)' 'Tables_in_information_schema (T%)'
 show tables from INFORMATION_SCHEMA like 'T%';
 create database `inf%`;

=== modified file 'mysql-test/t/innodb-autoinc.test'
--- a/mysql-test/t/innodb-autoinc.test	2009-01-23 12:22:05 +0000
+++ b/mysql-test/t/innodb-autoinc.test	2009-04-08 16:55:26 +0000
@@ -156,7 +156,7 @@ DROP TABLE t1;
 #
 # Test changes to AUTOINC next value calculation
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 INT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 INSERT INTO t1 VALUES (NULL),(5),(NULL);
@@ -173,7 +173,7 @@ DROP TABLE t1;
 # Reset the AUTOINC session variables
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 INT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 INSERT INTO t1 VALUES(0);
@@ -193,13 +193,13 @@ DROP TABLE t1;
 # Reset the AUTOINC session variables
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 INT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 INSERT INTO t1 VALUES(-1);
 SELECT * FROM t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 INSERT INTO t1 VALUES (-2), (NULL),(2),(NULL);
 INSERT INTO t1 VALUES (250),(NULL);
 SELECT * FROM t1;
@@ -214,13 +214,13 @@ DROP TABLE t1;
 # Reset the AUTOINC session variables
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 INT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 INSERT INTO t1 VALUES(-1);
 SELECT * FROM t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 INSERT INTO t1 VALUES (-2);
 INSERT INTO t1 VALUES (NULL);
 INSERT INTO t1 VALUES (2);
@@ -240,13 +240,13 @@ DROP TABLE t1;
 # Reset the AUTOINC session variables
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 INT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 INSERT INTO t1 VALUES(-1);
 SELECT * FROM t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 INSERT INTO t1 VALUES (-2),(NULL),(2),(NULL);
 INSERT INTO t1 VALUES (250),(NULL);
 SELECT * FROM t1;
@@ -262,7 +262,7 @@ DROP TABLE t1;
 # Check for overflow handling when increment is > 1
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 BIGINT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 # TODO: Fix the autoinc init code
@@ -271,7 +271,7 @@ INSERT INTO t1 VALUES(NULL);
 INSERT INTO t1 VALUES (9223372036854775794); #-- 2^63 - 14
 SELECT * FROM t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=2, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 # This should just fit
 INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
 SELECT * FROM t1;
@@ -281,7 +281,7 @@ DROP TABLE t1;
 # Check for overflow handling when increment and offser are > 1
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 # TODO: Fix the autoinc init code
@@ -290,7 +290,7 @@ INSERT INTO t1 VALUES(NULL);
 INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
 SELECT * FROM t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=2, @@SESSION.AUTO_INCREMENT_OFFSET=10;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 # This should fail because of overflow but it doesn't, it seems to be
 # a MySQL server bug. It wraps around to 0 for the last value.
 # See MySQL Bug# 39828
@@ -313,7 +313,7 @@ DROP TABLE t1;
 # Check for overflow handling when increment and offset are odd numbers
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 # TODO: Fix the autoinc init code
@@ -322,7 +322,7 @@ INSERT INTO t1 VALUES(NULL);
 INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
 SELECT * FROM t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=5, @@SESSION.AUTO_INCREMENT_OFFSET=7;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 # This should fail because of overflow but it doesn't. It fails with
 # a duplicate entry message because of a MySQL server bug, it wraps
 # around.  See MySQL Bug# 39828, once MySQL fix the bug we can replace
@@ -344,7 +344,7 @@ DROP TABLE t1;
 # and check for large -ve numbers
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 BIGINT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 # TODO: Fix the autoinc init code
@@ -355,7 +355,7 @@ INSERT INTO t1 VALUES(-92233720368547758
 INSERT INTO t1 VALUES(-9223372036854775808); #-- -2^63
 SELECT * FROM t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=3, @@SESSION.AUTO_INCREMENT_OFFSET=3;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 INSERT INTO t1 VALUES (NULL),(NULL), (NULL);
 SELECT * FROM t1;
 DROP TABLE t1;
@@ -364,7 +364,7 @@ DROP TABLE t1;
 # large numbers 2^60
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
 SET @@INSERT_ID=1;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
 # TODO: Fix the autoinc init code
@@ -373,7 +373,7 @@ INSERT INTO t1 VALUES(NULL);
 INSERT INTO t1 VALUES (18446744073709551610); #-- 2^64 - 2
 SELECT * FROM t1;
 SET @@SESSION.AUTO_INCREMENT_INCREMENT=1152921504606846976, @@SESSION.AUTO_INCREMENT_OFFSET=1152921504606846976;
-SHOW VARIABLES LIKE "%auto_inc%";
+SHOW VARIABLES LIKE "auto_inc%";
 # This should fail because of overflow but it doesn't. It wraps around
 # and the autoinc values look bogus too.
 # See MySQL Bug# 39828, once MySQL fix the bug we can enable the error

=== modified file 'mysql-test/t/mysqlshow.test'
--- a/mysql-test/t/mysqlshow.test	2006-07-22 03:29:25 +0000
+++ b/mysql-test/t/mysqlshow.test	2009-04-08 16:55:26 +0000
@@ -26,11 +26,4 @@ select "---- -v -v -t ------" as "";
 --exec $MYSQL_SHOW test -v -v -t
 DROP TABLE t1, t2;
 
-#
-# Bug #19147: mysqlshow INFORMATION_SCHEMA does not work
-#
---exec $MYSQL_SHOW information_schema
---exec $MYSQL_SHOW INFORMATION_SCHEMA
---exec $MYSQL_SHOW inf_rmation_schema
-
 --echo End of 5.0 tests

=== modified file 'mysql-test/valgrind.supp'
--- a/mysql-test/valgrind.supp	2008-11-21 14:21:50 +0000
+++ b/mysql-test/valgrind.supp	2009-04-08 16:55:26 +0000
@@ -379,7 +379,7 @@
 }
 
 {
-   dlclose memory loss from plugin
+   dlclose memory loss from plugin variant 1
    Memcheck:Leak
    fun:calloc
    fun:_dlerror_run
@@ -388,6 +388,19 @@
 }
 
 {
+   dlclose memory loss from plugin variant 2
+   Memcheck:Leak
+   fun:malloc
+   fun:_dl_close_worker
+   fun:_dl_close
+   fun:_dl_catch_error
+   fun:_dlerror_run
+   fun:dlclose
+   fun:_Z15free_plugin_memP12st_plugin_dl
+   fun:_Z13plugin_dl_delPK19st_mysql_lex_string
+}
+
+{
    dlopen / ptread_cancel_init memory loss on Suse Linux 10.3 32/64 bit
    Memcheck:Leak
    fun:*alloc
@@ -588,3 +601,19 @@
    fun:dlopen*
 }
 
+#
+# In glibc (checked version 2.7), inet_ntoa allocates an 18-byte
+# per-thread static buffer for the return value. That memory is freed
+# at thread exit, however if called from the main thread, Valgrind
+# does not see the free (test main.no-threads).
+#
+# Since inet_ntoa() does not allocate memory dynamically per-call, this
+# suppression is safe.
+#
+
+{
+   inet_ntoa thread local storage
+   Memcheck:Leak
+   fun:malloc
+   fun:inet_ntoa
+}

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2009-03-18 02:14:22 +0000
+++ b/sql/mysqld.cc	2009-04-08 16:55:26 +0000
@@ -4815,10 +4815,10 @@ static bool read_init_file(char *file_na
   DBUG_ENTER("read_init_file");
   DBUG_PRINT("enter",("name: %s",file_name));
   if (!(file=my_fopen(file_name,O_RDONLY,MYF(MY_WME))))
-    return(1);
+    DBUG_RETURN(1);
   bootstrap(file);
   (void) my_fclose(file,MYF(MY_WME));
-  return 0;
+  DBUG_RETURN(0);
 }
 
 
@@ -4839,6 +4839,7 @@ void handle_connection_in_main_thread(TH
   safe_mutex_assert_owner(&LOCK_thread_count);
   thread_cache_size=0;			// Safety
   threads.append(thd);
+  thd->connect_utime= my_micro_time();
   (void) pthread_mutex_unlock(&LOCK_thread_count);
   handle_one_connection((void*) thd);
 }

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2009-03-12 22:27:35 +0000
+++ b/sql/set_var.cc	2009-04-08 16:55:26 +0000
@@ -1740,7 +1740,7 @@ bool sys_var::check_enum(THD *thd, set_v
 {
   char buff[STRING_BUFFER_USUAL_SIZE];
   const char *value;
-  String str(buff, sizeof(buff), system_charset_info), *res;
+  String str(buff, sizeof(buff) - 1, system_charset_info), *res;
 
   if (var->value->result_type() == STRING_RESULT)
   {
@@ -1777,7 +1777,7 @@ bool sys_var::check_set(THD *thd, set_va
   bool not_used;
   char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
   uint error_len= 0;
-  String str(buff, sizeof(buff), system_charset_info), *res;
+  String str(buff, sizeof(buff) - 1, system_charset_info), *res;
 
   if (var->value->result_type() == STRING_RESULT)
   {
@@ -1795,7 +1795,7 @@ bool sys_var::check_set(THD *thd, set_va
     }
 
     var->save_result.ulong_value= ((ulong)
-				   find_set(enum_names, res->c_ptr(),
+				   find_set(enum_names, res->ptr(),
 					    res->length(),
                                             NULL,
                                             &error, &error_len,
@@ -1942,7 +1942,7 @@ bool sys_var_thd_date_time_format::updat
 bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
 {
   char buff[STRING_BUFFER_USUAL_SIZE];
-  String str(buff,sizeof(buff), system_charset_info), *res;
+  String str(buff,sizeof(buff) - 1, system_charset_info), *res;
   DATE_TIME_FORMAT *format;
 
   if (!(res=var->value->val_str(&str)))
@@ -2047,7 +2047,7 @@ bool sys_var_collation::check(THD *thd, 
   if (var->value->result_type() == STRING_RESULT)
   {
     char buff[STRING_BUFFER_USUAL_SIZE];
-    String str(buff,sizeof(buff), system_charset_info), *res;
+    String str(buff,sizeof(buff) - 1, system_charset_info), *res;
     if (!(res=var->value->val_str(&str)))
     {
       my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
@@ -2082,7 +2082,7 @@ bool sys_var_character_set::check(THD *t
   if (var->value->result_type() == STRING_RESULT)
   {
     char buff[STRING_BUFFER_USUAL_SIZE];
-    String str(buff,sizeof(buff), system_charset_info), *res;
+    String str(buff,sizeof(buff) - 1, system_charset_info), *res;
     if (!(res=var->value->val_str(&str)))
     {
       if (!nullable)
@@ -3620,7 +3620,7 @@ bool sys_var_thd_storage_engine::check(T
 {
   char buff[STRING_BUFFER_USUAL_SIZE];
   const char *value;
-  String str(buff, sizeof(buff), &my_charset_latin1), *res;
+  String str(buff, sizeof(buff) - 1, &my_charset_latin1), *res;
 
   var->save_result.plugin= NULL;
   if (var->value->result_type() == STRING_RESULT)
@@ -3737,7 +3737,7 @@ sys_var_thd_sql_mode::
 symbolic_mode_representation(THD *thd, ulonglong val, LEX_STRING *rep)
 {
   char buff[STRING_BUFFER_USUAL_SIZE*8];
-  String tmp(buff, sizeof(buff), &my_charset_latin1);
+  String tmp(buff, sizeof(buff) - 1, &my_charset_latin1);
 
   tmp.length(0);
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2009-02-19 09:01:25 +0000
+++ b/sql/sql_select.cc	2009-04-08 16:55:26 +0000
@@ -1994,8 +1994,17 @@ JOIN::exec()
 				     tmp_fields_list2, tmp_all_fields2, 
 				     fields_list.elements, tmp_all_fields1))
 	  DBUG_VOID_RETURN;
-	curr_join->tmp_fields_list2= tmp_fields_list2;
-	curr_join->tmp_all_fields2= tmp_all_fields2;
+#ifdef HAVE_purify
+        /*
+          Some GCCs use memcpy() for struct assignment, even for x=x.
+          GCC bug 19410: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19410
+        */
+        if (curr_join != this)
+#endif
+        {
+          curr_join->tmp_fields_list2= tmp_fields_list2;
+          curr_join->tmp_all_fields2= tmp_all_fields2;
+        }
       }
       curr_fields_list= &curr_join->tmp_fields_list2;
       curr_all_fields= &curr_join->tmp_all_fields2;

=== modified file 'sql/sql_string.h'
--- a/sql/sql_string.h	2009-01-15 18:11:25 +0000
+++ b/sql/sql_string.h	2009-04-08 16:55:26 +0000
@@ -63,6 +63,11 @@ public:
     Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;
     str_charset=cs;
   }
+  /*
+    NOTE: If one intend to use the c_ptr() method, the following two
+    contructors need the size of memory for STR to be at least LEN+1 (to make
+    room for zero termination).
+  */
   String(const char *str,uint32 len, CHARSET_INFO *cs)
   { 
     Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;

=== modified file 'storage/archive/azio.c'
--- a/storage/archive/azio.c	2007-12-12 13:16:59 +0000
+++ b/storage/archive/azio.c	2009-04-08 16:55:26 +0000
@@ -37,6 +37,40 @@ void putLong(File file, uLong x);
 uLong  getLong(azio_stream *s);
 void read_header(azio_stream *s, unsigned char *buffer);
 
+/*
+  Valgrind normally gives false alarms for zlib operations, in the form of
+  "conditional jump depends on uninitialised values" etc. The reason is
+  explained in the zlib FAQ (http://www.zlib.net/zlib_faq.html#faq36):
+
+    "That is intentional for performance reasons, and the output of deflate
+    is not affected."
+
+  Also discussed on a blog
+  (http://www.sirena.org.uk/log/2006/02/19/zlib-generating-valgrind-warnings/):
+
+    "...loop unrolling in the zlib library causes the mentioned
+    “Conditional jump or move depends on uninitialised value(s)”
+    warnings. These are safe since the results of the comparison are
+    subsequently ignored..."
+
+    "the results of the calculations are discarded by bounds checking done
+    after the loop exits"
+
+  Fix by initializing the memory allocated by zlib when running under Valgrind.
+
+  This fix is safe, since such memory is only used internally by zlib, so we
+  will not hide any bugs in mysql this way.
+*/
+static void *az_allocator(void *dummy, uInt items, uInt size)
+{
+  return my_malloc((size_t)items*(size_t)size, IF_PURIFY(MY_ZEROFILL, MYF(0)));
+}
+
+static void az_free(void *dummy, void *address)
+{
+  my_free(address, MYF(MY_ALLOW_ZERO_PTR));
+}
+
 /* ===========================================================================
   Opens a gzip (.gz) file for reading or writing. The mode parameter
   is as in fopen ("rb" or "wb"). The file is given either by file descriptor
@@ -52,8 +86,8 @@ int az_open (azio_stream *s, const char 
   int level = Z_DEFAULT_COMPRESSION; /* compression level */
   int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
 
-  s->stream.zalloc = (alloc_func)0;
-  s->stream.zfree = (free_func)0;
+  s->stream.zalloc = az_allocator;
+  s->stream.zfree = az_free;
   s->stream.opaque = (voidpf)0;
   memset(s->inbuf, 0, AZ_BUFSIZE_READ);
   memset(s->outbuf, 0, AZ_BUFSIZE_WRITE);