List:Commits« Previous MessageNext Message »
From:Tomas Ulin Date:February 9 2009 4:28pm
Subject:bzr commit into mysql-6.0-telco-6.3 branch (tomas.ulin:2841)
View as plain text  
#At file:///home/tomas/mysql_src/mysql-6.0-telco-6.3-2/

 2841 Tomas Ulin	2009-02-09 [merge]
      merge
removed:
  .bzr-mysql.moved/
  .bzr-mysql.moved/default.conf
modified:
  .bzrignore
  client/mysqldump.c
  client/mysqltest.cc
  include/hash.h
  include/lf.h
  include/my_global.h
  include/my_sys.h
  mysql-test/r/archive_aio_posix.result
  mysql-test/r/comment_index.result
  mysql-test/r/grant4.result
  mysql-test/r/implicit_commit.result
  mysql-test/r/subselect3.result
  mysql-test/r/subselect3_jcl6.result
  mysql-test/suite/ddl_lock/r/concurrent_ddl.result
  mysql-test/suite/ddl_lock/t/concurrent_ddl.test
  mysql-test/t/archive_aio_posix.test
  mysql-test/t/comment_index.test
  mysql-test/t/grant4.test
  mysql-test/t/implicit_commit.test
  mysql-test/t/subselect3.test
  mysys/lf_hash.c
  mysys/my_error.c
  mysys/my_init.c
  mysys/my_safehash.c
  mysys/safemalloc.c
  mysys/thr_mutex.c
  sql/backup/backup_aux.h
  sql/backup/backup_info.cc
  sql/backup/kernel.cc
  sql/backup/logger.cc
  sql/ha_ndbcluster.cc
  sql/ha_ndbcluster_binlog.cc
  sql/handler.cc
  sql/handler.h
  sql/hash_filo.h
  sql/hostname.cc
  sql/item_create.cc
  sql/item_func.cc
  sql/log.cc
  sql/mdl.cc
  sql/repl_failsafe.cc
  sql/rpl_filter.cc
  sql/rpl_handler.cc
  sql/rpl_tblmap.cc
  sql/rpl_tblmap.h
  sql/set_var.cc
  sql/si_objects.cc
  sql/sp.cc
  sql/sp_cache.cc
  sql/sp_head.cc
  sql/sql_acl.cc
  sql/sql_base.cc
  sql/sql_cache.cc
  sql/sql_class.cc
  sql/sql_class.h
  sql/sql_connect.cc
  sql/sql_db.cc
  sql/sql_error.cc
  sql/sql_handler.cc
  sql/sql_lex.cc
  sql/sql_parse.cc
  sql/sql_plugin.cc
  sql/sql_prepare.cc
  sql/sql_repl.cc
  sql/sql_select.cc
  sql/sql_servers.cc
  sql/sql_table.cc
  sql/sql_test.cc
  sql/sql_udf.cc
  sql/table.cc
  sql/transaction.cc
  sql/tztime.cc
  storage/archive/ha_archive.cc
  storage/blackhole/ha_blackhole.cc
  storage/csv/ha_tina.cc
  storage/example/ha_example.cc
  storage/federated/ha_federated.cc
  storage/innobase/handler/ha_innodb.cc
  storage/maria/ha_maria.cc
  storage/maria/ma_init.c
  storage/maria/ma_open.c
  storage/maria/ma_pagecache.c
  storage/maria/ma_recovery.c
  storage/maria/ma_recovery_util.c
  storage/maria/tablockman.c
  storage/myisam/ha_myisam.cc
  storage/myisam/mi_create.c
  storage/myisam/mi_log.c
  storage/myisam/mi_open.c
  storage/myisam/myisam_backup_engine.cc
  storage/ndb/include/ndbapi/NdbScanOperation.hpp
  storage/ndb/src/ndbapi/NdbScanOperation.cpp
  storage/ndb/src/ndbapi/ndberror.c

=== removed directory '.bzr-mysql.moved'
=== removed file '.bzr-mysql.moved/default.conf'
--- a/.bzr-mysql.moved/default.conf	2008-05-23 00:08:03 +0000
+++ b/.bzr-mysql.moved/default.conf	1970-01-01 00:00:00 +0000
@@ -1,3 +0,0 @@
-[MYSQL]
-post_commit_to = commits@stripped
-tree_name = mysql-6.0

=== modified file '.bzrignore'
--- a/.bzrignore	2009-02-05 12:22:39 +0000
+++ b/.bzrignore	2009-02-09 16:27:41 +0000
@@ -2012,29 +2012,4 @@ libmysql/probes.h
 libmysql_r/probes.h
 unittest/tmp
 libmysqld/sql_join_cache.cc
-storage/ndb/src/common/util/ndb_show_compat
-autom4te.cache
-sql/share/czech
-sql/share/danish
-sql/share/dutch
-sql/share/english
-sql/share/estonian
-sql/share/french
-sql/share/german
-sql/share/greek
-sql/share/hungarian
-sql/share/italian
-sql/share/japanese
-sql/share/japanese-sjis
-sql/share/korean
-sql/share/norwegian
-sql/share/norwegian-ny
-sql/share/polish
-sql/share/portuguese
-sql/share/romanian
-sql/share/russian
-sql/share/serbian
-sql/share/slovak
-sql/share/spanish
-sql/share/swedish
-sql/share/ukrainian
+libmysqld/examples/mysqltest.cc

=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2009-02-05 11:03:46 +0000
+++ b/client/mysqldump.c	2009-02-09 16:27:41 +0000
@@ -895,9 +895,9 @@ static int get_options(int *argc, char *
   load_defaults("my",load_default_groups,argc,argv);
   defaults_argv= *argv;
 
-  if (hash_init(&ignore_table, charset_info, 16, 0, 0,
-                (hash_get_key) get_table_key,
-                (hash_free_key) free_table_ent, 0))
+  if (my_hash_init(&ignore_table, charset_info, 16, 0, 0,
+                   (my_hash_get_key) get_table_key,
+                   (my_hash_free_key) free_table_ent, 0))
     return(EX_EOM);
   /* Don't copy internal log tables */
   if (my_hash_insert(&ignore_table,
@@ -1467,8 +1467,8 @@ static void free_resources()
   if (md_result_file && md_result_file != stdout)
     my_fclose(md_result_file, MYF(0));
   my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
-  if (hash_inited(&ignore_table))
-    hash_free(&ignore_table);
+  if (my_hash_inited(&ignore_table))
+    my_hash_free(&ignore_table);
   if (extended_insert)
     dynstr_free(&extended_row);
   if (insert_pat_inited)
@@ -4031,7 +4031,7 @@ static int init_dumping(char *database, 
 
 my_bool include_table(const uchar *hash_key, size_t len)
 {
-  return !hash_search(&ignore_table, hash_key, len);
+  return ! my_hash_search(&ignore_table, hash_key, len);
 }
 
 

=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2009-02-02 15:58:48 +0000
+++ b/client/mysqltest.cc	2009-02-05 12:49:39 +0000
@@ -1108,7 +1108,7 @@ void free_used_memory()
 
   close_connections();
   close_files();
-  hash_free(&var_hash);
+  my_hash_free(&var_hash);
 
   for (i= 0 ; i < q_lines.elements ; i++)
   {
@@ -1965,8 +1965,8 @@ VAR* var_get(const char *var_name, const
     if (length >= MAX_VAR_NAME_LENGTH)
       die("Too long variable name: %s", save_var_name);
 
-    if (!(v = (VAR*) hash_search(&var_hash, (const uchar*) save_var_name,
-                                            length)))
+    if (!(v = (VAR*) my_hash_search(&var_hash, (const uchar*) save_var_name,
+                                    length)))
     {
       char buff[MAX_VAR_NAME_LENGTH+1];
       strmake(buff, save_var_name, length);
@@ -1997,7 +1997,7 @@ err:
 VAR *var_obtain(const char *name, int len)
 {
   VAR* v;
-  if ((v = (VAR*)hash_search(&var_hash, (const uchar *) name, len)))
+  if ((v = (VAR*)my_hash_search(&var_hash, (const uchar *) name, len)))
     return v;
   v = var_init(0, name, len, "", 0);
   my_hash_insert(&var_hash, (uchar*)v);
@@ -7536,8 +7536,8 @@ int main(int argc, char **argv)
 
   my_init_dynamic_array(&q_lines, sizeof(struct st_command*), 1024, 1024);
 
-  if (hash_init(&var_hash, charset_info,
-                1024, 0, 0, get_var_key, var_free, MYF(0)))
+  if (my_hash_init(&var_hash, charset_info,
+                   1024, 0, 0, get_var_key, var_free, MYF(0)))
     die("Variable hash initialization failed");
 
   var_set_string("$MYSQL_SERVER_VERSION", MYSQL_SERVER_VERSION);

=== modified file 'include/hash.h'
--- a/include/hash.h	2008-12-13 20:48:00 +0000
+++ b/include/hash.h	2009-01-27 02:08:48 +0000
@@ -22,40 +22,6 @@ extern "C" {
 #endif
 
 /*
-  There was a problem on MacOSX with a shared object ha_example.so.
-  It used hash_search(). During build of ha_example.so no libmysys
-  was specified. Since MacOSX had a hash_search() in the system
-  library, it built the shared object so that the dynamic linker
-  linked hash_search() to the system library, which caused a crash
-  when called. To come around this, we renamed hash_search() to
-  my_hash_search(), as we did long ago with hash_insert() and
-  hash_reset(). However, this time we made the move complete with
-  all names. To keep compatibility, we redefine the old names.
-  Since every C and C++ file, that uses HASH, needs to include
-  this file, the change is complete. Both names could be used
-  in the code, but the my_* versions are recommended now.
-*/
-#define hash_get_key    my_hash_get_key
-#define hash_free_key   my_hash_free_key
-#define hash_init       my_hash_init
-#define hash_init2      my_hash_init2
-#define _hash_init      _my_hash_init
-#define hash_free       my_hash_free
-#define hash_reset      my_hash_reset
-#define hash_element    my_hash_element
-#define hash_search     my_hash_search
-#define hash_first      my_hash_first
-#define hash_next       my_hash_next
-#define hash_insert     my_hash_insert
-#define hash_delete     my_hash_delete
-#define hash_update     my_hash_update
-#define hash_replace    my_hash_replace
-#define hash_check      my_hash_check
-#define hash_clear      my_hash_clear
-#define hash_inited     my_hash_inited
-#define hash_init_opt   my_hash_init_opt
-
-/*
   Overhead to store an element in hash
   Can be used to approximate memory consumption for a hash
  */

=== modified file 'include/lf.h'
--- a/include/lf.h	2008-07-29 14:10:24 +0000
+++ b/include/lf.h	2009-01-27 02:08:48 +0000
@@ -224,7 +224,7 @@ lock_wrap(lf_alloc_new, void *,
 typedef struct {
   LF_DYNARRAY array;                    /* hash itself */
   LF_ALLOCATOR alloc;                   /* allocator for elements */
-  hash_get_key get_key;                 /* see HASH */
+  my_hash_get_key get_key;              /* see HASH */
   CHARSET_INFO *charset;                /* see HASH */
   uint key_offset, key_length;          /* see HASH */
   uint element_size;                    /* size of memcpy'ed area on insert */
@@ -234,7 +234,7 @@ typedef struct {
 } LF_HASH;
 
 void lf_hash_init(LF_HASH *hash, uint element_size, uint flags,
-                  uint key_offset, uint key_length, hash_get_key get_key,
+                  uint key_offset, uint key_length, my_hash_get_key get_key,
                   CHARSET_INFO *charset);
 void lf_hash_destroy(LF_HASH *hash);
 int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data);

=== modified file 'include/my_global.h'
--- a/include/my_global.h	2009-01-28 15:03:46 +0000
+++ b/include/my_global.h	2009-01-31 16:21:19 +0000
@@ -757,7 +757,6 @@ typedef SOCKET_SIZE_TYPE size_socket;
 #define UNSINT32		/* unsigned int32 */
 
 	/* General constants */
-#define SC_MAXWIDTH	256	/* Max width of screen (for error messages) */
 #define FN_LEN		256	/* Max file name len */
 #define FN_HEADLEN	253	/* Max length of filepart of file name */
 #define FN_EXTLEN	20	/* Max length of extension (part of FN_LEN) */

=== modified file 'include/my_sys.h'
--- a/include/my_sys.h	2009-01-26 16:03:39 +0000
+++ b/include/my_sys.h	2009-02-02 13:57:39 +0000
@@ -43,8 +43,17 @@ extern int NEAR my_errno;		/* Last error
 #define MYSYS_PROGRAM_DONT_USE_CURSES()  { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
 #define MY_INIT(name);		{ my_progname= name; my_init(); }
 
-#define ERRMSGSIZE	(SC_MAXWIDTH)	/* Max length of a error message */
-#define NRERRBUFFS	(2)	/* Buffers for parameters */
+/**
+  Max length of an error message generated by mysys utilities.
+  Some mysys functions produce error messages. These mostly go
+  to stderr.
+  This constant defines the size of the buffer used to format
+  the message. It should be kept in sync with MYSQL_ERRMSG_SIZE,
+  since sometimes mysys errors are stored in the server diagnostics
+  area, and we would like to avoid unexpected truncation.
+*/
+#define MYSYS_ERRMSG_SIZE   (512)
+
 #define MY_FILE_ERROR	((size_t) -1)
 
 	/* General bitmaps for my_func's */
@@ -214,7 +223,6 @@ extern void my_large_free(uchar * ptr, m
 extern int errno;			/* declare errno */
 #endif
 #endif					/* #ifndef errno */
-extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
 extern char *home_dir;			/* Home directory for user */
 extern const char *my_progname;		/* program-name (printed in errors) */
 extern const char *my_progname_short;	/* like above but without directory */

=== modified file 'mysql-test/r/archive_aio_posix.result'
--- a/mysql-test/r/archive_aio_posix.result	2007-12-13 12:55:04 +0000
+++ b/mysql-test/r/archive_aio_posix.result	2009-02-04 22:22:32 +0000
@@ -12686,3 +12686,5 @@ check table t1 extended;
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	OK
 drop table t1;
+# Test file cleanup
+SET GLOBAL archive_aio=off;

=== modified file 'mysql-test/r/comment_index.result'
--- a/mysql-test/r/comment_index.result	2007-08-28 11:04:35 +0000
+++ b/mysql-test/r/comment_index.result	2009-02-04 22:22:32 +0000
@@ -483,3 +483,4 @@ t1	CREATE TABLE `t1` (
   KEY `i11` (`c11`) COMMENT 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij
 abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcd',
   KEY `c13` (`c13`) COMMENT 'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij
 abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcd'
 ) ENGINE=ENGINE DEFAULT CHARSET=latin1 COMMENT='ABCDEFGHIJabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghija
 bcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcd'
+DROP TABLE t1;

=== modified file 'mysql-test/r/grant4.result'
--- a/mysql-test/r/grant4.result	2008-03-04 17:35:42 +0000
+++ b/mysql-test/r/grant4.result	2009-02-04 22:22:32 +0000
@@ -120,3 +120,4 @@ SHOW CREATE VIEW v3;
 View	Create View	character_set_client	collation_connection
 v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t_select_priv`.`a` AS `a`,`t_select_priv`.`b` AS `b` from `t_select_priv`	latin1	latin1_swedish_ci
 drop database mysqltest_db1;
+drop user mysqltest_u1@localhost;

=== modified file 'mysql-test/r/implicit_commit.result'
--- a/mysql-test/r/implicit_commit.result	2009-01-18 23:21:43 +0000
+++ b/mysql-test/r/implicit_commit.result	2009-02-04 22:22:32 +0000
@@ -447,6 +447,7 @@ revoke all on test.t1 from mysqltest_2@l
 CALL db1.test_if_commit();
 IMPLICIT COMMIT
 YES
+drop user mysqltest_2@localhost;
 #
 # SQLCOM_SHOW_GRANTS
 #

=== modified file 'mysql-test/r/subselect3.result'
--- a/mysql-test/r/subselect3.result	2009-01-30 14:13:39 +0000
+++ b/mysql-test/r/subselect3.result	2009-02-04 11:27:06 +0000
@@ -1219,6 +1219,21 @@ id	select_type	table	type	possible_keys	
 1	PRIMARY	Z	ALL	NULL	NULL	NULL	NULL	6	End materialize; Using join buffer
 drop table t0,t1,t2;
 
+BUG#37842: Assertion in DsMrr_impl::dsmrr_init, at handler.cc:4307
+
+CREATE TABLE t1 (
+`pk` int(11) NOT NULL AUTO_INCREMENT,
+`int_key` int(11) DEFAULT NULL,
+PRIMARY KEY (`pk`),
+KEY `int_key` (`int_key`)
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,9),(2,3),(3,8),(4,6),(5,9),(6,5),(7,5),(8,9),(9,1),(10,10);
+SELECT `pk` FROM t1 AS OUTR WHERE `int_key` = ALL (
+SELECT `int_key` FROM t1 AS INNR WHERE INNR . `pk` >= 9
+);
+pk
+DROP TABLE t1;
+
 BUG#40118 Crash when running Batched Key Access and requiring one match for each key
 
 create table t0(a int);

=== modified file 'mysql-test/r/subselect3_jcl6.result'
--- a/mysql-test/r/subselect3_jcl6.result	2009-02-03 09:16:53 +0000
+++ b/mysql-test/r/subselect3_jcl6.result	2009-02-04 11:27:06 +0000
@@ -1224,6 +1224,21 @@ id	select_type	table	type	possible_keys	
 1	PRIMARY	Z	ALL	NULL	NULL	NULL	NULL	6	End materialize; Using join buffer
 drop table t0,t1,t2;
 
+BUG#37842: Assertion in DsMrr_impl::dsmrr_init, at handler.cc:4307
+
+CREATE TABLE t1 (
+`pk` int(11) NOT NULL AUTO_INCREMENT,
+`int_key` int(11) DEFAULT NULL,
+PRIMARY KEY (`pk`),
+KEY `int_key` (`int_key`)
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,9),(2,3),(3,8),(4,6),(5,9),(6,5),(7,5),(8,9),(9,1),(10,10);
+SELECT `pk` FROM t1 AS OUTR WHERE `int_key` = ALL (
+SELECT `int_key` FROM t1 AS INNR WHERE INNR . `pk` >= 9
+);
+pk
+DROP TABLE t1;
+
 BUG#40118 Crash when running Batched Key Access and requiring one match for each key
 
 create table t0(a int);

=== modified file 'mysql-test/suite/ddl_lock/r/concurrent_ddl.result'
--- a/mysql-test/suite/ddl_lock/r/concurrent_ddl.result	2008-12-17 10:11:14 +0000
+++ b/mysql-test/suite/ddl_lock/r/concurrent_ddl.result	2009-02-04 09:11:18 +0000
@@ -311,14 +311,15 @@ DROP TABLE t4;
 ##
 CREATE TABLE t1(a INT, b CHAR(100))
 ENGINE=<engine_type>;
+INSERT INTO t1 (a, b) VALUES (1, 'one');
 # Switch to connection locker
-SET DEBUG_SYNC= 'after_lock_tables_takes_lock
-                 SIGNAL locked WAIT_FOR do_unlock';
+SET DEBUG_SYNC= 'locked_table_name
+                 SIGNAL locked WAIT_FOR do_unlock HIT_LIMIT 2';
 # "send" next statement
 ALTER TABLE t1 RENAME t2;
 # Switch to connection waiter
 SET DEBUG_SYNC= 'now WAIT_FOR locked';
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL do_unlock';
+SET DEBUG_SYNC= 'mdl_enter_cond SIGNAL do_unlock';
 # "send" next statement
 ALTER TABLE t2 RENAME t3;
 # Switch to connection locker
@@ -328,10 +329,10 @@ ALTER TABLE t2 RENAME t3;
 # Switch to connection default
 SELECT SUM(a) FROM t3;
 SUM(a)
-NULL
+1
 SELECT COUNT(*) FROM t3;
 COUNT(*)
-0
+1
 SET DEBUG_SYNC= 'RESET';
 DROP TABLE t3;
 ##

=== modified file 'mysql-test/suite/ddl_lock/t/concurrent_ddl.test'
--- a/mysql-test/suite/ddl_lock/t/concurrent_ddl.test	2008-12-17 10:11:14 +0000
+++ b/mysql-test/suite/ddl_lock/t/concurrent_ddl.test	2009-02-04 09:11:18 +0000
@@ -384,10 +384,12 @@ eval
 CREATE TABLE t1(a INT, b CHAR(100))
 ENGINE=$engine_type;
 
+INSERT INTO t1 (a, b) VALUES (1, 'one');
+
 --echo # Switch to connection locker
 connection locker;
-SET DEBUG_SYNC= 'after_lock_tables_takes_lock
-                 SIGNAL locked WAIT_FOR do_unlock';
+SET DEBUG_SYNC= 'locked_table_name
+                 SIGNAL locked WAIT_FOR do_unlock HIT_LIMIT 2';
 --echo # "send" next statement
 send
 ALTER TABLE t1 RENAME t2;
@@ -395,7 +397,7 @@ ALTER TABLE t1 RENAME t2;
 --echo # Switch to connection waiter
 connection waiter;
 SET DEBUG_SYNC= 'now WAIT_FOR locked';
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL do_unlock';
+SET DEBUG_SYNC= 'mdl_enter_cond SIGNAL do_unlock';
 --echo # "send" next statement
 send
 ALTER TABLE t2 RENAME t3;

=== modified file 'mysql-test/t/archive_aio_posix.test'
--- a/mysql-test/t/archive_aio_posix.test	2007-11-27 15:55:24 +0000
+++ b/mysql-test/t/archive_aio_posix.test	2009-02-04 22:22:32 +0000
@@ -1562,3 +1562,6 @@ insert into t1 set a='';
 insert into t1 set a='a';
 check table t1 extended;
 drop table t1;
+
+--echo # Test file cleanup
+SET GLOBAL archive_aio=off;

=== modified file 'mysql-test/t/comment_index.test'
--- a/mysql-test/t/comment_index.test	2007-06-30 21:25:11 +0000
+++ b/mysql-test/t/comment_index.test	2009-02-04 22:22:32 +0000
@@ -96,6 +96,4 @@ SELECT comment,index_comment,char_length
 let $ENGINE=`select variable_value from information_schema.global_variables where variable_name='STORAGE_ENGINE'`;
 --replace_result $ENGINE ENGINE
 SHOW CREATE TABLE t1;
-
-
-
+DROP TABLE t1;

=== modified file 'mysql-test/t/grant4.test'
--- a/mysql-test/t/grant4.test	2008-04-11 10:09:58 +0000
+++ b/mysql-test/t/grant4.test	2009-02-04 22:22:32 +0000
@@ -143,4 +143,4 @@ SHOW CREATE VIEW v3;
 connection default;
 disconnect con1;
 drop database mysqltest_db1;
-
+drop user mysqltest_u1@localhost;

=== modified file 'mysql-test/t/implicit_commit.test'
--- a/mysql-test/t/implicit_commit.test	2008-12-13 19:55:44 +0000
+++ b/mysql-test/t/implicit_commit.test	2009-02-04 22:22:32 +0000
@@ -461,6 +461,8 @@ let $statement=
   revoke all on test.t1 from mysqltest_2@localhost;
 source include/implicit_commit_helper.inc;
 
+drop user mysqltest_2@localhost;
+
 --echo #
 --echo # SQLCOM_SHOW_GRANTS
 --echo #

=== modified file 'mysql-test/t/subselect3.test'
--- a/mysql-test/t/subselect3.test	2009-01-30 14:13:39 +0000
+++ b/mysql-test/t/subselect3.test	2009-02-04 11:27:06 +0000
@@ -989,6 +989,21 @@ explain select * from t1 where (a,b,c) i
 
 drop table t0,t1,t2;
 
+--echo
+--echo BUG#37842: Assertion in DsMrr_impl::dsmrr_init, at handler.cc:4307
+--echo
+CREATE TABLE t1 (
+  `pk` int(11) NOT NULL AUTO_INCREMENT,
+  `int_key` int(11) DEFAULT NULL,
+  PRIMARY KEY (`pk`),
+  KEY `int_key` (`int_key`)
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1,9),(2,3),(3,8),(4,6),(5,9),(6,5),(7,5),(8,9),(9,1),(10,10);
+SELECT `pk` FROM t1 AS OUTR WHERE `int_key` = ALL (
+ SELECT `int_key` FROM t1 AS INNR WHERE INNR . `pk` >= 9
+);
+DROP TABLE t1;
+
 --echo 
 --echo BUG#40118 Crash when running Batched Key Access and requiring one match for each key
 --echo

=== modified file 'mysys/lf_hash.c'
--- a/mysys/lf_hash.c	2008-12-17 18:40:14 +0000
+++ b/mysys/lf_hash.c	2009-01-27 02:08:48 +0000
@@ -312,7 +312,7 @@ static int initialize_bucket(LF_HASH *, 
   See wt_init() for example.
 */
 void lf_hash_init(LF_HASH *hash, uint element_size, uint flags,
-                  uint key_offset, uint key_length, hash_get_key get_key,
+                  uint key_offset, uint key_length, my_hash_get_key get_key,
                   CHARSET_INFO *charset)
 {
   compile_time_assert(sizeof(LF_SLIST) == LF_HASH_OVERHEAD);

=== modified file 'mysys/my_error.c'
--- a/mysys/my_error.c	2008-05-29 15:44:11 +0000
+++ b/mysys/my_error.c	2009-01-30 12:32:09 +0000
@@ -19,6 +19,9 @@
 #include <stdarg.h>
 #include <m_ctype.h>
 
+/* Max length of a error message. Should be kept in sync with MYSQL_ERRMSG_SIZE. */
+#define ERRMSGSIZE      (512)
+
 /* Define some external variables for error handling */
 
 /*
@@ -30,8 +33,6 @@
   my_printf_error(ER_CODE, format, MYF(N), ...)
 */
 
-char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
-
 /*
   Message texts are registered into a linked list of 'my_err_head' structs.
   Each struct contains (1.) an array of pointers to C character strings with
@@ -71,7 +72,7 @@ void my_error(int nr, myf MyFlags, ...)
   const char *format;
   struct my_err_head *meh_p;
   va_list args;
-  char ebuff[ERRMSGSIZE + 20];
+  char ebuff[ERRMSGSIZE];
   DBUG_ENTER("my_error");
   DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d", nr, MyFlags, errno));
 
@@ -109,7 +110,7 @@ void my_error(int nr, myf MyFlags, ...)
 void my_printf_error(uint error, const char *format, myf MyFlags, ...)
 {
   va_list args;
-  char ebuff[ERRMSGSIZE+20];
+  char ebuff[ERRMSGSIZE];
   DBUG_ENTER("my_printf_error");
   DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d  format: %s",
 		    error, MyFlags, errno, format));
@@ -135,7 +136,7 @@ void my_printf_error(uint error, const c
 
 void my_printv_error(uint error, const char *format, myf MyFlags, va_list ap)
 {
-  char ebuff[ERRMSGSIZE+20];
+  char ebuff[ERRMSGSIZE];
   DBUG_ENTER("my_printv_error");
   DBUG_PRINT("my", ("nr: %d  MyFlags: %d  errno: %d  format: %s",
 		    error, MyFlags, errno, format));

=== modified file 'mysys/my_init.c'
--- a/mysys/my_init.c	2009-01-30 14:13:39 +0000
+++ b/mysys/my_init.c	2009-02-04 10:49:16 +0000
@@ -159,9 +159,11 @@ void my_end(int infoflag)
   {					/* Test if some file is left open */
     if (my_file_opened | my_stream_opened)
     {
-      sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened);
-      (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL);
-      DBUG_PRINT("error",("%s",errbuff[0]));
+      char ebuff[MYSYS_ERRMSG_SIZE];
+      my_snprintf(ebuff, sizeof(ebuff), EE(EE_OPEN_WARNING),
+                  my_file_opened, my_stream_opened);
+      my_message_no_curses(EE_OPEN_WARNING, ebuff, ME_BELL);
+      DBUG_PRINT("error", ("%s", ebuff));
       my_print_open_files();
     }
   }

=== modified file 'mysys/my_safehash.c'
--- a/mysys/my_safehash.c	2008-05-29 15:44:11 +0000
+++ b/mysys/my_safehash.c	2009-01-27 02:08:48 +0000
@@ -100,9 +100,9 @@ my_bool safe_hash_init(SAFE_HASH *hash, 
                        uchar *default_value)
 {
   DBUG_ENTER("safe_hash_init");
-  if (hash_init(&hash->hash, &my_charset_bin, elements,
-                0, 0, (hash_get_key) safe_hash_entry_get,
-                (void (*)(void*)) safe_hash_entry_free, 0))
+  if (my_hash_init(&hash->hash, &my_charset_bin, elements,
+                   0, 0, (my_hash_get_key) safe_hash_entry_get,
+                   (void (*)(void*)) safe_hash_entry_free, 0))
   {
     hash->default_value= 0;
     DBUG_RETURN(1);
@@ -133,7 +133,7 @@ void safe_hash_free(SAFE_HASH *hash)
   */
   if (hash->default_value)
   {
-    hash_free(&hash->hash);
+    my_hash_free(&hash->hash);
     rwlock_destroy(&hash->mutex);
     hash->default_value=0;
   }
@@ -160,7 +160,7 @@ uchar *safe_hash_search(SAFE_HASH *hash,
   uchar *result;
   DBUG_ENTER("safe_hash_search");
   rw_rdlock(&hash->mutex);
-  result= hash_search(&hash->hash, key, length);
+  result= my_hash_search(&hash->hash, key, length);
   rw_unlock(&hash->mutex);
   if (!result)
     result= def;
@@ -200,7 +200,7 @@ my_bool safe_hash_set(SAFE_HASH *hash, c
   DBUG_PRINT("enter",("key: %.*s  data: 0x%lx", length, key, (long) data));
 
   rw_wrlock(&hash->mutex);
-  entry= (SAFE_HASH_ENTRY*) hash_search(&hash->hash, key, length);
+  entry= (SAFE_HASH_ENTRY*) my_hash_search(&hash->hash, key, length);
 
   if (data == hash->default_value)
   {
@@ -214,7 +214,7 @@ my_bool safe_hash_set(SAFE_HASH *hash, c
     /* unlink entry from list */
     if ((*entry->prev= entry->next))
       entry->next->prev= entry->prev;
-    hash_delete(&hash->hash, (uchar*) entry);
+    my_hash_delete(&hash->hash, (uchar*) entry);
     goto end;
   }
   if (entry)
@@ -285,7 +285,7 @@ void safe_hash_change(SAFE_HASH *hash, u
       {
         if ((*entry->prev= entry->next))
           entry->next->prev= entry->prev;
-        hash_delete(&hash->hash, (uchar*) entry);
+        my_hash_delete(&hash->hash, (uchar*) entry);
       }
       else
         entry->data= new_data;

=== modified file 'mysys/safemalloc.c'
--- a/mysys/safemalloc.c	2008-10-20 09:16:47 +0000
+++ b/mysys/safemalloc.c	2009-02-02 13:57:39 +0000
@@ -147,14 +147,16 @@ void *_mymalloc(size_t size, const char 
       error_handler_hook=fatal_error_handler_hook;
     if (MyFlags & (MY_FAE+MY_WME))
     {
-      char buff[SC_MAXWIDTH];
+      char buff[MYSYS_ERRMSG_SIZE];
       my_errno=errno;
-      sprintf(buff,"Out of memory at line %d, '%s'", lineno, filename);
+      my_snprintf(buff, sizeof(buff), "Out of memory at line %d, '%s'",
+                  lineno, filename);
       my_message(EE_OUTOFMEMORY, buff, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH));
-      sprintf(buff,"needed %lu byte (%luk), memory in use: %lu bytes (%luk)",
-	      (ulong) size, (ulong) (size + 1023L) / 1024L,
-	      (ulong) sf_malloc_max_memory,
-	      (ulong) (sf_malloc_max_memory + 1023L) / 1024L);
+      my_snprintf(buff, sizeof(buff),
+                  "needed %lu byte (%luk), memory in use: %lu bytes (%luk)",
+	          (ulong) size, (ulong) (size + 1023L) / 1024L,
+	          (ulong) sf_malloc_max_memory,
+	          (ulong) (sf_malloc_max_memory + 1023L) / 1024L);
       my_message(EE_OUTOFMEMORY, buff, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH));
     }
     DBUG_PRINT("error",("Out of memory, in use: %ld at line %d, '%s'",

=== modified file 'mysys/thr_mutex.c'
--- a/mysys/thr_mutex.c	2008-12-04 21:02:09 +0000
+++ b/mysys/thr_mutex.c	2009-01-27 02:08:48 +0000
@@ -120,16 +120,16 @@ int safe_mutex_init(safe_mutex_t *mp,
       pthread_mutex_lock(&THR_LOCK_mutex);
       mp->id= ++safe_mutex_id;
       pthread_mutex_unlock(&THR_LOCK_mutex);
-      hash_init(mp->locked_mutex, &my_charset_bin,
-                1000,
-                offsetof(safe_mutex_deadlock_t, id),
-                sizeof(mp->id),
-                0, 0, HASH_UNIQUE);
-      hash_init(mp->used_mutex, &my_charset_bin,
-                1000,
-                offsetof(safe_mutex_t, id),
-                sizeof(mp->id),
-                0, 0, HASH_UNIQUE);
+      my_hash_init(mp->locked_mutex, &my_charset_bin,
+                   1000,
+                   offsetof(safe_mutex_deadlock_t, id),
+                   sizeof(mp->id),
+                   0, 0, HASH_UNIQUE);
+      my_hash_init(mp->used_mutex, &my_charset_bin,
+                   1000,
+                   offsetof(safe_mutex_t, id),
+                   sizeof(mp->id),
+                   0, 0, HASH_UNIQUE);
     }
   }
   else
@@ -267,7 +267,7 @@ int safe_mutex_lock(safe_mutex_t *mp, my
         */
         pthread_mutex_lock(&THR_LOCK_mutex);
 
-        if (!hash_search(mutex_root->locked_mutex, (uchar*) &mp->id, 0))
+        if (! my_hash_search(mutex_root->locked_mutex, (uchar*) &mp->id, 0))
         {
           safe_mutex_deadlock_t *deadlock;
           safe_mutex_t *mutex;
@@ -287,7 +287,7 @@ int safe_mutex_lock(safe_mutex_t *mp, my
           mutex= mutex_root;
           do
           {
-            if (hash_search(mp->locked_mutex, (uchar*) &mutex->id, 0))
+            if (my_hash_search(mp->locked_mutex, (uchar*) &mutex->id, 0))
             {
               print_deadlock_warning(mp, mutex);
               /* Mark wrong usage to avoid future warnings for same error */
@@ -592,8 +592,8 @@ void safe_mutex_free_deadlock_data(safe_
                     mp);
     pthread_mutex_unlock(&THR_LOCK_mutex);
 
-    hash_free(mp->used_mutex);
-    hash_free(mp->locked_mutex);
+    my_hash_free(mp->used_mutex);
+    my_hash_free(mp->locked_mutex);
     my_free(mp->locked_mutex, 0);
     mp->create_flags|= MYF_NO_DEADLOCK_DETECTION;
   }
@@ -702,12 +702,12 @@ static my_bool remove_from_locked_mutex(
                        (ulong) delete_mutex, (ulong) mp, 
                        delete_mutex->id, mp->id));
 
-  found= (safe_mutex_deadlock_t *) hash_search(mp->locked_mutex,
-                                               (uchar*) &delete_mutex->id, 0);
+  found= (safe_mutex_deadlock_t*) my_hash_search(mp->locked_mutex,
+                                                 (uchar*) &delete_mutex->id, 0);
   DBUG_ASSERT(found);
   if (found)
   {
-    if (hash_delete(mp->locked_mutex, (uchar*) found))
+    if (my_hash_delete(mp->locked_mutex, (uchar*) found))
     {
       DBUG_ASSERT(0);
     }
@@ -724,7 +724,7 @@ static my_bool remove_from_used_mutex(sa
   DBUG_PRINT("enter", ("delete_mutex: 0x%lx  mutex: 0x%lx  (id: %lu <- %lu)",
                        (ulong) mutex, (ulong) locked_mutex, 
                        mutex->id, locked_mutex->id));
-  if (hash_delete(locked_mutex->mutex->used_mutex, (uchar*) mutex))
+  if (my_hash_delete(locked_mutex->mutex->used_mutex, (uchar*) mutex))
   {
     DBUG_ASSERT(0);
   }

=== modified file 'sql/backup/backup_aux.h'
--- a/sql/backup/backup_aux.h	2008-12-18 21:46:36 +0000
+++ b/sql/backup/backup_aux.h	2009-02-04 10:49:16 +0000
@@ -356,15 +356,15 @@ template<class A, class B>
 inline
 Map<A,B>::Map(size_t init_size)
 {
-  hash_init(&m_hash, &::my_charset_bin, init_size, 
-            0, sizeof(A), NULL, Node::del_key, MYF(0));
+  my_hash_init(&m_hash, &::my_charset_bin, init_size,
+               0, sizeof(A), NULL, Node::del_key, MYF(0));
 }
 
 template<class A, class B>
 inline
 Map<A,B>::~Map()
 {
-  hash_free(&m_hash);
+  my_hash_free(&m_hash);
 }
 
 /** 
@@ -386,7 +386,7 @@ template<class A, class B>
 inline
 B* Map<A,B>::operator[](const A &a) const
 {
-  Node *n= (Node*) hash_search(&m_hash, (uchar*) &a, sizeof(A));
+  Node *n= (Node*) my_hash_search(&m_hash, (uchar*) &a, sizeof(A));
   
   return n ? n->ptr : NULL;
 }

=== modified file 'sql/backup/backup_info.cc'
--- a/sql/backup/backup_info.cc	2008-12-18 21:46:36 +0000
+++ b/sql/backup/backup_info.cc	2009-02-04 10:49:16 +0000
@@ -389,10 +389,10 @@ Backup_info::Backup_info(backup::Logger 
 
   bzero(m_snap, sizeof(m_snap));
 
-  if (hash_init(&ts_hash, &::my_charset_bin, 16, 0, 0,
-                Ts_hash_node::get_key, Ts_hash_node::free, MYF(0))
+  if (my_hash_init(&ts_hash, &::my_charset_bin, 16, 0, 0,
+                   Ts_hash_node::get_key, Ts_hash_node::free, MYF(0))
       ||
-      hash_init(&dep_hash, &::my_charset_bin, 16, 0, 0,
+      my_hash_init(&dep_hash, &::my_charset_bin, 16, 0, 0,
                 Dep_node::get_key, Dep_node::free, MYF(0)))
   {
     // Allocation failed. Error has been reported, but not logged to backup logs
@@ -474,8 +474,8 @@ Backup_info::~Backup_info()
   while ((snap= it++))
     delete snap;
 
-  hash_free(&ts_hash);  
-  hash_free(&dep_hash);
+  my_hash_free(&ts_hash);  
+  my_hash_free(&dep_hash);
 }
 
 /**
@@ -529,7 +529,7 @@ backup::Image_info::Ts* Backup_info::add
   size_t klen= 0;
   uchar  *key= Ts_hash_node::get_key((const uchar*)&n0, &klen, TRUE);
 
-  Ts_hash_node *n1= (Ts_hash_node*) hash_search(&ts_hash, key, klen);
+  Ts_hash_node *n1= (Ts_hash_node*) my_hash_search(&ts_hash, key, klen);
 
   // if tablespace was found, return the catalogue entry stored in the hash
   if (n1)
@@ -1236,7 +1236,7 @@ int Backup_info::get_dep_node(const ::St
   size_t klen;
   uchar  *key= Dep_node::get_key((const uchar*)&n, &klen, TRUE);
 
-  node= (Dep_node*) hash_search(&dep_hash, key, klen);
+  node= (Dep_node*) my_hash_search(&dep_hash, key, klen);
 
   // if we have found node in the hash there is nothing more to do
   if (node)

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2009-01-21 15:06:10 +0000
+++ b/sql/backup/kernel.cc	2009-02-04 10:49:16 +0000
@@ -260,7 +260,7 @@ int send_error(Backup_restore_ctx &conte
 {
   if (!context.error_reported())
   {
-    char buf[ERRMSGSIZE + 20];
+    char buf[MYSQL_ERRMSG_SIZE];
     va_list args;
     va_start(args, error_code);
 

=== modified file 'sql/backup/logger.cc'
--- a/sql/backup/logger.cc	2008-12-18 21:46:36 +0000
+++ b/sql/backup/logger.cc	2009-02-04 10:49:16 +0000
@@ -33,7 +33,7 @@ namespace backup {
 int Logger::write_message(log_level::value level, int error_code,
                           const char *msg)
 {
-   char buf[ERRMSGSIZE + 30];
+   char buf[MYSQL_ERRMSG_SIZE];
    /*
      When logging to server's error log, msg will be prefixed with
      "Backup:"/"Restore:" if the operation has been initialized (i.e., after
@@ -142,7 +142,7 @@ int Logger::v_report_error(log_level::va
 int Logger::v_write_message(log_level::value level, int error_code,
                             const char *format, va_list args)
 {
-  char buf[ERRMSGSIZE + 20];
+  char buf[MYSQL_ERRMSG_SIZE];
 
   my_vsnprintf(buf, sizeof(buf), format, args);
   return write_message(level, error_code, buf);

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2009-02-09 10:11:38 +0000
+++ b/sql/ha_ndbcluster.cc	2009-02-09 16:27:41 +0000
@@ -635,8 +635,8 @@ Thd_ndb::Thd_ndb()
   m_error= FALSE;
   m_error_code= 0;
   options= 0;
-  (void) hash_init(&open_tables, &my_charset_bin, 5, 0, 0,
-                   (hash_get_key)thd_ndb_share_get_key, 0, 0);
+  (void) my_hash_init(&open_tables, &my_charset_bin, 5, 0, 0,
+                   (my_hash_get_key)thd_ndb_share_get_key, 0, 0);
   m_unsent_bytes= 0;
   m_execute_count= 0;
   m_max_violation_count= 0;
@@ -656,7 +656,7 @@ Thd_ndb::~Thd_ndb()
     ndb= NULL;
   }
   changed_tables.empty();
-  hash_free(&open_tables);
+  my_hash_free(&open_tables);
   free_root(&m_batch_mem_root, MYF(0));
 }
 
@@ -2862,7 +2862,7 @@ int ha_ndbcluster::ordered_index_scan(co
   if (lm == NdbOperation::LM_Read)
     options.scan_flags|= NdbScanOperation::SF_KeyInfo;
   if (sorted)
-    options.scan_flags|= NdbScanOperation::SF_OrderBy;
+    options.scan_flags|= NdbScanOperation::SF_OrderByFull;
   if (descending)
     options.scan_flags|= NdbScanOperation::SF_Descending;
   const NdbRecord *key_rec= m_index[active_index].ndb_record_key;
@@ -5359,7 +5359,7 @@ int ha_ndbcluster::start_statement(THD *
   {
     PRINT_OPTION_FLAGS(thd);
     trans_register_ha(thd, FALSE, ndbcluster_hton);
-    if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
+    if (thd->in_multi_stmt_transaction())
     {
       if (!trans)
         trans_register_ha(thd, TRUE, ndbcluster_hton);
@@ -5487,14 +5487,14 @@ int ha_ndbcluster::init_handler_for_stat
   }
 #endif
 
-  if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
+  if (thd->in_multi_stmt_transaction())
   {
     const void *key= m_table;
     HASH_SEARCH_STATE state;
     THD_NDB_SHARE *thd_ndb_share=
-      (THD_NDB_SHARE*)hash_first(&thd_ndb->open_tables, (uchar *)&key, sizeof(key), &state);
+      (THD_NDB_SHARE*)my_hash_first(&thd_ndb->open_tables, (uchar *)&key, sizeof(key), &state);
     while (thd_ndb_share && thd_ndb_share->key != key)
-      thd_ndb_share= (THD_NDB_SHARE*)hash_next(&thd_ndb->open_tables, (uchar *)&key, sizeof(key), &state);
+      thd_ndb_share= (THD_NDB_SHARE*)my_hash_next(&thd_ndb->open_tables, (uchar *)&key, sizeof(key), &state);
     if (thd_ndb_share == 0)
     {
       thd_ndb_share= (THD_NDB_SHARE *) alloc_root(&thd->transaction.mem_root,
@@ -5579,8 +5579,7 @@ int ha_ndbcluster::external_lock(THD *th
     {
       DBUG_PRINT("info", ("Rows has changed"));
 
-      if (thd_ndb->trans &&
-          thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
+      if (thd_ndb->trans && thd->in_multi_stmt_transaction())
       {
         DBUG_PRINT("info", ("Add share to list of changed tables, %p",
                             m_share));
@@ -5604,8 +5603,7 @@ int ha_ndbcluster::external_lock(THD *th
       DBUG_PRINT("trans", ("Last external_lock"));
       PRINT_OPTION_FLAGS(thd);
 
-      if ((!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) &&
-          thd_ndb->trans)
+      if (!thd->in_multi_stmt_transaction())
       {
         if (thd_ndb->trans)
         {
@@ -5770,7 +5768,7 @@ int ndbcluster_commit(handlerton *hton, 
     DBUG_PRINT("info", ("trans == NULL"));
     DBUG_RETURN(0);
   }
-  if (!all && (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
+  if (!all && thd->in_multi_stmt_transaction())
   {
     /*
       An odditity in the handler interface is that commit on handlerton
@@ -5914,7 +5912,7 @@ static int ndbcluster_rollback(handlerto
     DBUG_PRINT("info", ("trans == NULL"));
     DBUG_RETURN(0);
   }
-  if (!all && (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
+  if (!all && thd->in_multi_stmt_transaction() &&
       (thd_ndb->save_point_count > 0))
   {
     /*
@@ -6757,8 +6755,8 @@ int ha_ndbcluster::create(const char *na
     */
     {
       uint length= (uint) strlen(name);
-      if ((share= (NDB_SHARE*) hash_search(&ndbcluster_open_tables,
-                                           (uchar*) name, length)))
+      if ((share= (NDB_SHARE*) my_hash_search(&ndbcluster_open_tables,
+                                              (uchar*) name, length)))
         handle_trailing_share(thd, share);
     }
     /*
@@ -8655,18 +8653,18 @@ int ndbcluster_find_files(handlerton *ht
                         NdbDictionary::Object::UserTable) != 0)
     ERR_RETURN(dict->getNdbError());
 
-  if (hash_init(&ndb_tables, system_charset_info,list.count,0,0,
-                (hash_get_key)tables_get_key,0,0))
+  if (my_hash_init(&ndb_tables, system_charset_info,list.count,0,0,
+                   (my_hash_get_key)tables_get_key,0,0))
   {
     DBUG_PRINT("error", ("Failed to init HASH ndb_tables"));
     DBUG_RETURN(-1);
   }
 
-  if (hash_init(&ok_tables, system_charset_info,32,0,0,
-                (hash_get_key)tables_get_key,0,0))
+  if (my_hash_init(&ok_tables, system_charset_info,32,0,0,
+                (my_hash_get_key)tables_get_key,0,0))
   {
     DBUG_PRINT("error", ("Failed to init HASH ok_tables"));
-    hash_free(&ndb_tables);
+    my_hash_free(&ndb_tables);
     DBUG_RETURN(-1);
   }  
 
@@ -8707,7 +8705,8 @@ int ndbcluster_find_files(handlerton *ht
   {
     bool file_on_disk= FALSE;
     DBUG_PRINT("info", ("%s", file_name->str));
-    if (hash_search(&ndb_tables, (uchar*) file_name->str, file_name->length))
+    if (my_hash_search(&ndb_tables, (uchar*) file_name->str,
+                       file_name->length))
     {
       build_table_filename(name, sizeof(name), db, file_name->str, reg_ext, 0);
       if (my_access(name, F_OK))
@@ -8740,10 +8739,10 @@ int ndbcluster_find_files(handlerton *ht
       if (file_on_disk)
       {
 	// Ignore this ndb table 
- 	uchar *record= hash_search(&ndb_tables, (uchar*) file_name->str,
-                                   file_name->length);
+        uchar *record= my_hash_search(&ndb_tables, (uchar*) file_name->str,
+                                      file_name->length);
 	DBUG_ASSERT(record);
-	hash_delete(&ndb_tables, record);
+	my_hash_delete(&ndb_tables, record);
 	push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 			    ER_TABLE_EXISTS_ERROR,
 			    "Local table %s.%s shadows ndb table",
@@ -8776,7 +8775,7 @@ int ndbcluster_find_files(handlerton *ht
       build_table_filename(name, sizeof(name), db, "", "", 0);
     for (i= 0; i < ok_tables.records; i++)
     {
-      file_name_str= (char*)hash_element(&ok_tables, i);
+      file_name_str= (char*)my_hash_element(&ok_tables, i);
       end= end1 +
         tablename_to_filename(file_name_str, end1, sizeof(name) - (end1 - name));
       pthread_mutex_lock(&LOCK_open);
@@ -8791,8 +8790,9 @@ int ndbcluster_find_files(handlerton *ht
   List<char> create_list;
   for (i= 0 ; i < ndb_tables.records ; i++)
   {
-    file_name_str= (char*) hash_element(&ndb_tables, i);
-    if (!hash_search(&ok_tables, (uchar*) file_name_str, strlen(file_name_str)))
+    file_name_str= (char*) my_hash_element(&ndb_tables, i);
+    if (!my_hash_search(&ok_tables, (uchar*) file_name_str,
+                        strlen(file_name_str)))
     {
       build_table_filename(name, sizeof(name), db, file_name_str, reg_ext, 0);
       if (my_access(name, F_OK))
@@ -8867,8 +8867,8 @@ int ndbcluster_find_files(handlerton *ht
 
   pthread_mutex_unlock(&LOCK_open);
 
-  hash_free(&ok_tables);
-  hash_free(&ndb_tables);
+  my_hash_free(&ok_tables);
+  my_hash_free(&ndb_tables);
 
   // Delete schema file from files
   if (!strcmp(db, NDB_REP_DB))
@@ -8974,8 +8974,8 @@ static int ndbcluster_init(void *p)
     goto ndbcluster_init_error;
   }
 
-  (void) hash_init(&ndbcluster_open_tables,system_charset_info,32,0,0,
-                   (hash_get_key) ndbcluster_get_key,0,0);
+  (void) my_hash_init(&ndbcluster_open_tables,system_charset_info,32,0,0,
+                      (my_hash_get_key) ndbcluster_get_key,0,0);
   /* start the ndb injector thread */
   if (ndbcluster_binlog_start())
   {
@@ -8989,7 +8989,7 @@ static int ndbcluster_init(void *p)
   if (pthread_create(&tmp, &connection_attrib, ndb_util_thread_func, 0))
   {
     DBUG_PRINT("error", ("Could not create ndb utility thread"));
-    hash_free(&ndbcluster_open_tables);
+    my_hash_free(&ndbcluster_open_tables);
     pthread_mutex_destroy(&ndbcluster_mutex);
     pthread_mutex_destroy(&LOCK_ndb_util_thread);
     pthread_cond_destroy(&COND_ndb_util_thread);
@@ -9007,7 +9007,7 @@ static int ndbcluster_init(void *p)
   if (!ndb_util_thread_running)
   {
     DBUG_PRINT("error", ("ndb utility thread exited prematurely"));
-    hash_free(&ndbcluster_open_tables);
+    my_hash_free(&ndbcluster_open_tables);
     pthread_mutex_destroy(&ndbcluster_mutex);
     pthread_mutex_destroy(&LOCK_ndb_util_thread);
     pthread_cond_destroy(&COND_ndb_util_thread);
@@ -9049,7 +9049,7 @@ static int ndbcluster_end(handlerton *ht
     while (ndbcluster_open_tables.records)
     {
       NDB_SHARE *share=
-        (NDB_SHARE*) hash_element(&ndbcluster_open_tables, 0);
+        (NDB_SHARE*) my_hash_element(&ndbcluster_open_tables, 0);
 #ifndef DBUG_OFF
       fprintf(stderr, "NDB: table share %s with use_count %d not freed\n",
               share->key, share->use_count);
@@ -9058,7 +9058,7 @@ static int ndbcluster_end(handlerton *ht
     }
     pthread_mutex_unlock(&ndbcluster_mutex);
   }
-  hash_free(&ndbcluster_open_tables);
+  my_hash_free(&ndbcluster_open_tables);
 
   ndbcluster_disconnect();
 
@@ -9381,9 +9381,9 @@ uint ndb_get_commitcount(THD *thd, char 
   build_table_filename(name, sizeof(name), dbname, tabname, "", 0);
   DBUG_PRINT("enter", ("name: %s", name));
   pthread_mutex_lock(&ndbcluster_mutex);
-  if (!(share=(NDB_SHARE*) hash_search(&ndbcluster_open_tables,
-                                       (uchar*) name,
-                                       strlen(name))))
+  if (!(share=(NDB_SHARE*) my_hash_search(&ndbcluster_open_tables,
+                                          (uchar*) name,
+                                          strlen(name))))
   {
     pthread_mutex_unlock(&ndbcluster_mutex);
     DBUG_PRINT("info", ("Table %s not found in ndbcluster_open_tables", name));
@@ -9512,7 +9512,7 @@ ndbcluster_cache_retrieval_allowed(THD *
   DBUG_PRINT("enter", ("dbname: %s, tabname: %s",
                        dbname, tabname));
 
-  if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
+  if (thd->in_multi_stmt_transaction())
   {
     /* Don't allow qc to be used if table has been previously
        modified in transaction */
@@ -9596,7 +9596,7 @@ ha_ndbcluster::register_query_cache_tabl
   DBUG_PRINT("enter",("dbname: %s, tabname: %s",
 		      m_dbname, m_tabname));
 
-  if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
+  if (thd->in_multi_stmt_transaction())
   {
     /* Don't allow qc to be used if table has been previously
        modified in transaction */
@@ -9680,7 +9680,7 @@ static void print_ndbcluster_open_tables
   fprintf(DBUG_FILE, ">ndbcluster_open_tables\n");
   for (uint i= 0; i < ndbcluster_open_tables.records; i++)
     print_share("",
-                (NDB_SHARE*)hash_element(&ndbcluster_open_tables, i));
+                (NDB_SHARE*)my_hash_element(&ndbcluster_open_tables, i));
   fprintf(DBUG_FILE, "<ndbcluster_open_tables\n");
   DBUG_UNLOCK_FILE;
 }
@@ -9810,7 +9810,7 @@ int handle_trailing_share(THD *thd, NDB_
     at the cost of a possible mem leak, by "renaming" the share
     - First remove from hash
   */
-  hash_delete(&ndbcluster_open_tables, (uchar*) share);
+  my_hash_delete(&ndbcluster_open_tables, (uchar*) share);
 
   /*
     now give it a new name, just a running number
@@ -9862,12 +9862,12 @@ int ndbcluster_rename_share(THD *thd, ND
   uint new_length= (uint) strlen(share->new_key);
   DBUG_PRINT("ndbcluster_rename_share", ("old_key: %s  old__length: %d",
                               share->key, share->key_length));
-  if ((tmp= (NDB_SHARE*) hash_search(&ndbcluster_open_tables,
-                                     (uchar*) share->new_key, new_length)))
+  if ((tmp= (NDB_SHARE*) my_hash_search(&ndbcluster_open_tables,
+                                        (uchar*) share->new_key, new_length)))
     handle_trailing_share(thd, tmp, have_lock_open);
 
   /* remove the share from hash */
-  hash_delete(&ndbcluster_open_tables, (uchar*) share);
+  my_hash_delete(&ndbcluster_open_tables, (uchar*) share);
   dbug_print_open_tables();
 
   /* save old stuff if insert should fail */
@@ -9969,9 +9969,9 @@ NDB_SHARE *ndbcluster_get_share(const ch
 
   if (!have_lock)
     pthread_mutex_lock(&ndbcluster_mutex);
-  if (!(share= (NDB_SHARE*) hash_search(&ndbcluster_open_tables,
-                                        (uchar*) key,
-                                        length)))
+  if (!(share= (NDB_SHARE*) my_hash_search(&ndbcluster_open_tables,
+                                           (uchar*) key,
+                                           length)))
   {
     if (!create_if_not_exists)
     {
@@ -10050,7 +10050,7 @@ void ndbcluster_real_free_share(NDB_SHAR
   if (ndb_extra_logging > 9)
     sql_print_information ("ndbcluster_real_free_share: %s use_count: %u", (*share)->key, (*share)->use_count);
 
-  hash_delete(&ndbcluster_open_tables, (uchar*) *share);
+  my_hash_delete(&ndbcluster_open_tables, (uchar*) *share);
   thr_lock_delete(&(*share)->lock);
   pthread_mutex_destroy(&(*share)->mutex);
 
@@ -10967,7 +10967,7 @@ int ha_ndbcluster::multi_range_start_ret
         if (lm == NdbOperation::LM_Read)
           options.scan_flags|= NdbScanOperation::SF_KeyInfo;
         if (mrr_is_output_sorted)
-          options.scan_flags|= NdbScanOperation::SF_OrderBy;
+          options.scan_flags|= NdbScanOperation::SF_OrderByFull;
 
         options.parallel=parallelism;
 
@@ -11533,7 +11533,7 @@ pthread_handler_t ndb_util_thread_func(v
     }
     for (i= 0, open_count= 0; i < record_count; i++)
     {
-      share= (NDB_SHARE *)hash_element(&ndbcluster_open_tables, i);
+      share= (NDB_SHARE *)my_hash_element(&ndbcluster_open_tables, i);
       if ((share->use_count - (int) (share->op != 0) - (int) (share->op != 0))
           <= 0)
         continue; // injector thread is the only user, skip statistics

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2009-02-05 12:22:39 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2009-02-09 16:27:41 +0000
@@ -996,9 +996,9 @@ static NDB_SHARE *ndbcluster_check_ndb_a
 {
   pthread_mutex_lock(&ndbcluster_mutex);
 
-  void *share= hash_search(&ndbcluster_open_tables, 
-                           (uchar*) NDB_APPLY_TABLE_FILE,
-                           sizeof(NDB_APPLY_TABLE_FILE) - 1);
+  void *share= my_hash_search(&ndbcluster_open_tables,
+                              (uchar*) NDB_APPLY_TABLE_FILE,
+                              sizeof(NDB_APPLY_TABLE_FILE) - 1);
   DBUG_PRINT("info",("ndbcluster_check_ndb_apply_status_share %s %p",
                      NDB_APPLY_TABLE_FILE, share));
   pthread_mutex_unlock(&ndbcluster_mutex);
@@ -1014,9 +1014,9 @@ static NDB_SHARE *ndbcluster_check_ndb_s
 {
   pthread_mutex_lock(&ndbcluster_mutex);
 
-  void *share= hash_search(&ndbcluster_open_tables, 
-                           (uchar*) NDB_SCHEMA_TABLE_FILE,
-                           sizeof(NDB_SCHEMA_TABLE_FILE) - 1);
+  void *share= my_hash_search(&ndbcluster_open_tables,
+                              (uchar*) NDB_SCHEMA_TABLE_FILE,
+                              sizeof(NDB_SCHEMA_TABLE_FILE) - 1);
   DBUG_PRINT("info",("ndbcluster_check_ndb_schema_share %s %p",
                      NDB_SCHEMA_TABLE_FILE, share));
   pthread_mutex_unlock(&ndbcluster_mutex);
@@ -2642,8 +2642,8 @@ ndb_binlog_thread_handle_schema_event_po
       {
         pthread_mutex_lock(&ndbcluster_mutex);
         NDB_SCHEMA_OBJECT *ndb_schema_object=
-          (NDB_SCHEMA_OBJECT*) hash_search(&ndb_schema_objects,
-                                           (uchar*) key, strlen(key));
+          (NDB_SCHEMA_OBJECT*) my_hash_search(&ndb_schema_objects,
+                                              (uchar*) key, strlen(key));
         if (ndb_schema_object)
         {
           pthread_mutex_lock(&ndb_schema_object->mutex);
@@ -3907,8 +3907,8 @@ int ndbcluster_create_binlog_setup(THD *
   pthread_mutex_lock(&ndbcluster_mutex);
 
   /* Handle any trailing share */
-  NDB_SHARE *share= (NDB_SHARE*) hash_search(&ndbcluster_open_tables,
-                                             (uchar*) key, key_len);
+  NDB_SHARE *share= (NDB_SHARE*) my_hash_search(&ndbcluster_open_tables,
+                                                (uchar*) key, key_len);
 
   if (share && share_may_exist)
   {
@@ -5257,9 +5257,9 @@ static NDB_SCHEMA_OBJECT *ndb_get_schema
   if (!have_lock)
     pthread_mutex_lock(&ndbcluster_mutex);
   while (!(ndb_schema_object=
-           (NDB_SCHEMA_OBJECT*) hash_search(&ndb_schema_objects,
-                                            (uchar*) key,
-                                            length)))
+           (NDB_SCHEMA_OBJECT*) my_hash_search(&ndb_schema_objects,
+                                               (uchar*) key,
+                                               length)))
   {
     if (!create_if_not_exists)
     {
@@ -5308,7 +5308,7 @@ static void ndb_free_schema_object(NDB_S
   if (!--(*ndb_schema_object)->use_count)
   {
     DBUG_PRINT("info", ("use_count: %d", (*ndb_schema_object)->use_count));
-    hash_delete(&ndb_schema_objects, (uchar*) *ndb_schema_object);
+    my_hash_delete(&ndb_schema_objects, (uchar*) *ndb_schema_object);
     pthread_mutex_destroy(&(*ndb_schema_object)->mutex);
     my_free((uchar*) *ndb_schema_object, MYF(0));
     *ndb_schema_object= 0;
@@ -5457,8 +5457,8 @@ restart_cluster_failure:
   }
 
   /* init hash for schema object distribution */
-  (void) hash_init(&ndb_schema_objects, system_charset_info, 32, 0, 0,
-                   (hash_get_key)ndb_schema_objects_get_key, 0, 0);
+  (void) my_hash_init(&ndb_schema_objects, system_charset_info, 32, 0, 0,
+                   (my_hash_get_key)ndb_schema_objects_get_key, 0, 0);
 
   /*
     Expose global reference to our ndb object.
@@ -6197,7 +6197,7 @@ restart_cluster_failure:
     i_ndb= 0;
   }
 
-  hash_free(&ndb_schema_objects);
+  my_hash_free(&ndb_schema_objects);
 
   if (thd_ndb)
   {

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2009-02-05 12:22:39 +0000
+++ b/sql/handler.cc	2009-02-09 16:27:41 +0000
@@ -1489,7 +1489,7 @@ static my_bool xarecover_handlerton(THD 
         }
         // recovery mode
         if (info->commit_list ?
-            hash_search(info->commit_list, (uchar *)&x, sizeof(x)) != 0 :
+            my_hash_search(info->commit_list, (uchar *)&x, sizeof(x)) != 0 :
             tc_heuristic_recover == TC_HEURISTIC_RECOVER_COMMIT)
         {
 #ifndef DBUG_OFF
@@ -1609,7 +1609,7 @@ bool mysql_xa_recover(THD *thd)
     DBUG_RETURN(1);
 
   pthread_mutex_lock(&LOCK_xid_cache);
-  while ((xs= (XID_STATE*)hash_element(&xid_cache, i++)))
+  while ((xs= (XID_STATE*) my_hash_element(&xid_cache, i++)))
   {
     if (xs->xa_state==XA_PREPARED)
     {
@@ -4366,17 +4366,20 @@ scan_it_again:
   @retval other Error
 */
 
-int DsMrr_impl::dsmrr_init(handler *h, KEY *key,
-                           RANGE_SEQ_IF *seq_funcs, void *seq_init_param,
-                           uint n_ranges, uint mode, HANDLER_BUFFER *buf)
+int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, 
+                           void *seq_init_param, uint n_ranges, uint mode,
+                           HANDLER_BUFFER *buf)
 {
   uint elem_size;
-  uint keyno;
   Item *pushed_cond= NULL;
   handler *new_h2= 0;
   DBUG_ENTER("DsMrr_impl::dsmrr_init");
-  keyno= h->active_index;
 
+  /*
+    index_merge may invoke a scan on an object for which dsmrr_info[_const]
+    has not been called, so set the owner handler here as well.
+  */
+  h= h_arg;
   if (mode & HA_MRR_USE_DEFAULT_IMPL || mode & HA_MRR_SORTED)
   {
     use_default_impl= TRUE;
@@ -4397,17 +4400,28 @@ int DsMrr_impl::dsmrr_init(handler *h, K
                       elem_size;
   rowids_buf_end= rowids_buf_last;
 
+    /*
+    There can be two cases:
+    - This is the first call since index_init(), h2==NULL
+       Need to setup h2 then.
+    - This is not the first call, h2 is initalized and set up appropriately.
+       The caller might have called h->index_init(), need to switch h to
+       rnd_pos calls.
+  */
   if (!h2)
   {
     /* Create a separate handler object to do rndpos() calls. */
     THD *thd= current_thd;
+    /*
+      ::clone() takes up a lot of stack, especially on 64 bit platforms.
+      The constant 5 is an empiric result.
+    */
+    if (check_stack_overrun(thd, 5*STACK_MIN_SIZE, (uchar*) &new_h2))
+      DBUG_RETURN(1);
+    DBUG_ASSERT(h->active_index != MAX_KEY);
+    uint mrr_keyno= h->active_index;
 
-  /*
-    ::clone() takes up a lot of stack, especially on 64 bit platforms.
-    The constant 5 is an empiric result.
-  */
-  if (check_stack_overrun(thd, 5*STACK_MIN_SIZE, (uchar*) &new_h2))
-    DBUG_RETURN(1);
+    /* Create a separate handler object to do rndpos() calls. */
     if (!(new_h2= h->clone(thd->mem_root)) || 
         new_h2->ha_external_lock(thd, F_RDLCK))
     {
@@ -4415,31 +4429,55 @@ int DsMrr_impl::dsmrr_init(handler *h, K
       DBUG_RETURN(1);
     }
 
-    if (keyno == h->pushed_idx_cond_keyno)
+    if (mrr_keyno == h->pushed_idx_cond_keyno)
       pushed_cond= h->pushed_idx_cond;
+
+    /*
+      Caution: this call will invoke this->dsmrr_close(). Do not put the
+      created secondary table handler into this->h2 or it will delete it.
+    */
     if (h->ha_index_end())
     {
-      new_h2= h2;
+      h2=new_h2;
       goto error;
     }
 
-    h2= new_h2;
+    h2= new_h2; /* Ok, now can put it into h2 */
     table->prepare_for_position();
-    new_h2->extra(HA_EXTRA_KEYREAD);
+    h2->extra(HA_EXTRA_KEYREAD);
   
-    if (h2->ha_index_init(keyno, FALSE))
+    if (h2->ha_index_init(mrr_keyno, FALSE))
+      goto error;
+
+    use_default_impl= FALSE;
+    if (pushed_cond)
+      h2->idx_cond_push(mrr_keyno, pushed_cond);
+  }
+  else
+  {
+    /* 
+      We get here when the access alternates betwen MRR scan(s) and non-MRR
+      scans.
+
+      Calling h->index_end() will invoke dsmrr_close() for this object,
+      which will delete h2. We need to keep it, so save put it away and dont
+      let it be deleted:
+    */
+    handler *save_h2= h2;
+    h2= NULL;
+    int res= (h->inited == handler::INDEX && h->ha_index_end());
+    h2= save_h2;
+    use_default_impl= FALSE;
+    if (res)
       goto error;
   }
 
   if (h2->handler::multi_range_read_init(seq_funcs, seq_init_param, n_ranges,
-                                         mode, buf))
-    goto error;
-  
-  if (pushed_cond)
-    h2->idx_cond_push(keyno, pushed_cond);
-  if (dsmrr_fill_buffer(new_h2))
+                                          mode, buf) || 
+      dsmrr_fill_buffer())
+  {
     goto error;
-
+  }
   /*
     If the above call has scanned through all intervals in *seq, then
     adjust *buf to indicate that the remaining buffer space will not be used.
@@ -4508,7 +4546,7 @@ static int rowid_cmp(void *h, uchar *a, 
   @retval other  Error
 */
 
-int DsMrr_impl::dsmrr_fill_buffer(handler *unused)
+int DsMrr_impl::dsmrr_fill_buffer()
 {
   char *range_info;
   int res;
@@ -4555,7 +4593,7 @@ int DsMrr_impl::dsmrr_fill_buffer(handle
   DS-MRR implementation: multi_range_read_next() function
 */
 
-int DsMrr_impl::dsmrr_next(handler *h, char **range_info)
+int DsMrr_impl::dsmrr_next(char **range_info)
 {
   int res;
   uchar *cur_range_info= 0;
@@ -4573,8 +4611,7 @@ int DsMrr_impl::dsmrr_next(handler *h, c
         res= HA_ERR_END_OF_FILE;
         goto end;
       }
-
-      res= dsmrr_fill_buffer(h);
+    res= dsmrr_fill_buffer();
       if (res)
         goto end;
     }

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2009-02-05 11:03:46 +0000
+++ b/sql/handler.h	2009-02-09 16:27:41 +0000
@@ -2494,14 +2494,15 @@ public:
 
   DsMrr_impl()
     : h2(NULL) {};
-
-  handler *h; /* The "owner" handler object. It is used for scanning the index */
-  TABLE *table; /* Always equal to h->table */
-private:
+  
   /*
-    Secondary handler object. It is used to retrieve full table rows by
-    calling rnd_pos().
+    The "owner" handler object (the one that calls dsmrr_XXX functions.
+    It is used to retrieve full table rows by calling rnd_pos().
   */
+  handler *h;
+  TABLE *table; /* Always equal to h->table */
+private:
+  /* Secondary handler object.  It is used for scanning the index */
   handler *h2;
 
   /* Buffer to store rowids, or (rowid, range_id) pairs */
@@ -2522,12 +2523,11 @@ public:
     h= h_arg; 
     table= table_arg;
   }
-  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs, 
-                 void *seq_init_param, uint n_ranges, uint mode, 
-                 HANDLER_BUFFER *buf);
+  int dsmrr_init(handler *h, RANGE_SEQ_IF *seq_funcs, void *seq_init_param, 
+                 uint n_ranges, uint mode, HANDLER_BUFFER *buf);
   void dsmrr_close();
-  int dsmrr_fill_buffer(handler *h);
-  int dsmrr_next(handler *h, char **range_info);
+  int dsmrr_fill_buffer();
+  int dsmrr_next(char **range_info);
 
   ha_rows dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz,
                      uint *flags, COST_VECT *cost);

=== modified file 'sql/hash_filo.h'
--- a/sql/hash_filo.h	2007-05-10 09:59:39 +0000
+++ b/sql/hash_filo.h	2009-01-27 02:08:48 +0000
@@ -38,8 +38,8 @@ class hash_filo_element
 class hash_filo
 {
   const uint size, key_offset, key_length;
-  const hash_get_key get_key;
-  hash_free_key free_element;
+  const my_hash_get_key get_key;
+  my_hash_free_key free_element;
   bool init;
   CHARSET_INFO *hash_charset;
 
@@ -49,7 +49,7 @@ public:
   HASH cache;
 
   hash_filo(uint size_arg, uint key_offset_arg , uint key_length_arg,
-	    hash_get_key get_key_arg, hash_free_key free_element_arg,
+	    my_hash_get_key get_key_arg, my_hash_free_key free_element_arg,
 	    CHARSET_INFO *hash_charset_arg)
     :size(size_arg), key_offset(key_offset_arg), key_length(key_length_arg),
     get_key(get_key_arg), free_element(free_element_arg),init(0),
@@ -63,7 +63,7 @@ public:
     if (init)
     {
       if (cache.array.buffer)	/* Avoid problems with thread library */
-	(void) hash_free(&cache);
+	(void) my_hash_free(&cache);
       pthread_mutex_destroy(&lock);
     }
   }
@@ -76,8 +76,8 @@ public:
     }
     if (!locked)
       (void) pthread_mutex_lock(&lock);
-    (void) hash_free(&cache);
-    (void) hash_init(&cache,hash_charset,size,key_offset, 
+    (void) my_hash_free(&cache);
+    (void) my_hash_init(&cache,hash_charset,size,key_offset, 
     		     key_length, get_key, free_element,0);
     if (!locked)
       (void) pthread_mutex_unlock(&lock);
@@ -87,7 +87,7 @@ public:
   hash_filo_element *search(uchar* key, size_t length)
   {
     hash_filo_element *entry=(hash_filo_element*)
-      hash_search(&cache,(uchar*) key,length);
+      my_hash_search(&cache,(uchar*) key,length);
     if (entry)
     {						// Found; link it first
       if (entry != first_link)
@@ -113,7 +113,7 @@ public:
     {
       hash_filo_element *tmp=last_link;
       last_link=last_link->prev_used;
-      hash_delete(&cache,(uchar*) tmp);
+      my_hash_delete(&cache,(uchar*) tmp);
     }
     if (my_hash_insert(&cache,(uchar*) entry))
     {

=== modified file 'sql/hostname.cc'
--- a/sql/hostname.cc	2008-12-13 20:01:27 +0000
+++ b/sql/hostname.cc	2009-01-27 02:08:48 +0000
@@ -61,7 +61,7 @@ bool hostname_cache_init()
   uint offset= (uint) ((char*) (&tmp.ip) - (char*) &tmp);
   if (!(hostname_cache=new hash_filo(HOST_CACHE_SIZE, offset,
 				     sizeof(struct sockaddr_storage),NULL,
-				     (hash_free_key) free,
+				     (my_hash_free_key) free,
 				     &my_charset_bin)))
     return 1;
   hostname_cache->clear();

=== modified file 'sql/item_create.cc'
--- a/sql/item_create.cc	2008-12-14 11:36:15 +0000
+++ b/sql/item_create.cc	2009-01-27 02:08:48 +0000
@@ -4959,14 +4959,14 @@ int item_create_init()
 
   DBUG_ENTER("item_create_init");
 
-  if (hash_init(& native_functions_hash,
-                system_charset_info,
-                array_elements(func_array),
-                0,
-                0,
-                (hash_get_key) get_native_fct_hash_key,
-                NULL,                          /* Nothing to free */
-                MYF(0)))
+  if (my_hash_init(& native_functions_hash,
+                   system_charset_info,
+                   array_elements(func_array),
+                   0,
+                   0,
+                   (my_hash_get_key) get_native_fct_hash_key,
+                   NULL,                          /* Nothing to free */
+                   MYF(0)))
     DBUG_RETURN(1);
 
   for (func= func_array; func->builder != NULL; func++)
@@ -4978,7 +4978,7 @@ int item_create_init()
 #ifndef DBUG_OFF
   for (uint i=0 ; i < native_functions_hash.records ; i++)
   {
-    func= (Native_func_registry*) hash_element(& native_functions_hash, i);
+    func= (Native_func_registry*) my_hash_element(& native_functions_hash, i);
     DBUG_PRINT("info", ("native function: %s  length: %u",
                         func->name.str, (uint) func->name.length));
   }
@@ -4996,7 +4996,7 @@ int item_create_init()
 void item_create_cleanup()
 {
   DBUG_ENTER("item_create_cleanup");
-  hash_free(& native_functions_hash);
+  my_hash_free(& native_functions_hash);
   DBUG_VOID_RETURN;
 }
 
@@ -5007,9 +5007,9 @@ find_native_function_builder(THD *thd, L
   Create_func *builder= NULL;
 
   /* Thread safe */
-  func= (Native_func_registry*) hash_search(& native_functions_hash,
-                                            (uchar*) name.str,
-                                             name.length);
+  func= (Native_func_registry*) my_hash_search(& native_functions_hash,
+                                               (uchar*) name.str,
+                                               name.length);
 
   if (func)
   {

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2009-02-05 12:22:39 +0000
+++ b/sql/item_func.cc	2009-02-09 16:27:41 +0000
@@ -3329,7 +3329,7 @@ public:
   {
     if (key)
     {
-      hash_delete(&hash_user_locks,(uchar*) this);
+      my_hash_delete(&hash_user_locks,(uchar*) this);
       my_free(key, MYF(0));
     }
     pthread_cond_destroy(&cond);
@@ -3353,8 +3353,8 @@ static bool item_user_lock_inited= 0;
 void item_user_lock_init(void)
 {
   pthread_mutex_init(&LOCK_user_locks,MY_MUTEX_INIT_SLOW);
-  hash_init(&hash_user_locks,system_charset_info,
-	    16,0,0,(hash_get_key) ull_get_key,NULL,0);
+  my_hash_init(&hash_user_locks,system_charset_info,
+	    16,0,0,(my_hash_get_key) ull_get_key,NULL,0);
   item_user_lock_inited= 1;
 }
 
@@ -3363,7 +3363,7 @@ void item_user_lock_free(void)
   if (item_user_lock_inited)
   {
     item_user_lock_inited= 0;
-    hash_free(&hash_user_locks);
+    my_hash_free(&hash_user_locks);
     pthread_mutex_destroy(&LOCK_user_locks);
   }
 }
@@ -3444,9 +3444,9 @@ void debug_sync_point(const char* lock_n
     this case, we will not be waiting, but rather, just waste CPU and
     memory on the whole deal
   */
-  if (!(ull= ((User_level_lock*) hash_search(&hash_user_locks,
-                                             (uchar*) lock_name,
-                                             lock_name_len))))
+  if (!(ull= ((User_level_lock*) my_hash_search(&hash_user_locks,
+                                                (uchar*) lock_name,
+                                                lock_name_len))))
   {
     pthread_mutex_unlock(&LOCK_user_locks);
     DBUG_VOID_RETURN;
@@ -3597,9 +3597,9 @@ longlong Item_func_get_lock::val_int()
     thd->ull=0;
   }
 
-  if (!(ull= ((User_level_lock *) hash_search(&hash_user_locks,
-                                              (uchar*) res->ptr(),
-                                              (size_t) res->length()))))
+  if (!(ull= ((User_level_lock *) my_hash_search(&hash_user_locks,
+                                                 (uchar*) res->ptr(),
+                                                 (size_t) res->length()))))
   {
     ull= new User_level_lock((uchar*) res->ptr(), (size_t) res->length(),
                              thd->thread_id);
@@ -3700,9 +3700,9 @@ longlong Item_func_release_lock::val_int
 
   result=0;
   pthread_mutex_lock(&LOCK_user_locks);
-  if (!(ull= ((User_level_lock*) hash_search(&hash_user_locks,
-                                             (const uchar*) res->ptr(),
-                                             (size_t) res->length()))))
+  if (!(ull= ((User_level_lock*) my_hash_search(&hash_user_locks,
+                                                (const uchar*) res->ptr(),
+                                                (size_t) res->length()))))
   {
     null_value=1;
   }
@@ -3880,12 +3880,12 @@ static user_var_entry *get_variable(HASH
 {
   user_var_entry *entry;
 
-  if (!(entry = (user_var_entry*) hash_search(hash, (uchar*) name.str,
-					      name.length)) &&
+  if (!(entry = (user_var_entry*) my_hash_search(hash, (uchar*) name.str,
+                                                 name.length)) &&
       create_if_not_exists)
   {
     uint size=ALIGN_SIZE(sizeof(user_var_entry))+name.length+1+extra_size;
-    if (!hash_inited(hash))
+    if (!my_hash_inited(hash))
       return 0;
     if (!(entry = (user_var_entry*) my_malloc(size,MYF(MY_WME | ME_FATALERROR))))
       return 0;
@@ -5755,8 +5755,8 @@ longlong Item_func_is_free_lock::val_int
   }
   
   pthread_mutex_lock(&LOCK_user_locks);
-  ull= (User_level_lock *) hash_search(&hash_user_locks, (uchar*) res->ptr(),
-                                       (size_t) res->length());
+  ull= (User_level_lock *) my_hash_search(&hash_user_locks, (uchar*) res->ptr(),
+                                          (size_t) res->length());
   pthread_mutex_unlock(&LOCK_user_locks);
   if (!ull || !ull->locked)
     return 1;
@@ -5774,8 +5774,8 @@ longlong Item_func_is_used_lock::val_int
     return 0;
   
   pthread_mutex_lock(&LOCK_user_locks);
-  ull= (User_level_lock *) hash_search(&hash_user_locks, (uchar*) res->ptr(),
-                                       (size_t) res->length());
+  ull= (User_level_lock *) my_hash_search(&hash_user_locks, (uchar*) res->ptr(),
+                                          (size_t) res->length());
   pthread_mutex_unlock(&LOCK_user_locks);
   if (!ull || !ull->locked)
     return 0;

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2009-02-05 12:22:39 +0000
+++ b/sql/log.cc	2009-02-09 16:27:41 +0000
@@ -2647,7 +2647,7 @@ binlog_end_trans(THD *thd, binlog_trx_da
       transaction cache to remove the statement.
      */
     thd->binlog_remove_pending_rows_event(TRUE);
-    if (all || !(thd->options & (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT)))
+    if (all || !thd->in_multi_stmt_transaction())
     {
       trx_data->reset();
 
@@ -2716,8 +2716,7 @@ static int binlog_commit(handlerton *hto
 
     Otherwise, we accumulate the statement
   */
-  ulonglong const in_transaction=
-    thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
+  bool const in_transaction= thd->in_multi_stmt_transaction();
   DBUG_PRINT("debug",
              ("all: %d, empty: %s, in_transaction: %s, all.modified_non_trans_table: %s, stmt.modified_non_trans_table: %s",
               all,
@@ -5527,7 +5526,7 @@ THD::binlog_start_trans_and_stmt()
       trx_data->before_stmt_pos == MY_OFF_T_UNDEF)
   {
     this->binlog_set_stmt_begin();
-    if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
+    if (in_multi_stmt_transaction())
       trans_register_ha(this, TRUE, binlog_hton);
     trans_register_ha(this, FALSE, binlog_hton);
     /*
@@ -7150,8 +7149,8 @@ int TC_LOG_MMAP::recover()
     goto err1;
   }
 
-  if (hash_init(&xids, &my_charset_bin, tc_log_page_size/3, 0,
-                sizeof(my_xid), 0, 0, MYF(0)))
+  if (my_hash_init(&xids, &my_charset_bin, tc_log_page_size/3, 0,
+                   sizeof(my_xid), 0, 0, MYF(0)))
     goto err1;
 
   for ( ; p < end_p ; p++)
@@ -7164,12 +7163,12 @@ int TC_LOG_MMAP::recover()
   if (ha_recover(&xids))
     goto err2;
 
-  hash_free(&xids);
+  my_hash_free(&xids);
   bzero(data, (size_t)file_length);
   return 0;
 
 err2:
-  hash_free(&xids);
+  my_hash_free(&xids);
 err1:
   sql_print_error("Crash recovery failed. Either correct the problem "
                   "(if it's, for example, out of memory error) and restart, "
@@ -7353,8 +7352,8 @@ int TC_LOG_BINLOG::recover(IO_CACHE *log
   MEM_ROOT mem_root;
 
   if (! fdle->is_valid() ||
-      hash_init(&xids, &my_charset_bin, TC_LOG_PAGE_SIZE/3, 0,
-                sizeof(my_xid), 0, 0, MYF(0)))
+      my_hash_init(&xids, &my_charset_bin, TC_LOG_PAGE_SIZE/3, 0,
+                   sizeof(my_xid), 0, 0, MYF(0)))
     goto err1;
 
   init_alloc_root(&mem_root, TC_LOG_PAGE_SIZE, TC_LOG_PAGE_SIZE);
@@ -7379,12 +7378,12 @@ int TC_LOG_BINLOG::recover(IO_CACHE *log
     goto err2;
 
   free_root(&mem_root, MYF(0));
-  hash_free(&xids);
+  my_hash_free(&xids);
   return 0;
 
 err2:
   free_root(&mem_root, MYF(0));
-  hash_free(&xids);
+  my_hash_free(&xids);
 err1:
   sql_print_error("Crash recovery failed. Either correct the problem "
                   "(if it's, for example, out of memory error) and restart, "

=== modified file 'sql/mdl.cc'
--- a/sql/mdl.cc	2008-12-17 10:11:14 +0000
+++ b/sql/mdl.cc	2009-01-27 13:41:58 +0000
@@ -119,8 +119,8 @@ void mdl_init()
   mdl_initialized= 1;
   pthread_mutex_init(&LOCK_mdl, NULL);
   pthread_cond_init(&COND_mdl, NULL);
-  hash_init(&mdl_locks, &my_charset_bin, 16 /* FIXME */, 0, 0,
-            mdl_locks_key, 0, 0);
+  my_hash_init(&mdl_locks, &my_charset_bin, 16 /* FIXME */, 0, 0,
+               mdl_locks_key, 0, 0);
   global_lock.waiting_shared= global_lock.active_shared= 0;
   global_lock.active_intention_exclusive= 0;
 }
@@ -141,7 +141,7 @@ void mdl_destroy()
     DBUG_ASSERT(!mdl_locks.records);
     pthread_mutex_destroy(&LOCK_mdl);
     pthread_cond_destroy(&COND_mdl);
-    hash_free(&mdl_locks);
+    my_hash_free(&mdl_locks);
   }
 }
 
@@ -740,8 +740,8 @@ bool mdl_acquire_shared_lock(MDL_CONTEXT
     return TRUE;
   }
 
-  if (!(lock= (MDL_LOCK *)hash_search(&mdl_locks, (uchar*)lock_data->key,
-                                      lock_data->key_length)))
+  if (!(lock= (MDL_LOCK*) my_hash_search(&mdl_locks, (uchar*)lock_data->key,
+                                         lock_data->key_length)))
   {
     if (!(lock= get_lock_object()))
     {
@@ -829,8 +829,8 @@ bool mdl_acquire_exclusive_locks(MDL_CON
   {
     DBUG_ASSERT(lock_data->type == MDL_EXCLUSIVE &&
                 lock_data->state == MDL_INITIALIZED);
-    if (!(lock= (MDL_LOCK *)hash_search(&mdl_locks, (uchar*)lock_data->key,
-                                        lock_data->key_length)))
+    if (!(lock= (MDL_LOCK*) my_hash_search(&mdl_locks, (uchar*)lock_data->key,
+                                           lock_data->key_length)))
     {
       if (!(lock= get_lock_object()))
         goto err;
@@ -1105,8 +1105,8 @@ bool mdl_try_acquire_exclusive_lock(MDL_
 
   pthread_mutex_lock(&LOCK_mdl);
 
-  if (!(lock= (MDL_LOCK *)hash_search(&mdl_locks, (uchar*)lock_data->key,
-                                      lock_data->key_length)))
+  if (!(lock= (MDL_LOCK*) my_hash_search(&mdl_locks, (uchar*)lock_data->key,
+                                         lock_data->key_length)))
   {
     if (!(lock= get_lock_object()))
       goto err;
@@ -1227,8 +1227,8 @@ bool mdl_wait_for_locks(MDL_CONTEXT *con
         request for MDL_EXCLUSIVE lock.
       */
       if (is_shared(lock_data) &&
-          (lock= (MDL_LOCK *)hash_search(&mdl_locks, (uchar*)lock_data->key,
-                                         lock_data->key_length)) &&
+          (lock= (MDL_LOCK*) my_hash_search(&mdl_locks, (uchar*)lock_data->key,
+                                            lock_data->key_length)) &&
           !can_grant_lock(lock, lock_data))
         break;
     }
@@ -1264,7 +1264,7 @@ static void release_lock(MDL_LOCK_DATA *
   lock= lock_data->lock;
   if (lock->has_one_lock_data())
   {
-    hash_delete(&mdl_locks, (uchar *)lock);
+    my_hash_delete(&mdl_locks, (uchar *)lock);
     DBUG_PRINT("info", ("releasing cached_object cached_object=%p",
                         lock->cached_object));
     if (lock->cached_object)
@@ -1330,10 +1330,11 @@ void mdl_release_locks(MDL_CONTEXT *cont
   {
     DBUG_PRINT("info", ("found lock to release lock_data=%p", lock_data));
     /*
-      We should not release locks which pending shared locks as these
-      are not associated with lock object and don't present in its
-      lists. Allows us to avoid problems in open_tables() in case of
-      back-off
+      Don't call release_lock() for a shared lock if has not been
+      granted. Lock state in this case is MDL_INITIALIZED.
+      We have pending and granted shared locks in the same context
+      when this function is called from the "back-off" path of
+      open_tables().
     */
     if (lock_data->state != MDL_INITIALIZED)
     {

=== modified file 'sql/repl_failsafe.cc'
--- a/sql/repl_failsafe.cc	2009-01-27 13:03:36 +0000
+++ b/sql/repl_failsafe.cc	2009-02-09 16:27:41 +0000
@@ -146,10 +146,10 @@ void unregister_slave(THD* thd, bool onl
       pthread_mutex_lock(&LOCK_slave_list);
 
     SLAVE_INFO* old_si;
-    if ((old_si = (SLAVE_INFO*)hash_search(&slave_list,
-					   (uchar*)&thd->server_id, 4)) &&
+    if ((old_si = (SLAVE_INFO*)my_hash_search(&slave_list,
+                                              (uchar*)&thd->server_id, 4)) &&
 	(!only_mine || old_si->thd == thd))
-    hash_delete(&slave_list, (uchar*)old_si);
+    my_hash_delete(&slave_list, (uchar*)old_si);
 
     if (need_mutex)
       pthread_mutex_unlock(&LOCK_slave_list);
@@ -221,17 +221,18 @@ extern "C" void slave_info_free(void *s)
 
 void init_slave_list()
 {
-  hash_init(&slave_list, system_charset_info, SLAVE_LIST_CHUNK, 0, 0,
-	    (hash_get_key) slave_list_key, (hash_free_key) slave_info_free, 0);
+  my_hash_init(&slave_list, system_charset_info, SLAVE_LIST_CHUNK, 0, 0,
+               (my_hash_get_key) slave_list_key,
+               (my_hash_free_key) slave_info_free, 0);
   pthread_mutex_init(&LOCK_slave_list, MY_MUTEX_INIT_FAST);
 }
 
 void end_slave_list()
 {
   /* No protection by a mutex needed as we are only called at shutdown */
-  if (hash_inited(&slave_list))
+  if (my_hash_inited(&slave_list))
   {
-    hash_free(&slave_list);
+    my_hash_free(&slave_list);
     pthread_mutex_destroy(&LOCK_slave_list);
   }
 }
@@ -547,8 +548,8 @@ HOSTS";
     uint32 log_server_id;
     SLAVE_INFO* si, *old_si;
     log_server_id = atoi(row[0]);
-    if ((old_si= (SLAVE_INFO*)hash_search(&slave_list,
-					  (uchar*)&log_server_id,4)))
+    if ((old_si= (SLAVE_INFO*)my_hash_search(&slave_list,
+                                             (uchar*)&log_server_id,4)))
       si = old_si;
     else
     {
@@ -682,7 +683,7 @@ bool show_slave_hosts(THD* thd)
 
   for (uint i = 0; i < slave_list.records; ++i)
   {
-    SLAVE_INFO* si = (SLAVE_INFO*) hash_element(&slave_list, i);
+    SLAVE_INFO* si = (SLAVE_INFO*) my_hash_element(&slave_list, i);
     protocol->prepare_for_resend();
     protocol->store((uint32) si->server_id);
     protocol->store(si->host, &my_charset_bin);

=== modified file 'sql/rpl_filter.cc'
--- a/sql/rpl_filter.cc	2008-02-07 18:51:50 +0000
+++ b/sql/rpl_filter.cc	2009-01-27 02:08:48 +0000
@@ -32,9 +32,9 @@ Rpl_filter::Rpl_filter() : 
 Rpl_filter::~Rpl_filter() 
 {
   if (do_table_inited) 
-    hash_free(&do_table);
+    my_hash_free(&do_table);
   if (ignore_table_inited)
-    hash_free(&ignore_table);
+    my_hash_free(&ignore_table);
   if (wild_do_table_inited)
     free_string_array(&wild_do_table);
   if (wild_ignore_table_inited)
@@ -103,12 +103,12 @@ Rpl_filter::tables_ok(const char* db, TA
     len= (uint) (strmov(end, tables->table_name) - hash_key);
     if (do_table_inited) // if there are any do's
     {
-      if (hash_search(&do_table, (uchar*) hash_key, len))
+      if (my_hash_search(&do_table, (uchar*) hash_key, len))
 	DBUG_RETURN(1);
     }
     if (ignore_table_inited) // if there are any ignores
     {
-      if (hash_search(&ignore_table, (uchar*) hash_key, len))
+      if (my_hash_search(&ignore_table, (uchar*) hash_key, len))
 	DBUG_RETURN(0); 
     }
     if (wild_do_table_inited && 
@@ -388,7 +388,7 @@ void free_table_ent(void* a)
 void 
 Rpl_filter::init_table_rule_hash(HASH* h, bool* h_inited)
 {
-  hash_init(h, system_charset_info,TABLE_RULE_HASH_SIZE,0,0,
+  my_hash_init(h, system_charset_info,TABLE_RULE_HASH_SIZE,0,0,
 	    get_table_key, free_table_ent, 0);
   *h_inited = 1;
 }
@@ -459,7 +459,7 @@ Rpl_filter::table_rule_ent_hash_to_str(S
   {
     for (uint i= 0; i < h->records; i++)
     {
-      TABLE_RULE_ENT* e= (TABLE_RULE_ENT*) hash_element(h, i);
+      TABLE_RULE_ENT* e= (TABLE_RULE_ENT*) my_hash_element(h, i);
       if (s->length())
         s->append(',');
       s->append(e->db,e->key_len);

=== modified file 'sql/rpl_handler.cc'
--- a/sql/rpl_handler.cc	2008-10-24 07:03:30 +0000
+++ b/sql/rpl_handler.cc	2009-01-27 02:08:48 +0000
@@ -43,9 +43,9 @@ int get_user_var_int(const char *name,
                      long long int *value, int *null_value)
 {
   my_bool null_val;
-  user_var_entry *entry= 
-    (user_var_entry*) hash_search(&current_thd->user_vars,
-                                  (uchar*) name, strlen(name));
+  user_var_entry *entry=
+    (user_var_entry*) my_hash_search(&current_thd->user_vars,
+                                     (uchar*) name, strlen(name));
   if (!entry)
     return 1;
   *value= entry->val_int(&null_val);
@@ -58,9 +58,9 @@ int get_user_var_real(const char *name,
                       double *value, int *null_value)
 {
   my_bool null_val;
-  user_var_entry *entry= 
-    (user_var_entry*) hash_search(&current_thd->user_vars,
-                                  (uchar*) name, strlen(name));
+  user_var_entry *entry=
+    (user_var_entry*) my_hash_search(&current_thd->user_vars,
+                                     (uchar*) name, strlen(name));
   if (!entry)
     return 1;
   *value= entry->val_real(&null_val);
@@ -74,9 +74,9 @@ int get_user_var_str(const char *name, c
 {
   String str;
   my_bool null_val;
-  user_var_entry *entry= 
-    (user_var_entry*) hash_search(&current_thd->user_vars,
-                                  (uchar*) name, strlen(name));
+  user_var_entry *entry=
+    (user_var_entry*) my_hash_search(&current_thd->user_vars,
+                                     (uchar*) name, strlen(name));
   if (!entry)
     return 1;
   entry->val_str(&null_val, &str, precision);

=== modified file 'sql/rpl_tblmap.cc'
--- a/sql/rpl_tblmap.cc	2008-09-04 18:30:34 +0000
+++ b/sql/rpl_tblmap.cc	2009-01-27 02:08:48 +0000
@@ -34,10 +34,10 @@ table_mapping::table_mapping()
     No "free_element" function for entries passed here, as the entries are
     allocated in a MEM_ROOT (freed as a whole in the destructor), they cannot
     be freed one by one.
-    Note that below we don't test if hash_init() succeeded. This constructor
-    is called at startup only.
+    Note that below we don't test if my_hash_init() succeeded. This
+    constructor is called at startup only.
   */
-  (void) hash_init(&m_table_ids,&my_charset_bin,TABLE_ID_HASH_SIZE,
+  (void) my_hash_init(&m_table_ids,&my_charset_bin,TABLE_ID_HASH_SIZE,
 		   offsetof(entry,table_id),sizeof(ulong),
 		   0,0,0);
   /* We don't preallocate any block, this is consistent with m_free=0 above */
@@ -49,7 +49,7 @@ table_mapping::~table_mapping()
 #ifdef MYSQL_CLIENT
   clear_tables();
 #endif
-  hash_free(&m_table_ids);
+  my_hash_free(&m_table_ids);
   free_root(&m_mem_root, MYF(0));
 }
 
@@ -115,7 +115,7 @@ int table_mapping::set_table(ulong table
 #ifdef MYSQL_CLIENT
     free_table_map_log_event(e->table);
 #endif
-    hash_delete(&m_table_ids,(uchar *)e);
+    my_hash_delete(&m_table_ids,(uchar *)e);
   }
   e->table_id= table_id;
   e->table= table;
@@ -132,7 +132,7 @@ int table_mapping::remove_table(ulong ta
   entry *e= find_entry(table_id);
   if (e)
   {
-    hash_delete(&m_table_ids,(uchar *)e);
+    my_hash_delete(&m_table_ids,(uchar *)e);
     /* we add this entry to the chain of free (free for use) entries */
     e->next= m_free;
     m_free= e;
@@ -150,7 +150,7 @@ void table_mapping::clear_tables()
   DBUG_ENTER("table_mapping::clear_tables()");
   for (uint i= 0; i < m_table_ids.records; i++)
   {
-    entry *e= (entry *)hash_element(&m_table_ids, i);
+    entry *e= (entry *)my_hash_element(&m_table_ids, i);
 #ifdef MYSQL_CLIENT
     free_table_map_log_event(e->table);
 #endif

=== modified file 'sql/rpl_tblmap.h'
--- a/sql/rpl_tblmap.h	2008-09-04 18:30:34 +0000
+++ b/sql/rpl_tblmap.h	2009-01-27 02:08:48 +0000
@@ -90,9 +90,9 @@ private:
 
   entry *find_entry(ulong table_id)
   {
-    return (entry *)hash_search(&m_table_ids,
-				(uchar*)&table_id,
-				sizeof(table_id));
+    return (entry *) my_hash_search(&m_table_ids,
+                                    (uchar*)&table_id,
+                                    sizeof(table_id));
   }
   int expand();
 

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2009-02-05 12:22:39 +0000
+++ b/sql/set_var.cc	2009-02-09 16:27:41 +0000
@@ -3705,7 +3705,7 @@ int mysql_add_sys_var_chain(sys_var *fir
 
 error:
   for (; first != var; first= first->next)
-    hash_delete(&system_variable_hash, (uchar*) first);
+    my_hash_delete(&system_variable_hash, (uchar*) first);
   return 1;
 }
  
@@ -3729,7 +3729,7 @@ int mysql_del_sys_var_chain(sys_var *fir
   /* A write lock should be held on LOCK_system_variables_hash */
    
   for (sys_var *var= first; var; var= var->next)
-    result|= hash_delete(&system_variable_hash, (uchar*) var);
+    result|= my_hash_delete(&system_variable_hash, (uchar*) var);
 
   return result;
 }
@@ -3766,7 +3766,7 @@ SHOW_VAR* enumerate_sys_vars(THD *thd, b
 
     for (i= 0; i < count; i++)
     {
-      sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
+      sys_var *var= (sys_var*) my_hash_element(&system_variable_hash, i);
       show->name= var->name;
       show->value= (char*) var;
       show->type= SHOW_SYS;
@@ -3803,8 +3803,8 @@ int set_var_init()
   
   for (sys_var *var=vars.first; var; var= var->next, count++) {}
 
-  if (hash_init(&system_variable_hash, system_charset_info, count, 0,
-                0, (hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
+  if (my_hash_init(&system_variable_hash, system_charset_info, count, 0,
+                   0, (my_hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
     goto error;
 
   vars.last->next= NULL;
@@ -3829,7 +3829,7 @@ error:
 
 void set_var_free()
 {
-  hash_free(&system_variable_hash);
+  my_hash_free(&system_variable_hash);
 }
 
 
@@ -3855,7 +3855,7 @@ sys_var *intern_find_sys_var(const char 
     This function is only called from the sql_plugin.cc.
     A lock on LOCK_system_variable_hash should be held
   */
-  var= (sys_var*) hash_search(&system_variable_hash,
+  var= (sys_var*) my_hash_search(&system_variable_hash,
 			      (uchar*) str, length ? length : strlen(str));
   if (!(var || no_error))
     my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);

=== modified file 'sql/si_objects.cc'
--- a/sql/si_objects.cc	2009-01-29 21:17:59 +0000
+++ b/sql/si_objects.cc	2009-02-04 10:49:16 +0000
@@ -1492,16 +1492,16 @@ Iterator *View_base_obj_iterator::create
 inline View_base_obj_iterator::View_base_obj_iterator()
   :m_cur_idx(0)
 {
-  hash_init(&m_table_names, system_charset_info, 16, 0, 0,
-            get_table_name_key, free_table_name_key,
-            MYF(0));
+  my_hash_init(&m_table_names, system_charset_info, 16, 0, 0,
+               get_table_name_key, free_table_name_key,
+               MYF(0));
 }
 
 ///////////////////////////////////////////////////////////////////////////
 
 inline View_base_obj_iterator::~View_base_obj_iterator()
 {
-  hash_free(&m_table_names);
+  my_hash_free(&m_table_names);
 }
 
 
@@ -1631,7 +1631,7 @@ Obj *View_base_obj_iterator::next()
     return NULL;
 
   Table_name_key *table_name_key=
-    (Table_name_key *) hash_element(&m_table_names, m_cur_idx);
+    (Table_name_key *) my_hash_element(&m_table_names, m_cur_idx);
 
   ++m_cur_idx;
 

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2009-01-06 10:38:47 +0000
+++ b/sql/sp.cc	2009-01-27 02:08:48 +0000
@@ -1490,11 +1490,11 @@ static bool add_used_routine(LEX *lex, Q
                              const LEX_STRING *key,
                              TABLE_LIST *belong_to_view)
 {
-  hash_init_opt(&lex->sroutines, system_charset_info,
-                Query_tables_list::START_SROUTINES_HASH_SIZE,
-                0, 0, sp_sroutine_key, 0, 0);
+  my_hash_init_opt(&lex->sroutines, system_charset_info,
+                   Query_tables_list::START_SROUTINES_HASH_SIZE,
+                   0, 0, sp_sroutine_key, 0, 0);
 
-  if (!hash_search(&lex->sroutines, (uchar *)key->str, key->length))
+  if (!my_hash_search(&lex->sroutines, (uchar *)key->str, key->length))
   {
     Sroutine_hash_entry *rn=
       (Sroutine_hash_entry *)arena->alloc(sizeof(Sroutine_hash_entry) +
@@ -1559,7 +1559,7 @@ void sp_remove_not_own_routines(LEX *lex
       but we want to be more future-proof.
     */
     next_rt= not_own_rt->next;
-    hash_delete(&lex->sroutines, (uchar *)not_own_rt);
+    my_hash_delete(&lex->sroutines, (uchar *)not_own_rt);
   }
 
   *(Sroutine_hash_entry **)lex->sroutines_list_own_last= NULL;
@@ -1588,8 +1588,8 @@ void sp_update_sp_used_routines(HASH *ds
 {
   for (uint i=0 ; i < src->records ; i++)
   {
-    Sroutine_hash_entry *rt= (Sroutine_hash_entry *)hash_element(src, i);
-    if (!hash_search(dst, (uchar *)rt->key.str, rt->key.length))
+    Sroutine_hash_entry *rt= (Sroutine_hash_entry *)my_hash_element(src, i);
+    if (!my_hash_search(dst, (uchar *)rt->key.str, rt->key.length))
       my_hash_insert(dst, (uchar *)rt);
   }
 }
@@ -1615,7 +1615,7 @@ sp_update_stmt_used_routines(THD *thd, L
 {
   for (uint i=0 ; i < src->records ; i++)
   {
-    Sroutine_hash_entry *rt= (Sroutine_hash_entry *)hash_element(src, i);
+    Sroutine_hash_entry *rt= (Sroutine_hash_entry *)my_hash_element(src, i);
     (void)add_used_routine(lex, thd->stmt_arena, &rt->key, belong_to_view);
   }
 }

=== modified file 'sql/sp_cache.cc'
--- a/sql/sp_cache.cc	2008-12-02 22:02:52 +0000
+++ b/sql/sp_cache.cc	2009-01-27 02:08:48 +0000
@@ -44,7 +44,8 @@ public:
 
   inline sp_head *lookup(char *name, uint namelen)
   {
-    return (sp_head *)hash_search(&m_hashtable, (const uchar *)name, namelen);
+    return (sp_head *) my_hash_search(&m_hashtable, (const uchar *)name,
+                                      namelen);
   }
 
 #ifdef NOT_USED
@@ -261,15 +262,15 @@ sp_cache::sp_cache()
 
 sp_cache::~sp_cache()
 {
-  hash_free(&m_hashtable);
+  my_hash_free(&m_hashtable);
 }
 
 
 void
 sp_cache::init()
 {
-  hash_init(&m_hashtable, system_charset_info, 0, 0, 0,
-	    hash_get_key_for_sp_head, hash_free_sp_head, 0);
+  my_hash_init(&m_hashtable, system_charset_info, 0, 0, 0,
+               hash_get_key_for_sp_head, hash_free_sp_head, 0);
   version= 0;
 }
 
@@ -277,5 +278,5 @@ sp_cache::init()
 void
 sp_cache::cleanup()
 {
-  hash_free(&m_hashtable);
+  my_hash_free(&m_hashtable);
 }

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2009-02-02 15:58:48 +0000
+++ b/sql/sp_head.cc	2009-02-05 12:49:39 +0000
@@ -523,8 +523,9 @@ sp_head::sp_head()
   m_backpatch.empty();
   m_cont_backpatch.empty();
   m_lex.empty();
-  hash_init(&m_sptabs, system_charset_info, 0, 0, 0, sp_table_key, 0, 0);
-  hash_init(&m_sroutines, system_charset_info, 0, 0, 0, sp_sroutine_key, 0, 0);
+  my_hash_init(&m_sptabs, system_charset_info, 0, 0, 0, sp_table_key, 0, 0);
+  my_hash_init(&m_sroutines, system_charset_info, 0, 0, 0, sp_sroutine_key,
+               0, 0);
 
   m_body_utf8.str= NULL;
   m_body_utf8.length= 0;
@@ -773,8 +774,8 @@ sp_head::destroy()
     m_thd->lex= lex;
   }
 
-  hash_free(&m_sptabs);
-  hash_free(&m_sroutines);
+  my_hash_free(&m_sptabs);
+  my_hash_free(&m_sroutines);
   DBUG_VOID_RETURN;
 }
 
@@ -3816,7 +3817,7 @@ sp_head::merge_table_list(THD *thd, TABL
 
   for (uint i= 0 ; i < m_sptabs.records ; i++)
   {
-    tab= (SP_TABLE *)hash_element(&m_sptabs, i);
+    tab= (SP_TABLE*) my_hash_element(&m_sptabs, i);
     tab->query_lock_count= 0;
   }
 
@@ -3850,8 +3851,8 @@ sp_head::merge_table_list(THD *thd, TABL
         (and therefore should not be prelocked). Otherwise we will erroneously
         treat table with same name but with different alias as non-temporary.
       */
-      if ((tab= (SP_TABLE *)hash_search(&m_sptabs, (uchar *)tname, tlen)) ||
-          ((tab= (SP_TABLE *)hash_search(&m_sptabs, (uchar *)tname,
+      if ((tab= (SP_TABLE*) my_hash_search(&m_sptabs, (uchar *)tname, tlen)) ||
+          ((tab= (SP_TABLE*) my_hash_search(&m_sptabs, (uchar *)tname,
                                         tlen - alen - 1)) &&
            tab->temp))
       {
@@ -3942,7 +3943,7 @@ sp_head::add_used_tables_to_table_list(T
   {
     char *tab_buff, *key_buff;
     TABLE_LIST *table;
-    SP_TABLE *stab= (SP_TABLE *)hash_element(&m_sptabs, i);
+    SP_TABLE *stab= (SP_TABLE*) my_hash_element(&m_sptabs, i);
     if (stab->temp)
       continue;
 

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2009-02-02 12:28:30 +0000
+++ b/sql/sql_acl.cc	2009-02-05 12:49:39 +0000
@@ -261,8 +261,8 @@ my_bool acl_init(bool dont_read_acl_tabl
   DBUG_ENTER("acl_init");
 
   acl_cache= new hash_filo(ACL_CACHE_SIZE, 0, 0,
-                           (hash_get_key) acl_entry_get_key,
-                           (hash_free_key) free,
+                           (my_hash_get_key) acl_entry_get_key,
+                           (my_hash_free_key) free,
                            lower_case_file_system ?
                            system_charset_info : &my_charset_bin);
   if (dont_read_acl_tables)
@@ -637,7 +637,7 @@ void acl_free(bool end)
   delete_dynamic(&acl_users);
   delete_dynamic(&acl_dbs);
   delete_dynamic(&acl_wild_hosts);
-  hash_free(&acl_check_hosts);
+  my_hash_free(&acl_check_hosts);
   if (!end)
     acl_cache->clear(1); /* purecov: inspected */
   else
@@ -710,7 +710,7 @@ my_bool acl_reload(THD *thd)
   old_acl_dbs=acl_dbs;
   old_mem=mem;
   delete_dynamic(&acl_wild_hosts);
-  hash_free(&acl_check_hosts);
+  my_hash_free(&acl_check_hosts);
 
   if ((return_val= acl_load(thd, tables)))
   {					// Error. Revert to old list
@@ -1418,8 +1418,9 @@ static void init_check_host(void)
   DBUG_ENTER("init_check_host");
   (void) my_init_dynamic_array(&acl_wild_hosts,sizeof(struct acl_host_and_ip),
 			  acl_users.elements,1);
-  (void) hash_init(&acl_check_hosts,system_charset_info,acl_users.elements,0,0,
-		 (hash_get_key) check_get_key,0,0);
+  (void) my_hash_init(&acl_check_hosts,system_charset_info,
+                      acl_users.elements, 0, 0,
+                      (my_hash_get_key) check_get_key, 0, 0);
   if (!allow_all_hosts)
   {
     for (uint i=0 ; i < acl_users.elements ; i++)
@@ -1441,8 +1442,9 @@ static void init_check_host(void)
 	if (j == acl_wild_hosts.elements)	// If new
 	  (void) push_dynamic(&acl_wild_hosts,(uchar*) &acl_user->host);
       }
-      else if (!hash_search(&acl_check_hosts,(uchar*) acl_user->host.hostname,
-			    strlen(acl_user->host.hostname)))
+      else if (!my_hash_search(&acl_check_hosts,(uchar*)
+                               acl_user->host.hostname,
+                               strlen(acl_user->host.hostname)))
       {
 	if (my_hash_insert(&acl_check_hosts,(uchar*) acl_user))
 	{					// End of memory
@@ -1469,7 +1471,7 @@ static void init_check_host(void)
 void rebuild_check_host(void)
 {
   delete_dynamic(&acl_wild_hosts);
-  hash_free(&acl_check_hosts);
+  my_hash_free(&acl_check_hosts);
   init_check_host();
 }
 
@@ -1482,8 +1484,8 @@ bool acl_check_host(const char *host, co
     return 0;
   pthread_mutex_lock(&acl_cache->lock);
 
-  if (host && hash_search(&acl_check_hosts,(uchar*) host,strlen(host)) ||
-      ip && hash_search(&acl_check_hosts,(uchar*) ip, strlen(ip)))
+  if (host && my_hash_search(&acl_check_hosts,(uchar*) host,strlen(host)) ||
+      ip && my_hash_search(&acl_check_hosts,(uchar*) ip, strlen(ip)))
   {
     pthread_mutex_unlock(&acl_cache->lock);
     return 0;					// Found host
@@ -2287,8 +2289,8 @@ GRANT_TABLE::GRANT_TABLE(const char *h, 
                 	 const char *t, ulong p, ulong c)
   :GRANT_NAME(h,d,u,t,p), cols(c)
 {
-  (void) hash_init2(&hash_columns,4,system_charset_info,
-                   0,0,0, (hash_get_key) get_key_column,0,0);
+  (void) my_hash_init2(&hash_columns,4,system_charset_info,
+                   0,0,0, (my_hash_get_key) get_key_column,0,0);
 }
 
 
@@ -2328,15 +2330,15 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TA
   if (!db || !tname)
   {
     /* Wrong table row; Ignore it */
-    hash_clear(&hash_columns);                  /* allow for destruction */
+    my_hash_clear(&hash_columns);               /* allow for destruction */
     cols= 0;
     return;
   }
   cols= (ulong) form->field[7]->val_int();
   cols =  fix_rights_for_column(cols);
 
-  (void) hash_init2(&hash_columns,4,system_charset_info,
-                   0,0,0, (hash_get_key) get_key_column,0,0);
+  (void) my_hash_init2(&hash_columns,4,system_charset_info,
+                   0,0,0, (my_hash_get_key) get_key_column,0,0);
   if (cols)
   {
     uint key_prefix_len;
@@ -2388,7 +2390,7 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TA
 
 GRANT_TABLE::~GRANT_TABLE()
 {
-  hash_free(&hash_columns);
+  my_hash_free(&hash_columns);
 }
 
 
@@ -2402,7 +2404,7 @@ static uchar* get_grant_table(GRANT_NAME
 
 void free_grant_table(GRANT_TABLE *grant_table)
 {
-  hash_free(&grant_table->hash_columns);
+  my_hash_free(&grant_table->hash_columns);
 }
 
 
@@ -2420,11 +2422,11 @@ static GRANT_NAME *name_hash_search(HASH
   HASH_SEARCH_STATE state;
 
   len  = (uint) (strmov(strmov(strmov(helping,user)+1,db)+1,tname)-helping)+ 1;
-  for (grant_name= (GRANT_NAME*) hash_first(name_hash, (uchar*) helping,
-                                            len, &state);
+  for (grant_name= (GRANT_NAME*) my_hash_first(name_hash, (uchar*) helping,
+                                               len, &state);
        grant_name ;
-       grant_name= (GRANT_NAME*) hash_next(name_hash,(uchar*) helping,
-                                           len, &state))
+       grant_name= (GRANT_NAME*) my_hash_next(name_hash,(uchar*) helping,
+                                              len, &state))
   {
     if (exact)
     {
@@ -2468,7 +2470,8 @@ table_hash_search(const char *host, cons
 inline GRANT_COLUMN *
 column_hash_search(GRANT_TABLE *t, const char *cname, uint length)
 {
-  return (GRANT_COLUMN*) hash_search(&t->hash_columns, (uchar*) cname,length);
+  return (GRANT_COLUMN*) my_hash_search(&t->hash_columns,
+                                        (uchar*) cname, length);
 }
 
 
@@ -2648,7 +2651,7 @@ static int replace_column_table(GRANT_TA
 	    goto end;				/* purecov: deadcode */
 	  }
 	  if (grant_column)
-	    hash_delete(&g_t->hash_columns,(uchar*) grant_column);
+	    my_hash_delete(&g_t->hash_columns,(uchar*) grant_column);
 	}
       }
     } while (!table->file->index_next(table->record[0]) &&
@@ -2774,7 +2777,7 @@ static int replace_table_table(THD *thd,
   }
   else
   {
-    hash_delete(&column_priv_hash,(uchar*) grant_table);
+    my_hash_delete(&column_priv_hash,(uchar*) grant_table);
   }
   DBUG_RETURN(0);
 
@@ -2895,7 +2898,8 @@ static int replace_routine_table(THD *th
   }
   else
   {
-    hash_delete(is_proc ? &proc_priv_hash : &func_priv_hash,(uchar*) grant_name);
+    my_hash_delete(is_proc ? &proc_priv_hash : &func_priv_hash,(uchar*)
+                   grant_name);
   }
   DBUG_RETURN(0);
 
@@ -3137,8 +3141,8 @@ int mysql_table_grant(THD *thd, TABLE_LI
       column_priv= 0;
       for (uint idx=0 ; idx < grant_table->hash_columns.records ; idx++)
       {
-	grant_column= (GRANT_COLUMN*) hash_element(&grant_table->hash_columns,
-						   idx);
+        grant_column= (GRANT_COLUMN*)
+          my_hash_element(&grant_table->hash_columns, idx);
 	grant_column->rights&= ~rights;		// Fix other columns
 	column_priv|= grant_column->rights;
       }
@@ -3478,9 +3482,9 @@ bool mysql_grant(THD *thd, const char *d
 void  grant_free(void)
 {
   DBUG_ENTER("grant_free");
-  hash_free(&column_priv_hash);
-  hash_free(&proc_priv_hash);
-  hash_free(&func_priv_hash);
+  my_hash_free(&column_priv_hash);
+  my_hash_free(&proc_priv_hash);
+  my_hash_free(&func_priv_hash);
   free_root(&memex,MYF(0));
   DBUG_VOID_RETURN;
 }
@@ -3536,12 +3540,12 @@ static my_bool grant_load_procs_priv(TAB
   MEM_ROOT **save_mem_root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**,
                                                            THR_MALLOC);
   DBUG_ENTER("grant_load_procs_priv");
-  (void) hash_init(&proc_priv_hash,system_charset_info,
-                   0,0,0, (hash_get_key) get_grant_table,
-                   0,0);
-  (void) hash_init(&func_priv_hash,system_charset_info,
-                   0,0,0, (hash_get_key) get_grant_table,
-                   0,0);
+  (void) my_hash_init(&proc_priv_hash,system_charset_info,
+                      0,0,0, (my_hash_get_key) get_grant_table,
+                      0,0);
+  (void) my_hash_init(&func_priv_hash,system_charset_info,
+                      0,0,0, (my_hash_get_key) get_grant_table,
+                      0,0);
   p_table->file->ha_index_init(0, 1);
   p_table->use_all_columns();
 
@@ -3637,9 +3641,9 @@ static my_bool grant_load(THD *thd, TABL
 
   thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
 
-  (void) hash_init(&column_priv_hash,system_charset_info,
-                   0,0,0, (hash_get_key) get_grant_table,
-                   (hash_free_key) free_grant_table,0);
+  (void) my_hash_init(&column_priv_hash,system_charset_info,
+                      0,0,0, (my_hash_get_key) get_grant_table,
+                      (my_hash_free_key) free_grant_table,0);
 
   t_table = tables[0].table;
   c_table = tables[1].table;
@@ -3743,8 +3747,8 @@ static my_bool grant_reload_procs_priv(T
   }
   else
   {
-    hash_free(&old_proc_priv_hash);
-    hash_free(&old_func_priv_hash);
+    my_hash_free(&old_proc_priv_hash);
+    my_hash_free(&old_func_priv_hash);
   }
   rw_unlock(&LOCK_grant);
 
@@ -3815,7 +3819,7 @@ my_bool grant_reload(THD *thd)
   }
   else
   {
-    hash_free(&old_column_priv_hash);
+    my_hash_free(&old_column_priv_hash);
     free_root(&old_mem,MYF(0));
   }
   rw_unlock(&LOCK_grant);
@@ -4318,7 +4322,7 @@ static bool check_grant_db_routine(THD *
 
   for (uint idx= 0; idx < hash->records; ++idx)
   {
-    GRANT_NAME *item= (GRANT_NAME*) hash_element(hash, idx);
+    GRANT_NAME *item= (GRANT_NAME*) my_hash_element(hash, idx);
 
     if (strcmp(item->user, sctx->priv_user) == 0 &&
         strcmp(item->db, db) == 0 &&
@@ -4351,8 +4355,9 @@ bool check_grant_db(THD *thd,const char 
 
   for (uint idx=0 ; idx < column_priv_hash.records ; idx++)
   {
-    GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash,
-							  idx);
+    GRANT_TABLE *grant_table= (GRANT_TABLE*)
+      my_hash_element(&column_priv_hash,
+                      idx);
     if (len < grant_table->key_length &&
 	!memcmp(grant_table->hash_key,helping,len) &&
         compare_hostname(&grant_table->host, sctx->host, sctx->ip))
@@ -4824,8 +4829,8 @@ bool mysql_show_grants(THD *thd,LEX_USER
   for (index=0 ; index < column_priv_hash.records ; index++)
   {
     const char *user, *host;
-    GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash,
-							  index);
+    GRANT_TABLE *grant_table= (GRANT_TABLE*)
+      my_hash_element(&column_priv_hash, index);
 
     if (!(user=grant_table->user))
       user= "";
@@ -4878,7 +4883,7 @@ bool mysql_show_grants(THD *thd,LEX_USER
 		     col_index++)
 		{
 		  GRANT_COLUMN *grant_column = (GRANT_COLUMN*)
-		    hash_element(&grant_table->hash_columns,col_index);
+                    my_hash_element(&grant_table->hash_columns,col_index);
 		  if (grant_column->rights & j)
 		  {
 		    if (!found_col)
@@ -4968,7 +4973,7 @@ static int show_routine_grants(THD* thd,
   for (index=0 ; index < hash->records ; index++)
   {
     const char *user, *host;
-    GRANT_NAME *grant_proc= (GRANT_NAME*) hash_element(hash, index);
+    GRANT_NAME *grant_proc= (GRANT_NAME*) my_hash_element(hash, index);
 
     if (!(user=grant_proc->user))
       user= "";
@@ -5485,13 +5490,13 @@ static int handle_grant_struct(uint stru
       break;
 
     case 2:
-      grant_name= (GRANT_NAME*) hash_element(&column_priv_hash, idx);
+      grant_name= (GRANT_NAME*) my_hash_element(&column_priv_hash, idx);
       user= grant_name->user;
       host= grant_name->host.hostname;
       break;
 
     case 3:
-      grant_name= (GRANT_NAME*) hash_element(&proc_priv_hash, idx);
+      grant_name= (GRANT_NAME*) my_hash_element(&proc_priv_hash, idx);
       user= grant_name->user;
       host= grant_name->host.hostname;
       break;
@@ -5524,11 +5529,11 @@ static int handle_grant_struct(uint stru
         break;
 
       case 2:
-        hash_delete(&column_priv_hash, (uchar*) grant_name);
+        my_hash_delete(&column_priv_hash, (uchar*) grant_name);
 	break;
 
       case 3:
-        hash_delete(&proc_priv_hash, (uchar*) grant_name);
+        my_hash_delete(&proc_priv_hash, (uchar*) grant_name);
 	break;
       }
       elements--;
@@ -6036,8 +6041,8 @@ bool mysql_revoke_all(THD *thd,  List <L
       for (counter= 0, revoked= 0 ; counter < column_priv_hash.records ; )
       {
 	const char *user,*host;
-	GRANT_TABLE *grant_table= (GRANT_TABLE*)hash_element(&column_priv_hash,
-							     counter);
+        GRANT_TABLE *grant_table=
+          (GRANT_TABLE*) my_hash_element(&column_priv_hash, counter);
 	if (!(user=grant_table->user))
 	  user= "";
 	if (!(host=grant_table->host.hostname))
@@ -6083,7 +6088,7 @@ bool mysql_revoke_all(THD *thd,  List <L
       for (counter= 0, revoked= 0 ; counter < hash->records ; )
       {
 	const char *user,*host;
-	GRANT_NAME *grant_proc= (GRANT_NAME*) hash_element(hash, counter);
+        GRANT_NAME *grant_proc= (GRANT_NAME*) my_hash_element(hash, counter);
 	if (!(user=grant_proc->user))
 	  user= "";
 	if (!(host=grant_proc->host.hostname))
@@ -6222,7 +6227,7 @@ bool sp_revoke_privileges(THD *thd, cons
   {
     for (counter= 0, revoked= 0 ; counter < hash->records ; )
     {
-      GRANT_NAME *grant_proc= (GRANT_NAME*) hash_element(hash, counter);
+      GRANT_NAME *grant_proc= (GRANT_NAME*) my_hash_element(hash, counter);
       if (!my_strcasecmp(system_charset_info, grant_proc->db, sp_db) &&
 	  !my_strcasecmp(system_charset_info, grant_proc->tname, sp_name))
       {
@@ -6602,7 +6607,7 @@ int fill_schema_table_privileges(THD *th
   for (index=0 ; index < column_priv_hash.records ; index++)
   {
     const char *user, *host, *is_grantable= "YES";
-    GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash,
+    GRANT_TABLE *grant_table= (GRANT_TABLE*) my_hash_element(&column_priv_hash,
 							  index);
     if (!(user=grant_table->user))
       user= "";
@@ -6685,7 +6690,7 @@ int fill_schema_column_privileges(THD *t
   for (index=0 ; index < column_priv_hash.records ; index++)
   {
     const char *user, *host, *is_grantable= "YES";
-    GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash,
+    GRANT_TABLE *grant_table= (GRANT_TABLE*) my_hash_element(&column_priv_hash,
 							  index);
     if (!(user=grant_table->user))
       user= "";
@@ -6720,7 +6725,7 @@ int fill_schema_column_privileges(THD *t
                  col_index++)
             {
               GRANT_COLUMN *grant_column = (GRANT_COLUMN*)
-                hash_element(&grant_table->hash_columns,col_index);
+                my_hash_element(&grant_table->hash_columns,col_index);
               if ((grant_column->rights & j) && (table_access & j))
               {
                 if (update_schema_privilege(thd, table, buff, grant_table->db,

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2009-02-05 11:03:46 +0000
+++ b/sql/sql_base.cc	2009-02-09 16:27:41 +0000
@@ -149,7 +149,7 @@ static void check_unused(void)
   }
   for (idx=0 ; idx < table_def_cache.records ; idx++)
   {
-    share= (TABLE_SHARE*) hash_element(&table_def_cache, idx);
+    share= (TABLE_SHARE*) my_hash_element(&table_def_cache, idx);
 
     I_P_List_iterator<TABLE, TABLE_share> it(share->free_tables);
     while ((entry= it++))
@@ -262,9 +262,9 @@ bool table_def_init(void)
   oldest_unused_share= &end_of_unused_share;
   end_of_unused_share.prev= &oldest_unused_share;
 
-  return hash_init(&table_def_cache, &my_charset_bin, table_def_size,
-		   0, 0, table_def_key,
-		   (hash_free_key) table_def_free_entry, 0) != 0;
+  return my_hash_init(&table_def_cache, &my_charset_bin, table_def_size,
+                      0, 0, table_def_key,
+                      (my_hash_free_key) table_def_free_entry, 0) != 0;
 }
 
 
@@ -277,7 +277,7 @@ void table_def_free(void)
     close_cached_tables(NULL, NULL, FALSE, FALSE);
     table_def_inited= 0;
     /* Free table definitions. */
-    hash_free(&table_def_cache);
+    my_hash_free(&table_def_cache);
   }
   DBUG_VOID_RETURN;
 }
@@ -442,8 +442,8 @@ TABLE_SHARE *get_table_share(THD *thd, T
                                 table_list->table_name));
 
   /* Read table definition from cache */
-  if ((share= (TABLE_SHARE*) hash_search(&table_def_cache,(uchar*) key,
-                                         key_length)))
+  if ((share= (TABLE_SHARE*) my_hash_search(&table_def_cache,(uchar*) key,
+                                            key_length)))
     goto found;
 
   if (!(share= alloc_table_share(table_list, key, key_length)))
@@ -474,7 +474,7 @@ TABLE_SHARE *get_table_share(THD *thd, T
   if (open_table_def(thd, share, db_flags))
   {
     *error= share->error;
-    (void) hash_delete(&table_def_cache, (uchar*) share);
+    (void) my_hash_delete(&table_def_cache, (uchar*) share);
     DBUG_RETURN(0);
   }
   share->ref_count++;				// Mark in use
@@ -515,7 +515,7 @@ found:
    /* Free cache if too big */
   while (table_def_cache.records > table_def_size &&
          oldest_unused_share->next)
-    hash_delete(&table_def_cache, (uchar*) oldest_unused_share);
+    my_hash_delete(&table_def_cache, (uchar*) oldest_unused_share);
 
   DBUG_PRINT("exit", ("share: %p  ref_count: %u",
                       share, share->ref_count));
@@ -653,7 +653,7 @@ void release_table_share(TABLE_SHARE *sh
   if (to_be_deleted)
   {
     DBUG_PRINT("info", ("Deleting share"));
-    hash_delete(&table_def_cache, (uchar*) share);
+    my_hash_delete(&table_def_cache, (uchar*) share);
   }
   DBUG_VOID_RETURN;
 }
@@ -682,7 +682,8 @@ TABLE_SHARE *get_cached_table_share(cons
   table_list.db= (char*) db;
   table_list.table_name= (char*) table_name;
   key_length= create_table_def_key((THD*) 0, key, &table_list, 0);
-  return (TABLE_SHARE*) hash_search(&table_def_cache,(uchar*) key, key_length);
+  return (TABLE_SHARE*) my_hash_search(&table_def_cache,
+                                       (uchar*) key, key_length);
 }  
 
 
@@ -737,7 +738,7 @@ OPEN_TABLE_LIST *list_open_tables(THD *t
 
   for (uint idx=0 ; result == 0 && idx < table_def_cache.records; idx++)
   {
-    TABLE_SHARE *share= (TABLE_SHARE *)hash_element(&table_def_cache, idx);
+    TABLE_SHARE *share= (TABLE_SHARE *)my_hash_element(&table_def_cache, idx);
 
     if (db && my_strcasecmp(system_charset_info, db, share->db.str))
       continue;
@@ -913,7 +914,7 @@ bool close_cached_tables(THD *thd, TABLE
       free_cache_entry(unused_tables);
     /* Free table shares which were not freed implicitly by loop above. */
     while (oldest_unused_share->next)
-      (void) hash_delete(&table_def_cache, (uchar*) oldest_unused_share);
+      (void) my_hash_delete(&table_def_cache, (uchar*) oldest_unused_share);
   }
   else
   {
@@ -995,7 +996,8 @@ bool close_cached_tables(THD *thd, TABLE
     {
       for (uint idx=0 ; idx < table_def_cache.records ; idx++)
       {
-        TABLE_SHARE *share=(TABLE_SHARE*) hash_element(&table_def_cache, idx);
+        TABLE_SHARE *share=(TABLE_SHARE*) my_hash_element(&table_def_cache,
+                                                          idx);
         if (share->version != refresh_version)
         {
           found= TRUE;
@@ -1067,7 +1069,7 @@ bool close_cached_connection_tables(THD 
 
   for (idx= 0; idx < table_def_cache.records; idx++)
   {
-    TABLE_SHARE *share= (TABLE_SHARE *) hash_element(&table_def_cache, idx);
+    TABLE_SHARE *share= (TABLE_SHARE *) my_hash_element(&table_def_cache, idx);
 
     /* Ignore if table is not open or does not have a connect_string */
     if (!share->connect_string.length || !share->ref_count)
@@ -3812,7 +3814,7 @@ int open_tables(THD *thd, TABLE_LIST **s
         Let us free memory used by 'sroutines' hash here since we never
         call destructor for this LEX.
       */
-      hash_free(&tables->view->sroutines);
+      my_hash_free(&tables->view->sroutines);
       goto process_view_routines;
     }
 
@@ -5038,8 +5040,8 @@ find_field_in_table(THD *thd, TABLE *tab
     field_ptr= table->field + cached_field_index;
   else if (table->s->name_hash.records)
   {
-    field_ptr= (Field**) hash_search(&table->s->name_hash, (uchar*) name,
-                                     length);
+    field_ptr= (Field**) my_hash_search(&table->s->name_hash, (uchar*) name,
+                                        length);
     if (field_ptr)
     {
       /*
@@ -5287,8 +5289,8 @@ Field *find_field_in_table_sef(TABLE *ta
   Field **field_ptr;
   if (table->s->name_hash.records)
   {
-    field_ptr= (Field**)hash_search(&table->s->name_hash,(uchar*) name,
-                                    strlen(name));
+    field_ptr= (Field**)my_hash_search(&table->s->name_hash,(uchar*) name,
+                                       strlen(name));
     if (field_ptr)
     {
       /*
@@ -7669,8 +7671,8 @@ void tdc_remove_table(THD *thd, enum_tdc
 
   key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
 
-  if ((share= (TABLE_SHARE*) hash_search(&table_def_cache,(uchar*) key,
-                                         key_length)))
+  if ((share= (TABLE_SHARE*) my_hash_search(&table_def_cache,(uchar*) key,
+                                            key_length)))
   {
     if (share->ref_count)
     {
@@ -7699,7 +7701,7 @@ void tdc_remove_table(THD *thd, enum_tdc
         free_cache_entry(table);
     }
     else
-      (void) hash_delete(&table_def_cache, (uchar*) share);
+      (void) my_hash_delete(&table_def_cache, (uchar*) share);
   }
 }
 
@@ -7735,8 +7737,9 @@ static bool tdc_wait_for_old_versions(TH
     while ((lock_data= it++))
     {
       mdl_get_tdc_key(lock_data, &key);
-      if ((share= (TABLE_SHARE*) hash_search(&table_def_cache, (uchar*) key.str,
-                                             key.length)) &&
+      if ((share= (TABLE_SHARE*) my_hash_search(&table_def_cache,
+                                                (uchar*) key.str,
+                                                key.length)) &&
           share->version != refresh_version)
         break;
     }

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2009-01-30 14:13:39 +0000
+++ b/sql/sql_cache.cc	2009-02-04 10:49:16 +0000
@@ -1112,7 +1112,7 @@ def_week_frmt: %lu, in_trans: %d, autoco
 
     /* Check if another thread is processing the same query? */
     Query_cache_block *competitor = (Query_cache_block *)
-      hash_search(&queries, (uchar*) thd->query, tot_length);
+      my_hash_search(&queries, (uchar*) thd->query, tot_length);
     DBUG_PRINT("qcache", ("competitor %p", competitor));
     if (competitor == 0)
     {
@@ -1141,7 +1141,7 @@ def_week_frmt: %lu, in_trans: %d, autoco
 	{
 	  refused++;
 	  DBUG_PRINT("warning", ("tables list including failed"));
-	  hash_delete(&queries, (uchar *) query_block);
+	  my_hash_delete(&queries, (uchar *) query_block);
 	  header->unlock_n_destroy();
 	  free_memory_block(query_block);
 	  STRUCT_UNLOCK(&structure_guard_mutex);
@@ -1333,8 +1333,8 @@ def_week_frmt: %lu, in_trans: %d, autoco
                           (int)flags.autocommit));
   memcpy((uchar *)(sql + (tot_length - QUERY_CACHE_FLAGS_SIZE)),
 	 (uchar*) &flags, QUERY_CACHE_FLAGS_SIZE);
-  query_block = (Query_cache_block *)  hash_search(&queries, (uchar*) sql,
-						   tot_length);
+  query_block = (Query_cache_block *)  my_hash_search(&queries, (uchar*) sql,
+                                                      tot_length);
   /* Quick abort on unlocked data */
   if (query_block == 0 ||
       query_block->query()->result() == 0 ||
@@ -1363,7 +1363,7 @@ def_week_frmt: %lu, in_trans: %d, autoco
   }
   DBUG_PRINT("qcache", ("Query have result %p", query));
 
-  if ((thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
+  if (thd->in_multi_stmt_transaction() &&
       (query->tables_type() & HA_CACHE_TBL_TRANSACT))
   {
     DBUG_PRINT("qcache",
@@ -1521,8 +1521,7 @@ void Query_cache::invalidate(THD *thd, T
   if (is_disabled())
     DBUG_VOID_RETURN;
 
-  using_transactions= using_transactions &&
-    (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
+  using_transactions= using_transactions && thd->in_multi_stmt_transaction();
   for (; tables_used; tables_used= tables_used->next_local)
   {
     DBUG_ASSERT(!using_transactions || tables_used->table!=0);
@@ -1603,8 +1602,7 @@ void Query_cache::invalidate(THD *thd, T
   if (is_disabled())
     DBUG_VOID_RETURN;
 
-  using_transactions= using_transactions &&
-    (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
+  using_transactions= using_transactions && thd->in_multi_stmt_transaction();
   if (using_transactions && 
       (table->file->table_cache_type() == HA_CACHE_TBL_TRANSACT))
     thd->add_changed_table(table);
@@ -1622,8 +1620,7 @@ void Query_cache::invalidate(THD *thd, c
   if (is_disabled())
     DBUG_VOID_RETURN;
 
-  using_transactions= using_transactions &&
-    (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
+  using_transactions= using_transactions && thd->in_multi_stmt_transaction();
   if (using_transactions) // used for innodb => has_transactions() is TRUE
     thd->add_changed_table(key, key_length);
   else
@@ -2009,8 +2006,8 @@ ulong Query_cache::init_cache()
 
   DUMP(this);
 
-  (void) hash_init(&queries, &my_charset_bin, def_query_hash_size, 0, 0,
-		 query_cache_query_get_key, 0, 0);
+  (void) my_hash_init(&queries, &my_charset_bin, def_query_hash_size, 0, 0,
+                      query_cache_query_get_key, 0, 0);
 #ifndef FN_NO_CASE_SENCE
   /*
     If lower_case_table_names!=0 then db and table names are already 
@@ -2020,8 +2017,8 @@ ulong Query_cache::init_cache()
     lower_case_table_names == 0 then we should distinguish my_table
     and MY_TABLE cases and so again can use binary collation.
   */
-  (void) hash_init(&tables, &my_charset_bin, def_table_hash_size, 0, 0,
-		 query_cache_table_get_key, 0, 0);
+  (void) my_hash_init(&tables, &my_charset_bin, def_table_hash_size, 0, 0,
+                      query_cache_table_get_key, 0, 0);
 #else
   /*
     On windows, OS/2, MacOS X with HFS+ or any other case insensitive
@@ -2031,10 +2028,11 @@ ulong Query_cache::init_cache()
     file system) and so should use case insensitive collation for
     comparison.
   */
-  (void) hash_init(&tables,
-		 lower_case_table_names ? &my_charset_bin :
-		 files_charset_info,
-		 def_table_hash_size, 0, 0,query_cache_table_get_key, 0, 0);
+  (void) my_hash_init(&tables,
+                      lower_case_table_names ? &my_charset_bin :
+                      files_charset_info,
+                      def_table_hash_size, 0, 0,query_cache_table_get_key,
+                      0, 0);
 #endif
 
   queries_in_cache = 0;
@@ -2084,8 +2082,8 @@ void Query_cache::free_cache()
 
   my_free((uchar*) cache, MYF(MY_ALLOW_ZERO_PTR));
   make_disabled();
-  hash_free(&queries);
-  hash_free(&tables);
+  my_hash_free(&queries);
+  my_hash_free(&tables);
   DBUG_VOID_RETURN;
 }
 
@@ -2278,7 +2276,7 @@ void Query_cache::free_query(Query_cache
 		      query_block,
 		      query_block->query()->length() ));
 
-  hash_delete(&queries,(uchar *) query_block);
+  my_hash_delete(&queries,(uchar *) query_block);
   free_query_internal(query_block);
 
   DBUG_VOID_RETURN;
@@ -2632,7 +2630,7 @@ void
 Query_cache::invalidate_table_internal(THD *thd, uchar *key, uint32 key_length)
 {
   Query_cache_block *table_block=
-    (Query_cache_block*)hash_search(&tables, key, key_length);
+    (Query_cache_block*)my_hash_search(&tables, key, key_length);
   if (table_block)
   {
     Query_cache_block_table *list_root= table_block->table(0);
@@ -2831,7 +2829,7 @@ Query_cache::insert_table(uint key_len, 
   THD *thd= current_thd;
 
   Query_cache_block *table_block= 
-    (Query_cache_block *)hash_search(&tables, (uchar*) key, key_len);
+    (Query_cache_block *) my_hash_search(&tables, (uchar*) key, key_len);
 
   if (table_block &&
       table_block->table()->engine_data() != engine_data)
@@ -2947,7 +2945,7 @@ void Query_cache::unlink_table(Query_cac
     Query_cache_block *table_block= neighbour->block();
     double_linked_list_exclude(table_block,
                                &tables_blocks);
-    hash_delete(&tables,(uchar *) table_block);
+    my_hash_delete(&tables,(uchar *) table_block);
     free_memory_block(table_block);
   }
   DBUG_VOID_RETURN;
@@ -3475,7 +3473,7 @@ Query_cache::is_cacheable(THD *thd, size
                                                 tables_type)))
       DBUG_RETURN(0);
 
-    if ((thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
+    if (thd->in_multi_stmt_transaction() &&
 	((*tables_type)&HA_CACHE_TBL_TRANSACT))
     {
       DBUG_PRINT("qcache", ("not in autocommin mode"));
@@ -3632,7 +3630,7 @@ my_bool Query_cache::move_by_type(uchar 
     uchar *key;
     size_t key_length;
     key=query_cache_table_get_key((uchar*) block, &key_length, 0);
-    hash_first(&tables, (uchar*) key, key_length, &record_idx);
+    my_hash_first(&tables, (uchar*) key, key_length, &record_idx);
 
     block->destroy();
     new_block->init(len);
@@ -3666,7 +3664,7 @@ my_bool Query_cache::move_by_type(uchar 
     /* Fix pointer to table name */
     new_block->table()->table(new_block->table()->db() + tablename_offset);
     /* Fix hash to point at moved block */
-    hash_replace(&tables, &record_idx, (uchar*) new_block);
+    my_hash_replace(&tables, &record_idx, (uchar*) new_block);
 
     DBUG_PRINT("qcache", ("moved %lu bytes to %p, new gap at %p",
 			len, new_block, *border));
@@ -3692,7 +3690,7 @@ my_bool Query_cache::move_by_type(uchar 
     uchar *key;
     size_t key_length;
     key=query_cache_query_get_key((uchar*) block, &key_length, 0);
-    hash_first(&queries, (uchar*) key, key_length, &record_idx);
+    my_hash_first(&queries, (uchar*) key, key_length, &record_idx);
     // Move table of used tables 
     memmove((char*) new_block->table(0), (char*) block->table(0),
 	   ALIGN_SIZE(n_tables*sizeof(Query_cache_block_table)));
@@ -3760,7 +3758,7 @@ my_bool Query_cache::move_by_type(uchar 
       query_cache_tls->first_query_block= new_block;
     }
     /* Fix hash to point at moved block */
-    hash_replace(&queries, &record_idx, (uchar*) new_block);
+    my_hash_replace(&queries, &record_idx, (uchar*) new_block);
     DBUG_PRINT("qcache", ("moved %lu bytes to %p, new gap at %p",
 			len, new_block, *border));
     break;
@@ -4174,13 +4172,13 @@ my_bool Query_cache::check_integrity(boo
   while (is_flushing())
     pthread_cond_wait(&COND_cache_status_changed,&structure_guard_mutex);
 
-  if (hash_check(&queries))
+  if (my_hash_check(&queries))
   {
     DBUG_PRINT("error", ("queries hash is damaged"));
     result = 1;
   }
 
-  if (hash_check(&tables))
+  if (my_hash_check(&tables))
   {
     DBUG_PRINT("error", ("tables hash is damaged"));
     result = 1;
@@ -4347,7 +4345,7 @@ my_bool Query_cache::check_integrity(boo
 			    block, (uint) block->type));
       size_t length;
       uchar *key = query_cache_query_get_key((uchar*) block, &length, 0);
-      uchar* val = hash_search(&queries, key, length);
+      uchar* val = my_hash_search(&queries, key, length);
       if (((uchar*)block) != val)
       {
 	DBUG_PRINT("error", ("block %p found in queries hash like %p",
@@ -4382,7 +4380,7 @@ my_bool Query_cache::check_integrity(boo
 			    block, (uint) block->type));
       size_t length;
       uchar *key = query_cache_table_get_key((uchar*) block, &length, 0);
-      uchar* val = hash_search(&tables, key, length);
+      uchar* val = my_hash_search(&tables, key, length);
       if (((uchar*)block) != val)
       {
 	DBUG_PRINT("error", ("block %p found in tables hash like %p",

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2009-02-05 12:22:39 +0000
+++ b/sql/sql_class.cc	2009-02-09 16:27:41 +0000
@@ -447,7 +447,7 @@ THD::THD()
   killed= NOT_KILLED;
   col_access=0;
   is_slave_error= thread_specific_used= FALSE;
-  hash_clear(&handler_tables_hash);
+  my_hash_clear(&handler_tables_hash);
   tmp_table=0;
   used_tables=0;
   cuted_fields= 0L;
@@ -514,9 +514,9 @@ THD::THD()
   profiling.set_thd(this);
 #endif
   user_connect=(USER_CONN *)0;
-  hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
-	    (hash_get_key) get_var_key,
-	    (hash_free_key) free_user_var, 0);
+  my_hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
+               (my_hash_get_key) get_var_key,
+               (my_hash_free_key) free_user_var, 0);
 
   sp_proc_cache= NULL;
   sp_func_cache= NULL;
@@ -707,9 +707,9 @@ void THD::change_user(void)
   cleanup_done= 0;
   init();
   stmt_map.reset();
-  hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
-	    (hash_get_key) get_var_key,
-	    (hash_free_key) free_user_var, 0);
+  my_hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
+               (my_hash_get_key) get_var_key,
+               (my_hash_free_key) free_user_var, 0);
   sp_cache_clear(&sp_proc_cache);
   sp_cache_clear(&sp_func_cache);
 }
@@ -744,7 +744,7 @@ void THD::cleanup(void)
   wt_thd_destroy(&transaction.wt);
   mysql_ha_cleanup(this);
   delete_dynamic(&user_var_events);
-  hash_free(&user_vars);
+  my_hash_free(&user_vars);
   close_temporary_tables(this);
   my_free((char*) variables.time_format, MYF(MY_ALLOW_ZERO_PTR));
   my_free((char*) variables.date_format, MYF(MY_ALLOW_ZERO_PTR));
@@ -1232,8 +1232,7 @@ void THD::add_changed_table(TABLE *table
 {
   DBUG_ENTER("THD::add_changed_table(table)");
 
-  DBUG_ASSERT((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
-	      table->file->has_transactions());
+  DBUG_ASSERT(in_multi_stmt_transaction() && table->file->has_transactions());
   add_changed_table(table->s->table_cache_key.str,
                     (long) table->s->table_cache_key.length);
   DBUG_VOID_RETURN;
@@ -2411,12 +2410,12 @@ Statement_map::Statement_map() :
     START_STMT_HASH_SIZE = 16,
     START_NAME_HASH_SIZE = 16
   };
-  hash_init(&st_hash, &my_charset_bin, START_STMT_HASH_SIZE, 0, 0,
-            get_statement_id_as_hash_key,
-            delete_statement_as_hash_key, MYF(0));
-  hash_init(&names_hash, system_charset_info, START_NAME_HASH_SIZE, 0, 0,
-            (hash_get_key) get_stmt_name_hash_key,
-            NULL,MYF(0));
+  my_hash_init(&st_hash, &my_charset_bin, START_STMT_HASH_SIZE, 0, 0,
+               get_statement_id_as_hash_key,
+               delete_statement_as_hash_key, MYF(0));
+  my_hash_init(&names_hash, system_charset_info, START_NAME_HASH_SIZE, 0, 0,
+               (my_hash_get_key) get_stmt_name_hash_key,
+               NULL,MYF(0));
 }
 
 
@@ -2481,9 +2480,9 @@ int Statement_map::insert(THD *thd, Stat
 
 err_max:
   if (statement->name.str)
-    hash_delete(&names_hash, (uchar*) statement);
+    my_hash_delete(&names_hash, (uchar*) statement);
 err_names_hash:
-  hash_delete(&st_hash, (uchar*) statement);
+  my_hash_delete(&st_hash, (uchar*) statement);
 err_st_hash:
   return 1;
 }
@@ -2504,9 +2503,9 @@ void Statement_map::erase(Statement *sta
   if (statement == last_found_statement)
     last_found_statement= 0;
   if (statement->name.str)
-    hash_delete(&names_hash, (uchar *) statement);
+    my_hash_delete(&names_hash, (uchar *) statement);
 
-  hash_delete(&st_hash, (uchar *) statement);
+  my_hash_delete(&st_hash, (uchar *) statement);
   pthread_mutex_lock(&LOCK_prepared_stmt_count);
   DBUG_ASSERT(prepared_stmt_count > 0);
   prepared_stmt_count--;
@@ -2536,8 +2535,8 @@ Statement_map::~Statement_map()
   prepared_stmt_count-= st_hash.records;
   pthread_mutex_unlock(&LOCK_prepared_stmt_count);
 
-  hash_free(&names_hash);
-  hash_free(&st_hash);
+  my_hash_free(&names_hash);
+  my_hash_free(&st_hash);
 }
 
 bool select_dumpvar::send_data(List<Item> &items)
@@ -3051,15 +3050,15 @@ void xid_free_hash(void *ptr)
 bool xid_cache_init()
 {
   pthread_mutex_init(&LOCK_xid_cache, MY_MUTEX_INIT_FAST);
-  return hash_init(&xid_cache, &my_charset_bin, 100, 0, 0,
-                   xid_get_hash_key, xid_free_hash, 0) != 0;
+  return my_hash_init(&xid_cache, &my_charset_bin, 100, 0, 0,
+                      xid_get_hash_key, xid_free_hash, 0) != 0;
 }
 
 void xid_cache_free()
 {
-  if (hash_inited(&xid_cache))
+  if (my_hash_inited(&xid_cache))
   {
-    hash_free(&xid_cache);
+    my_hash_free(&xid_cache);
     pthread_mutex_destroy(&LOCK_xid_cache);
   }
 }
@@ -3067,7 +3066,8 @@ void xid_cache_free()
 XID_STATE *xid_cache_search(XID *xid)
 {
   pthread_mutex_lock(&LOCK_xid_cache);
-  XID_STATE *res=(XID_STATE *)hash_search(&xid_cache, xid->key(), xid->key_length());
+  XID_STATE *res=(XID_STATE *)my_hash_search(&xid_cache, xid->key(),
+                                             xid->key_length());
   pthread_mutex_unlock(&LOCK_xid_cache);
   return res;
 }
@@ -3078,7 +3078,7 @@ bool xid_cache_insert(XID *xid, enum xa_
   XID_STATE *xs;
   my_bool res;
   pthread_mutex_lock(&LOCK_xid_cache);
-  if (hash_search(&xid_cache, xid->key(), xid->key_length()))
+  if (my_hash_search(&xid_cache, xid->key(), xid->key_length()))
     res=0;
   else if (!(xs=(XID_STATE *)my_malloc(sizeof(*xs), MYF(MY_WME))))
     res=1;
@@ -3097,8 +3097,8 @@ bool xid_cache_insert(XID *xid, enum xa_
 bool xid_cache_insert(XID_STATE *xid_state)
 {
   pthread_mutex_lock(&LOCK_xid_cache);
-  DBUG_ASSERT(hash_search(&xid_cache, xid_state->xid.key(),
-                          xid_state->xid.key_length())==0);
+  DBUG_ASSERT(my_hash_search(&xid_cache, xid_state->xid.key(),
+                             xid_state->xid.key_length())==0);
   my_bool res=my_hash_insert(&xid_cache, (uchar*)xid_state);
   pthread_mutex_unlock(&LOCK_xid_cache);
   return res;
@@ -3108,7 +3108,7 @@ bool xid_cache_insert(XID_STATE *xid_sta
 void xid_cache_delete(XID_STATE *xid_state)
 {
   pthread_mutex_lock(&LOCK_xid_cache);
-  hash_delete(&xid_cache, (uchar *)xid_state);
+  my_hash_delete(&xid_cache, (uchar *)xid_state);
   pthread_mutex_unlock(&LOCK_xid_cache);
 }
 

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2009-02-05 12:22:39 +0000
+++ b/sql/sql_class.h	2009-02-09 16:27:41 +0000
@@ -730,8 +730,8 @@ public:
   Statement *find_by_name(LEX_STRING *name)
   {
     Statement *stmt;
-    stmt= (Statement*)hash_search(&names_hash, (uchar*)name->str,
-                                  name->length);
+    stmt= (Statement*)my_hash_search(&names_hash, (uchar*)name->str,
+                                     name->length);
     return stmt;
   }
 
@@ -740,7 +740,7 @@ public:
     if (last_found_statement == 0 || id != last_found_statement->id)
     {
       Statement *stmt;
-      stmt= (Statement *) hash_search(&st_hash, (uchar *) &id, sizeof(id));
+      stmt= (Statement *) my_hash_search(&st_hash, (uchar *) &id, sizeof(id));
       if (stmt && stmt->name.str)
         return NULL;
       last_found_statement= stmt;
@@ -1959,6 +1959,21 @@ public:
   inline bool active_transaction()
   {
     return server_status & SERVER_STATUS_IN_TRANS;
+  }
+  /**
+    Returns TRUE if session is in a multi-statement transaction mode.
+
+    OPTION_NOT_AUTOCOMMIT: When autocommit is off, a multi-statement
+    transaction is implicitly started on the first statement after a
+    previous transaction has been ended.
+
+    OPTION_BEGIN: Regardless of the autocommit status, a multi-statement
+    transaction can be explicitly started with the statements "START
+    TRANSACTION", "BEGIN [WORK]", "[COMMIT | ROLLBACK] AND CHAIN", etc.
+  */
+  inline bool in_multi_stmt_transaction()
+  {
+    return options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
   }
   inline bool fill_derived_tables()
   {

=== modified file 'sql/sql_connect.cc'
--- a/sql/sql_connect.cc	2008-12-24 10:48:24 +0000
+++ b/sql/sql_connect.cc	2009-01-31 16:21:19 +0000
@@ -61,7 +61,7 @@ static int get_or_create_user_conn(THD *
   user_len= strlen(user);
   temp_len= (strmov(strmov(temp_user, user)+1, host) - temp_user)+1;
   (void) pthread_mutex_lock(&LOCK_user_conn);
-  if (!(uc = (struct  user_conn *) hash_search(&hash_user_connections,
+  if (!(uc = (struct  user_conn *) my_hash_search(&hash_user_connections,
 					       (uchar*) temp_user, temp_len)))
   {
     /* First connection for user; Create a user connection object */
@@ -191,7 +191,7 @@ void decrease_user_connections(USER_CONN
   if (!--uc->connections && !mqh_used)
   {
     /* Last connection for user; Delete it */
-    (void) hash_delete(&hash_user_connections,(uchar*) uc);
+    (void) my_hash_delete(&hash_user_connections,(uchar*) uc);
   }
   (void) pthread_mutex_unlock(&LOCK_user_conn);
   DBUG_VOID_RETURN;
@@ -537,10 +537,10 @@ extern "C" void free_user(struct user_co
 void init_max_user_conn(void)
 {
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
-  (void) hash_init(&hash_user_connections,system_charset_info,max_connections,
-		   0,0,
-		   (hash_get_key) get_key_conn, (hash_free_key) free_user,
-		   0);
+  (void)
+    my_hash_init(&hash_user_connections,system_charset_info,max_connections,
+                 0,0, (my_hash_get_key) get_key_conn,
+                 (my_hash_free_key) free_user, 0);
 #endif
 }
 
@@ -548,7 +548,7 @@ void init_max_user_conn(void)
 void free_max_user_conn(void)
 {
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
-  hash_free(&hash_user_connections);
+  my_hash_free(&hash_user_connections);
 #endif /* NO_EMBEDDED_ACCESS_CHECKS */
 }
 
@@ -566,8 +566,9 @@ void reset_mqh(LEX_USER *lu, bool get_th
     memcpy(temp_user,lu->user.str,lu->user.length);
     memcpy(temp_user+lu->user.length+1,lu->host.str,lu->host.length);
     temp_user[lu->user.length]='\0'; temp_user[temp_len-1]=0;
-    if ((uc = (struct  user_conn *) hash_search(&hash_user_connections,
-						(uchar*) temp_user, temp_len)))
+    if ((uc = (struct  user_conn *) my_hash_search(&hash_user_connections,
+                                                   (uchar*) temp_user,
+                                                   temp_len)))
     {
       uc->questions=0;
       get_mqh(temp_user,&temp_user[lu->user.length+1],uc);
@@ -580,8 +581,8 @@ void reset_mqh(LEX_USER *lu, bool get_th
     /* for FLUSH PRIVILEGES and FLUSH USER_RESOURCES */
     for (uint idx=0;idx < hash_user_connections.records; idx++)
     {
-      USER_CONN *uc=(struct user_conn *) hash_element(&hash_user_connections,
-						      idx);
+      USER_CONN *uc=(struct user_conn *)
+        my_hash_element(&hash_user_connections, idx);
       if (get_them)
 	get_mqh(uc->user,uc->host,uc);
       uc->questions=0;

=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc	2009-02-02 15:58:48 +0000
+++ b/sql/sql_db.cc	2009-02-05 12:49:39 +0000
@@ -105,8 +105,8 @@ static my_bool lock_db_insert(const char
   
   safe_mutex_assert_owner(&LOCK_lock_db);
 
-  if (!(opt= (my_dblock_t*) hash_search(&lock_db_cache,
-                                        (uchar*) dbname, length)))
+  if (!(opt= (my_dblock_t*) my_hash_search(&lock_db_cache,
+                                           (uchar*) dbname, length)))
   { 
     /* Db is not in the hash, insert it */
     char *tmp_name;
@@ -139,9 +139,9 @@ void lock_db_delete(const char *name, ui
 {
   my_dblock_t *opt;
   safe_mutex_assert_owner(&LOCK_lock_db);
-  if ((opt= (my_dblock_t *)hash_search(&lock_db_cache,
-                                       (const uchar*) name, length)))
-    hash_delete(&lock_db_cache, (uchar*) opt);
+  if ((opt= (my_dblock_t *)my_hash_search(&lock_db_cache,
+                                          (const uchar*) name, length)))
+    my_hash_delete(&lock_db_cache, (uchar*) opt);
 }
 
 
@@ -222,14 +222,14 @@ bool my_database_names_init(void)
   if (!dboptions_init)
   {
     dboptions_init= 1;
-    error= hash_init(&dboptions, lower_case_table_names ? 
-                     &my_charset_bin : system_charset_info,
-                     32, 0, 0, (hash_get_key) dboptions_get_key,
-                     free_dbopt,0) ||
-           hash_init(&lock_db_cache, lower_case_table_names ? 
-                     &my_charset_bin : system_charset_info,
-                     32, 0, 0, (hash_get_key) lock_db_get_key,
-                     lock_db_free_element,0);
+    error= my_hash_init(&dboptions, lower_case_table_names ?
+                        &my_charset_bin : system_charset_info,
+                        32, 0, 0, (my_hash_get_key) dboptions_get_key,
+                        free_dbopt,0) ||
+           my_hash_init(&lock_db_cache, lower_case_table_names ?
+                        &my_charset_bin : system_charset_info,
+                        32, 0, 0, (my_hash_get_key) lock_db_get_key,
+                        lock_db_free_element,0);
 
   }
   return error;
@@ -246,9 +246,9 @@ void my_database_names_free(void)
   if (dboptions_init)
   {
     dboptions_init= 0;
-    hash_free(&dboptions);
+    my_hash_free(&dboptions);
     (void) rwlock_destroy(&LOCK_dboptions);
-    hash_free(&lock_db_cache);
+    my_hash_free(&lock_db_cache);
   }
 }
 
@@ -260,11 +260,11 @@ void my_database_names_free(void)
 void my_dbopt_cleanup(void)
 {
   rw_wrlock(&LOCK_dboptions);
-  hash_free(&dboptions);
-  hash_init(&dboptions, lower_case_table_names ? 
-            &my_charset_bin : system_charset_info,
-            32, 0, 0, (hash_get_key) dboptions_get_key,
-            free_dbopt,0);
+  my_hash_free(&dboptions);
+  my_hash_init(&dboptions, lower_case_table_names ? 
+               &my_charset_bin : system_charset_info,
+               32, 0, 0, (my_hash_get_key) dboptions_get_key,
+               free_dbopt,0);
   rw_unlock(&LOCK_dboptions);
 }
 
@@ -290,7 +290,7 @@ static my_bool get_dbopt(const char *dbn
   length= (uint) strlen(dbname);
   
   rw_rdlock(&LOCK_dboptions);
-  if ((opt= (my_dbopt_t*) hash_search(&dboptions, (uchar*) dbname, length)))
+  if ((opt= (my_dbopt_t*) my_hash_search(&dboptions, (uchar*) dbname, length)))
   {
     create->default_table_charset= opt->charset;
     error= 0;
@@ -322,7 +322,8 @@ static my_bool put_dbopt(const char *dbn
   length= (uint) strlen(dbname);
   
   rw_wrlock(&LOCK_dboptions);
-  if (!(opt= (my_dbopt_t*) hash_search(&dboptions, (uchar*) dbname, length)))
+  if (!(opt= (my_dbopt_t*) my_hash_search(&dboptions, (uchar*) dbname,
+                                          length)))
   { 
     /* Options are not in the hash, insert them */
     char *tmp_name;
@@ -362,9 +363,9 @@ void del_dbopt(const char *path)
 {
   my_dbopt_t *opt;
   rw_wrlock(&LOCK_dboptions);
-  if ((opt= (my_dbopt_t *)hash_search(&dboptions, (const uchar*) path,
-                                      strlen(path))))
-    hash_delete(&dboptions, (uchar*) opt);
+  if ((opt= (my_dbopt_t *)my_hash_search(&dboptions, (const uchar*) path,
+                                         strlen(path))))
+    my_hash_delete(&dboptions, (uchar*) opt);
   rw_unlock(&LOCK_dboptions);
 }
 
@@ -1724,8 +1725,8 @@ lock_databases(THD *thd, const char *db1
 {
   pthread_mutex_lock(&LOCK_lock_db);
   while (!thd->killed &&
-         (hash_search(&lock_db_cache,(uchar*) db1, length1) ||
-          hash_search(&lock_db_cache,(uchar*) db2, length2)))
+         (my_hash_search(&lock_db_cache,(uchar*) db1, length1) ||
+          my_hash_search(&lock_db_cache,(uchar*) db2, length2)))
   {
     wait_for_condition(thd, &LOCK_lock_db, &COND_refresh);
     pthread_mutex_lock(&LOCK_lock_db);

=== modified file 'sql/sql_error.cc'
--- a/sql/sql_error.cc	2009-01-27 13:03:36 +0000
+++ b/sql/sql_error.cc	2009-02-09 16:27:41 +0000
@@ -380,7 +380,7 @@ void push_warning_printf(THD *thd, MYSQL
 			 uint code, const char *format, ...)
 {
   va_list args;
-  char    warning[ERRMSGSIZE+20];
+  char    warning[MYSQL_ERRMSG_SIZE];
   DBUG_ENTER("push_warning_printf");
   DBUG_PRINT("enter",("warning: %u", code));
 

=== modified file 'sql/sql_handler.cc'
--- a/sql/sql_handler.cc	2008-08-07 17:52:43 +0000
+++ b/sql/sql_handler.cc	2009-01-27 02:08:48 +0000
@@ -199,15 +199,15 @@ bool mysql_ha_open(THD *thd, TABLE_LIST 
                       tables->db, tables->table_name, tables->alias,
                       (int) reopen));
 
-  if (! hash_inited(&thd->handler_tables_hash))
+  if (! my_hash_inited(&thd->handler_tables_hash))
   {
     /*
       HASH entries are of type TABLE_LIST.
     */
-    if (hash_init(&thd->handler_tables_hash, &my_charset_latin1,
-                  HANDLER_TABLES_HASH_SIZE, 0, 0,
-                  (hash_get_key) mysql_ha_hash_get_key,
-                  (hash_free_key) mysql_ha_hash_free, 0))
+    if (my_hash_init(&thd->handler_tables_hash, &my_charset_latin1,
+                     HANDLER_TABLES_HASH_SIZE, 0, 0,
+                     (my_hash_get_key) mysql_ha_hash_get_key,
+                     (my_hash_free_key) mysql_ha_hash_free, 0))
     {
       DBUG_PRINT("exit",("ERROR"));
       DBUG_RETURN(TRUE);
@@ -215,8 +215,8 @@ bool mysql_ha_open(THD *thd, TABLE_LIST 
   }
   else if (! reopen) /* Otherwise we have 'tables' already. */
   {
-    if (hash_search(&thd->handler_tables_hash, (uchar*) tables->alias,
-                    strlen(tables->alias) + 1))
+    if (my_hash_search(&thd->handler_tables_hash, (uchar*) tables->alias,
+                       strlen(tables->alias) + 1))
     {
       DBUG_PRINT("info",("duplicate '%s'", tables->alias));
       DBUG_PRINT("exit",("ERROR"));
@@ -328,7 +328,7 @@ err:
   if (hash_tables->table)
     mysql_ha_close_table(thd, hash_tables);
   if (!reopen)
-    hash_delete(&thd->handler_tables_hash, (uchar*) hash_tables);
+    my_hash_delete(&thd->handler_tables_hash, (uchar*) hash_tables);
   DBUG_PRINT("exit",("ERROR"));
   DBUG_RETURN(TRUE);
 }
@@ -358,12 +358,12 @@ bool mysql_ha_close(THD *thd, TABLE_LIST
   DBUG_PRINT("enter",("'%s'.'%s' as '%s'",
                       tables->db, tables->table_name, tables->alias));
 
-  if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash,
+  if ((hash_tables= (TABLE_LIST*) my_hash_search(&thd->handler_tables_hash,
                                               (uchar*) tables->alias,
                                               strlen(tables->alias) + 1)))
   {
     mysql_ha_close_table(thd, hash_tables);
-    hash_delete(&thd->handler_tables_hash, (uchar*) hash_tables);
+    my_hash_delete(&thd->handler_tables_hash, (uchar*) hash_tables);
   }
   else
   {
@@ -430,9 +430,9 @@ bool mysql_ha_read(THD *thd, TABLE_LIST 
   it++;
 
 retry:
-  if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash,
-                                              (uchar*) tables->alias,
-                                              strlen(tables->alias) + 1)))
+  if ((hash_tables= (TABLE_LIST*) my_hash_search(&thd->handler_tables_hash,
+                                                 (uchar*) tables->alias,
+                                                 strlen(tables->alias) + 1)))
   {
     table= hash_tables->table;
     DBUG_PRINT("info-in-hash",("'%s'.'%s' as '%s' table: %p",
@@ -703,7 +703,7 @@ static TABLE_LIST *mysql_ha_find(THD *th
   /* search for all handlers with matching table names */
   for (uint i= 0; i < thd->handler_tables_hash.records; i++)
   {
-    hash_tables= (TABLE_LIST*) hash_element(&thd->handler_tables_hash, i);
+    hash_tables= (TABLE_LIST*) my_hash_element(&thd->handler_tables_hash, i);
     for (tables= first; tables; tables= tables->next_local)
     {
       if ((! *tables->db ||
@@ -746,7 +746,7 @@ void mysql_ha_rm_tables(THD *thd, TABLE_
     next= hash_tables->next_local;
     if (hash_tables->table)
       mysql_ha_close_table(thd, hash_tables);
-    hash_delete(&thd->handler_tables_hash, (uchar*) hash_tables);
+    my_hash_delete(&thd->handler_tables_hash, (uchar*) hash_tables);
     hash_tables= next;
   }
 
@@ -772,7 +772,7 @@ void mysql_ha_flush(THD *thd)
 
   for (uint i= 0; i < thd->handler_tables_hash.records; i++)
   {
-    hash_tables= (TABLE_LIST*) hash_element(&thd->handler_tables_hash, i);
+    hash_tables= (TABLE_LIST*) my_hash_element(&thd->handler_tables_hash, i);
     /*
       TABLE::mdl_lock_data is 0 for temporary tables so we need extra check.
     */
@@ -806,12 +806,12 @@ void mysql_ha_cleanup(THD *thd)
 
   for (uint i= 0; i < thd->handler_tables_hash.records; i++)
   {
-    hash_tables= (TABLE_LIST*) hash_element(&thd->handler_tables_hash, i);
+    hash_tables= (TABLE_LIST*) my_hash_element(&thd->handler_tables_hash, i);
     if (hash_tables->table)
       mysql_ha_close_table(thd, hash_tables);
   }
 
-  hash_free(&thd->handler_tables_hash);
+  my_hash_free(&thd->handler_tables_hash);
 
   DBUG_VOID_RETURN;
 }

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2009-02-04 12:34:03 +0000
+++ b/sql/sql_lex.cc	2009-02-05 12:49:39 +0000
@@ -2171,7 +2171,7 @@ void Query_tables_list::reset_query_tabl
       We delay real initialization of hash (and therefore related
       memory allocation) until first insertion into this hash.
     */
-    hash_clear(&sroutines);
+    my_hash_clear(&sroutines);
   }
   else if (sroutines.records)
   {
@@ -2194,7 +2194,7 @@ void Query_tables_list::reset_query_tabl
 
 void Query_tables_list::destroy_query_tables_list()
 {
-  hash_free(&sroutines);
+  my_hash_free(&sroutines);
 }
 
 

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2009-02-04 12:34:03 +0000
+++ b/sql/sql_parse.cc	2009-02-05 12:49:39 +0000
@@ -5386,9 +5386,10 @@ bool check_stack_overrun(THD *thd, long 
   if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >=
       (long) (my_thread_stack_size - margin))
   {
-    sprintf(errbuff[0],ER(ER_STACK_OVERRUN_NEED_MORE),
-            stack_used,my_thread_stack_size,margin);
-    my_message(ER_STACK_OVERRUN_NEED_MORE,errbuff[0],MYF(ME_FATALERROR));
+    char ebuff[MYSQL_ERRMSG_SIZE];
+    my_snprintf(ebuff, sizeof(ebuff), ER(ER_STACK_OVERRUN_NEED_MORE),
+                stack_used, my_thread_stack_size, margin);
+    my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR));
     return 1;
   }
 #ifndef DBUG_OFF
@@ -5477,7 +5478,7 @@ void mysql_reset_thd_for_next_command(TH
     OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG to not get warnings
     in ha_rollback_trans() about some tables couldn't be rolled back.
   */
-  if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
+  if (!thd->in_multi_stmt_transaction())
   {
     thd->options&= ~OPTION_KEEP_LOG;
     thd->transaction.all.modified_non_trans_table= FALSE;

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2009-01-26 16:03:39 +0000
+++ b/sql/sql_plugin.cc	2009-01-31 16:21:19 +0000
@@ -566,14 +566,15 @@ static struct st_plugin_int *plugin_find
     for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
     {
       struct st_plugin_int *plugin= (st_plugin_int *)
-        hash_search(&plugin_hash[i], (const uchar *)name->str, name->length);
+        my_hash_search(&plugin_hash[i], (const uchar *)name->str, name->length);
       if (plugin)
         DBUG_RETURN(plugin);
     }
   }
   else
     DBUG_RETURN((st_plugin_int *)
-        hash_search(&plugin_hash[type], (const uchar *)name->str, name->length));
+        my_hash_search(&plugin_hash[type], (const uchar *)name->str,
+                       name->length));
   DBUG_RETURN(0);
 }
 
@@ -850,7 +851,7 @@ static void plugin_del(struct st_plugin_
   safe_mutex_assert_owner(&LOCK_plugin);
   /* Free allocated strings before deleting the plugin. */
   plugin_vars_free_values(plugin->system_vars);
-  hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin);
+  my_hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin);
   if (plugin->plugin_dl)
     plugin_dl_del(&plugin->plugin_dl->dl);
   plugin->state= PLUGIN_IS_FREED;
@@ -1111,8 +1112,8 @@ int plugin_init(int *argc, char **argv, 
   init_alloc_root(&plugin_mem_root, 4096, 4096);
   init_alloc_root(&tmp_root, 4096, 4096);
 
-  if (hash_init(&bookmark_hash, &my_charset_bin, 16, 0, 0,
-                  get_bookmark_hash_key, NULL, HASH_UNIQUE))
+  if (my_hash_init(&bookmark_hash, &my_charset_bin, 16, 0, 0,
+                   get_bookmark_hash_key, NULL, HASH_UNIQUE))
       goto err;
 
 
@@ -1126,8 +1127,8 @@ int plugin_init(int *argc, char **argv, 
 
   for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
   {
-    if (hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0,
-                  get_plugin_hash_key, NULL, HASH_UNIQUE))
+    if (my_hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0,
+                     get_plugin_hash_key, NULL, HASH_UNIQUE))
       goto err;
   }
 
@@ -1604,7 +1605,7 @@ void plugin_shutdown(void)
   /* Dispose of the memory */
 
   for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
-    hash_free(&plugin_hash[i]);
+    my_hash_free(&plugin_hash[i]);
   delete_dynamic(&plugin_array);
 
   count= plugin_dl_array.elements;
@@ -1616,7 +1617,7 @@ void plugin_shutdown(void)
   my_afree(dl);
   delete_dynamic(&plugin_dl_array);
 
-  hash_free(&bookmark_hash);
+  my_hash_free(&bookmark_hash);
   free_root(&plugin_mem_root, MYF(0));
 
   global_variables_dynamic_size= 0;
@@ -1797,7 +1798,7 @@ bool plugin_foreach_with_mask(THD *thd, 
     HASH *hash= plugin_hash + type;
     for (idx= 0; idx < total; idx++)
     {
-      plugin= (struct st_plugin_int *) hash_element(hash, idx);
+      plugin= (struct st_plugin_int *) my_hash_element(hash, idx);
       plugins[idx]= !(plugin->state & state_mask) ? plugin : NULL;
     }
   }
@@ -2196,8 +2197,8 @@ static st_bookmark *find_bookmark(const 
 
   varname[0]= flags & PLUGIN_VAR_TYPEMASK;
 
-  result= (st_bookmark*) hash_search(&bookmark_hash,
-                                     (const uchar*) varname, length - 1);
+  result= (st_bookmark*) my_hash_search(&bookmark_hash,
+                                        (const uchar*) varname, length - 1);
 
   my_afree(varname);
   return result;
@@ -2357,7 +2358,7 @@ static uchar *intern_sys_var_ptr(THD* th
     {
       sys_var_pluginvar *pi;
       sys_var *var;
-      st_bookmark *v= (st_bookmark*) hash_element(&bookmark_hash,idx);
+      st_bookmark *v= (st_bookmark*) my_hash_element(&bookmark_hash,idx);
 
       if (v->version <= thd->variables.dynamic_variables_version ||
           !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
@@ -2451,7 +2452,7 @@ static void cleanup_variables(THD *thd, 
   rw_rdlock(&LOCK_system_variables_hash);
   for (idx= 0; idx < bookmark_hash.records; idx++)
   {
-    v= (st_bookmark*) hash_element(&bookmark_hash, idx);
+    v= (st_bookmark*) my_hash_element(&bookmark_hash, idx);
     if (v->version > vars->dynamic_variables_version ||
         !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
         !(pivar= var->cast_pluginvar()) ||

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2009-01-18 23:21:43 +0000
+++ b/sql/sql_prepare.cc	2009-01-31 16:21:19 +0000
@@ -1100,9 +1100,9 @@ static bool insert_params_from_vars(Prep
   {
     Item_param *param= *it;
     varname= var_it++;
-    entry= (user_var_entry*)hash_search(&stmt->thd->user_vars,
-                                        (uchar*) varname->str,
-                                         varname->length);
+    entry= (user_var_entry*)my_hash_search(&stmt->thd->user_vars,
+                                           (uchar*) varname->str,
+                                           varname->length);
     if (param->set_from_user_var(stmt->thd, entry) ||
         param->convert_str_value(stmt->thd))
       DBUG_RETURN(1);
@@ -1147,8 +1147,8 @@ static bool insert_params_from_vars_with
     Item_param *param= *it;
     varname= var_it++;
 
-    entry= (user_var_entry *) hash_search(&thd->user_vars, (uchar*) varname->str,
-                                          varname->length);
+    entry= (user_var_entry *) my_hash_search(&thd->user_vars, (uchar*)
+                                             varname->str, varname->length);
     /*
       We have to call the setup_one_conversion_function() here to set
       the parameter's members that might be needed further
@@ -2216,9 +2216,9 @@ static const char *get_dynamic_sql_strin
       convert it for error messages to be uniform.
     */
     if ((entry=
-         (user_var_entry*)hash_search(&thd->user_vars,
-                                      (uchar*)lex->prepared_stmt_code.str,
-                                      lex->prepared_stmt_code.length))
+         (user_var_entry*)my_hash_search(&thd->user_vars,
+                                         (uchar*)lex->prepared_stmt_code.str,
+                                         lex->prepared_stmt_code.length))
         && entry->value)
     {
       my_bool is_var_null;

=== modified file 'sql/sql_repl.cc'
--- a/sql/sql_repl.cc	2009-02-05 12:22:39 +0000
+++ b/sql/sql_repl.cc	2009-02-09 16:27:41 +0000
@@ -353,8 +353,8 @@ static ulonglong get_heartbeat_period(TH
   my_bool null_value;
   LEX_STRING name=  { C_STRING_WITH_LEN("master_heartbeat_period")};
   user_var_entry *entry= 
-    (user_var_entry*) hash_search(&thd->user_vars, (uchar*) name.str,
-                                  name.length);
+    (user_var_entry*) my_hash_search(&thd->user_vars, (uchar*) name.str,
+                                     name.length);
   return entry? entry->val_int(&null_value) : 0;
 }
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2009-02-04 12:34:03 +0000
+++ b/sql/sql_select.cc	2009-02-05 12:49:39 +0000
@@ -19291,8 +19291,8 @@ static int remove_dup_with_hash_index(TH
     extra_length= ALIGN_SIZE(key_length)-key_length;
   }
 
-  if (hash_init(&hash, &my_charset_bin, (uint) file->stats.records, 0, 
-		key_length, (hash_get_key) 0, 0, 0))
+  if (my_hash_init(&hash, &my_charset_bin, (uint) file->stats.records, 0, 
+                   key_length, (my_hash_get_key) 0, 0, 0))
   {
     my_free((char*) key_buffer,MYF(0));
     DBUG_RETURN(1);
@@ -19333,7 +19333,7 @@ static int remove_dup_with_hash_index(TH
       key_pos+= *field_length++;
     }
     /* Check if it exists before */
-    if (hash_search(&hash, org_key_pos, key_length))
+    if (my_hash_search(&hash, org_key_pos, key_length))
     {
       /* Duplicated found ; Remove the row */
       if ((error=file->ha_delete_row(record)))
@@ -19344,14 +19344,14 @@ static int remove_dup_with_hash_index(TH
     key_pos+=extra_length;
   }
   my_free((char*) key_buffer,MYF(0));
-  hash_free(&hash);
+  my_hash_free(&hash);
   file->extra(HA_EXTRA_NO_CACHE);
   (void) file->ha_rnd_end();
   DBUG_RETURN(0);
 
 err:
   my_free((char*) key_buffer,MYF(0));
-  hash_free(&hash);
+  my_hash_free(&hash);
   file->extra(HA_EXTRA_NO_CACHE);
   (void) file->ha_rnd_end();
   if (error)

=== modified file 'sql/sql_servers.cc'
--- a/sql/sql_servers.cc	2008-12-04 16:50:07 +0000
+++ b/sql/sql_servers.cc	2009-01-27 02:08:48 +0000
@@ -120,8 +120,8 @@ bool servers_init(bool dont_read_servers
     DBUG_RETURN(TRUE);
 
   /* initialise our servers cache */
-  if (hash_init(&servers_cache, system_charset_info, 32, 0, 0,
-                (hash_get_key) servers_cache_get_key, 0, 0))
+  if (my_hash_init(&servers_cache, system_charset_info, 32, 0, 0,
+                   (my_hash_get_key) servers_cache_get_key, 0, 0))
   {
     return_val= TRUE; /* we failed, out of memory? */
     goto end;
@@ -644,9 +644,10 @@ delete_server_record_in_cache(LEX_SERVER
                      server_options->server_name_length));
 
 
-  if (!(server= (FOREIGN_SERVER *) hash_search(&servers_cache,
-                                     (uchar*) server_options->server_name,
-                                     server_options->server_name_length)))
+  if (!(server= (FOREIGN_SERVER *)
+        my_hash_search(&servers_cache,
+                       (uchar*) server_options->server_name,
+                       server_options->server_name_length)))
   {
     DBUG_PRINT("info", ("server_name %s length %d not found!",
                         server_options->server_name,
@@ -661,8 +662,8 @@ delete_server_record_in_cache(LEX_SERVER
                      server->server_name,
                      server->server_name_length));
 
-  hash_delete(&servers_cache, (uchar*) server);
-  
+  my_hash_delete(&servers_cache, (uchar*) server);
+
   error= 0;
 
 end:
@@ -769,7 +770,7 @@ int update_server_record_in_cache(FOREIG
   /*
     delete the existing server struct from the server cache
   */
-  hash_delete(&servers_cache, (uchar*)existing);
+  my_hash_delete(&servers_cache, (uchar*)existing);
 
   /*
     Insert the altered server struct into the server cache
@@ -964,8 +965,8 @@ int create_server(THD *thd, LEX_SERVER_O
   rw_wrlock(&THR_LOCK_servers);
 
   /* hit the memory first */
-  if (hash_search(&servers_cache, (uchar*) server_options->server_name,
-				   server_options->server_name_length))
+  if (my_hash_search(&servers_cache, (uchar*) server_options->server_name,
+                     server_options->server_name_length))
     goto end;
 
 
@@ -1013,9 +1014,9 @@ int alter_server(THD *thd, LEX_SERVER_OP
 
   rw_wrlock(&THR_LOCK_servers);
 
-  if (!(existing= (FOREIGN_SERVER *) hash_search(&servers_cache,
-                                                 (uchar*) name.str,
-                                                 name.length)))
+  if (!(existing= (FOREIGN_SERVER *) my_hash_search(&servers_cache,
+                                                    (uchar*) name.str,
+                                                    name.length)))
     goto end;
 
   altered= (FOREIGN_SERVER *)alloc_root(&mem,
@@ -1194,7 +1195,7 @@ prepare_server_struct_for_update(LEX_SER
 void servers_free(bool end)
 {
   DBUG_ENTER("servers_free");
-  if (!hash_inited(&servers_cache))
+  if (!my_hash_inited(&servers_cache))
     DBUG_VOID_RETURN;
   if (!end)
   {
@@ -1204,7 +1205,7 @@ void servers_free(bool end)
   }
   rwlock_destroy(&THR_LOCK_servers);
   free_root(&mem,MYF(0));
-  hash_free(&servers_cache);
+  my_hash_free(&servers_cache);
   DBUG_VOID_RETURN;
 }
 
@@ -1285,9 +1286,9 @@ FOREIGN_SERVER *get_server_by_name(MEM_R
 
   DBUG_PRINT("info", ("locking servers_cache"));
   rw_rdlock(&THR_LOCK_servers);
-  if (!(server= (FOREIGN_SERVER *) hash_search(&servers_cache,
-                                               (uchar*) server_name,
-                                               server_name_length)))
+  if (!(server= (FOREIGN_SERVER *) my_hash_search(&servers_cache,
+                                                  (uchar*) server_name,
+                                                  server_name_length)))
   {
     DBUG_PRINT("info", ("server_name %s length %d not found!",
                         server_name, server_name_length));

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-02-02 15:58:48 +0000
+++ b/sql/sql_table.cc	2009-02-05 12:49:39 +0000
@@ -3785,6 +3785,8 @@ static bool lock_table_name_if_not_cache
     }
     else
       *lock_data= 0;
+  } else {
+    DEBUG_SYNC(thd, "locked_table_name");
   }
   return FALSE;
 }
@@ -3813,7 +3815,7 @@ bool mysql_create_table(THD *thd, const 
   /* Wait for any database locks */
   pthread_mutex_lock(&LOCK_lock_db);
   while (!thd->killed &&
-         hash_search(&lock_db_cache,(uchar*) db, strlen(db)))
+         my_hash_search(&lock_db_cache,(uchar*) db, strlen(db)))
   {
     wait_for_condition(thd, &LOCK_lock_db, &COND_refresh);
     pthread_mutex_lock(&LOCK_lock_db);
@@ -4495,8 +4497,8 @@ send_result_message:
     switch (result_code) {
     case HA_ADMIN_NOT_IMPLEMENTED:
       {
-	char buf[ERRMSGSIZE+20];
-	uint length=my_snprintf(buf, ERRMSGSIZE,
+	char buf[MYSQL_ERRMSG_SIZE];
+	uint length=my_snprintf(buf, sizeof(buf),
 				ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
 	protocol->store(STRING_WITH_LEN("note"), system_charset_info);
 	protocol->store(buf, length, system_charset_info);
@@ -4505,8 +4507,8 @@ send_result_message:
 
     case HA_ADMIN_NOT_BASE_TABLE:
       {
-        char buf[ERRMSGSIZE+20];
-        uint length= my_snprintf(buf, ERRMSGSIZE,
+        char buf[MYSQL_ERRMSG_SIZE];
+        uint length= my_snprintf(buf, sizeof(buf),
                                  ER(ER_BAD_TABLE_ERROR), table_name);
         protocol->store(STRING_WITH_LEN("note"), system_charset_info);
         protocol->store(buf, length, system_charset_info);
@@ -4633,11 +4635,12 @@ send_result_message:
     case HA_ADMIN_NEEDS_UPGRADE:
     case HA_ADMIN_NEEDS_ALTER:
     {
-      char buf[ERRMSGSIZE];
+      char buf[MYSQL_ERRMSG_SIZE];
       uint length;
 
       protocol->store(STRING_WITH_LEN("error"), system_charset_info);
-      length=my_snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
+      length=my_snprintf(buf, sizeof(buf), ER(ER_TABLE_NEEDS_UPGRADE),
+                         table->table_name);
       protocol->store(buf, length, system_charset_info);
       fatal_error=1;
       break;
@@ -4645,8 +4648,8 @@ send_result_message:
 
     default:				// Probably HA_ADMIN_INTERNAL_ERROR
       {
-        char buf[ERRMSGSIZE+20];
-        uint length=my_snprintf(buf, ERRMSGSIZE,
+        char buf[MYSQL_ERRMSG_SIZE];
+        uint length=my_snprintf(buf, sizeof(buf),
                                 "Unknown - internal error %d during operation",
                                 result_code);
         protocol->store(STRING_WITH_LEN("error"), system_charset_info);

=== modified file 'sql/sql_test.cc'
--- a/sql/sql_test.cc	2009-01-27 14:53:22 +0000
+++ b/sql/sql_test.cc	2009-01-31 16:21:19 +0000
@@ -82,7 +82,7 @@ void print_cached_tables(void)
 
   for (idx=unused=0 ; idx < table_def_cache.records ; idx++)
   {
-    share= (TABLE_SHARE*) hash_element(&table_def_cache, idx);
+    share= (TABLE_SHARE*) my_hash_element(&table_def_cache, idx);
 
     I_P_List_iterator<TABLE, TABLE_share> it(share->used_tables);
     while ((entry= it++))
@@ -121,7 +121,7 @@ void print_cached_tables(void)
     printf("Unused_links (%d) doesn't match table_def_cache: %d\n", count,
            unused);
   printf("\nCurrent refresh version: %ld\n",refresh_version);
-  if (hash_check(&table_def_cache))
+  if (my_hash_check(&table_def_cache))
     printf("Error: Table definition hash table is corrupted\n");
   fflush(stdout);
   pthread_mutex_unlock(&LOCK_open);

=== modified file 'sql/sql_udf.cc'
--- a/sql/sql_udf.cc	2009-01-16 11:53:32 +0000
+++ b/sql/sql_udf.cc	2009-01-27 02:08:48 +0000
@@ -124,10 +124,10 @@ void udf_init()
   init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0);
   THD *new_thd = new THD;
   if (!new_thd ||
-      hash_init(&udf_hash,system_charset_info,32,0,0,get_hash_key, NULL, 0))
+      my_hash_init(&udf_hash,system_charset_info,32,0,0,get_hash_key, NULL, 0))
   {
     sql_print_error("Can't allocate memory for udf structures");
-    hash_free(&udf_hash);
+    my_hash_free(&udf_hash);
     free_root(&mem,MYF(0));
     delete new_thd;
     DBUG_VOID_RETURN;
@@ -238,20 +238,20 @@ void udf_free()
   DBUG_ENTER("udf_free");
   for (uint idx=0 ; idx < udf_hash.records ; idx++)
   {
-    udf_func *udf=(udf_func*) hash_element(&udf_hash,idx);
+    udf_func *udf=(udf_func*) my_hash_element(&udf_hash,idx);
     if (udf->dlhandle)				// Not closed before
     {
       /* Mark all versions using the same handler as closed */
       for (uint j=idx+1 ;  j < udf_hash.records ; j++)
       {
-	udf_func *tmp=(udf_func*) hash_element(&udf_hash,j);
+	udf_func *tmp=(udf_func*) my_hash_element(&udf_hash,j);
 	if (udf->dlhandle == tmp->dlhandle)
 	  tmp->dlhandle=0;			// Already closed
       }
       dlclose(udf->dlhandle);
     }
   }
-  hash_free(&udf_hash);
+  my_hash_free(&udf_hash);
   free_root(&mem,MYF(0));
   if (initialized)
   {
@@ -267,7 +267,7 @@ static void del_udf(udf_func *udf)
   DBUG_ENTER("del_udf");
   if (!--udf->usage_count)
   {
-    hash_delete(&udf_hash,(uchar*) udf);
+    my_hash_delete(&udf_hash,(uchar*) udf);
     using_udf_functions=udf_hash.records != 0;
   }
   else
@@ -281,7 +281,7 @@ static void del_udf(udf_func *udf)
     uint name_length=udf->name.length;
     udf->name.str=(char*) "*";
     udf->name.length=1;
-    hash_update(&udf_hash,(uchar*) udf,(uchar*) name,name_length);
+    my_hash_update(&udf_hash,(uchar*) udf,(uchar*) name,name_length);
   }
   DBUG_VOID_RETURN;
 }
@@ -301,7 +301,7 @@ void free_udf(udf_func *udf)
       We come here when someone has deleted the udf function
       while another thread still was using the udf
     */
-    hash_delete(&udf_hash,(uchar*) udf);
+    my_hash_delete(&udf_hash,(uchar*) udf);
     using_udf_functions=udf_hash.records != 0;
     if (!find_udf_dl(udf->dl))
       dlclose(udf->dlhandle);
@@ -327,8 +327,8 @@ udf_func *find_udf(const char *name,uint
   else
     rw_rdlock(&THR_LOCK_udf);  /* Called during parsing */
 
-  if ((udf=(udf_func*) hash_search(&udf_hash,(uchar*) name,
-				   length ? length : (uint) strlen(name))))
+  if ((udf=(udf_func*) my_hash_search(&udf_hash,(uchar*) name,
+                                      length ? length : (uint) strlen(name))))
   {
     if (!udf->dlhandle)
       udf=0;					// Could not be opened
@@ -350,7 +350,7 @@ static void *find_udf_dl(const char *dl)
   */
   for (uint idx=0 ; idx < udf_hash.records ; idx++)
   {
-    udf_func *udf=(udf_func*) hash_element(&udf_hash,idx);
+    udf_func *udf=(udf_func*) my_hash_element(&udf_hash,idx);
     if (!strcmp(dl, udf->dl) && udf->dlhandle != NULL)
       DBUG_RETURN(udf->dlhandle);
   }
@@ -436,7 +436,7 @@ int mysql_create_function(THD *thd,udf_f
     thd->clear_current_stmt_binlog_row_based();
 
   rw_wrlock(&THR_LOCK_udf);
-  if ((hash_search(&udf_hash,(uchar*) udf->name.str, udf->name.length)))
+  if ((my_hash_search(&udf_hash,(uchar*) udf->name.str, udf->name.length)))
   {
     my_error(ER_UDF_EXISTS, MYF(0), udf->name.str);
     goto err;
@@ -540,8 +540,8 @@ int mysql_drop_function(THD *thd,const L
     thd->clear_current_stmt_binlog_row_based();
 
   rw_wrlock(&THR_LOCK_udf);  
-  if (!(udf=(udf_func*) hash_search(&udf_hash,(uchar*) udf_name->str,
-				    (uint) udf_name->length)))
+  if (!(udf=(udf_func*) my_hash_search(&udf_hash,(uchar*) udf_name->str,
+                                       (uint) udf_name->length)))
   {
     my_error(ER_FUNCTION_NOT_DEFINED, MYF(0), udf_name->str);
     goto err;

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2009-02-05 11:03:46 +0000
+++ b/sql/table.cc	2009-02-09 16:27:41 +0000
@@ -474,7 +474,7 @@ void free_table_share(TABLE_SHARE *share
   /* The mutex is initialized only for shares that are part of the TDC */
   if (share->tmp_table == NO_TMP_TABLE)
     pthread_mutex_destroy(&share->LOCK_ha_data);
-  hash_free(&share->name_hash);
+  my_hash_free(&share->name_hash);
 
   plugin_unlock(NULL, share->db_plugin);
   share->db_plugin= NULL;
@@ -1263,10 +1263,10 @@ static int open_binary_frm(THD *thd, TAB
 
   use_hash= share->fields >= MAX_FIELDS_BEFORE_HASH;
   if (use_hash)
-    use_hash= !hash_init(&share->name_hash,
-			 system_charset_info,
-			 share->fields,0,0,
-			 (hash_get_key) get_field_name,0,0);
+    use_hash= !my_hash_init(&share->name_hash,
+                            system_charset_info,
+                            share->fields,0,0,
+                            (my_hash_get_key) get_field_name,0,0);
 
   for (i=0 ; i < share->fields; i++, strpos+=field_pack_length, field_ptr++)
   {
@@ -1710,7 +1710,7 @@ static int open_binary_frm(THD *thd, TAB
   delete handler_file;
 #ifndef DBUG_OFF
   if (use_hash)
-    (void) hash_check(&share->name_hash);
+    (void) my_hash_check(&share->name_hash);
 #endif
   if (buffbuff)
     my_free(buffbuff, MYF(0));
@@ -1725,7 +1725,7 @@ static int open_binary_frm(THD *thd, TAB
   x_free((uchar*) disk_buff);
   delete crypted;
   delete handler_file;
-  hash_free(&share->name_hash);
+  my_hash_free(&share->name_hash);
 
   open_table_error(share, error, share->open_errno, errarg);
   DBUG_RETURN(error);

=== modified file 'sql/transaction.cc'
--- a/sql/transaction.cc	2008-12-04 16:50:07 +0000
+++ b/sql/transaction.cc	2009-01-26 17:19:14 +0000
@@ -165,8 +165,7 @@ bool trans_commit_implicit(THD *thd)
   if (trans_check(thd))
     DBUG_RETURN(TRUE);
 
-  if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
-                      OPTION_TABLE_LOCK))
+  if (thd->in_multi_stmt_transaction() || (thd->options & OPTION_TABLE_LOCK))
   {
     /* Safety if one did "drop table" on locked tables */
     if (!thd->locked_tables_mode)
@@ -304,8 +303,8 @@ bool trans_savepoint(THD *thd, LEX_STRIN
   SAVEPOINT **sv, *newsv;
   DBUG_ENTER("trans_savepoint");
 
-  if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
-        thd->in_sub_stmt) || !opt_using_transactions)
+  if (!(thd->in_multi_stmt_transaction() || thd->in_sub_stmt) ||
+      !opt_using_transactions)
     DBUG_RETURN(FALSE);
 
   sv= find_savepoint(thd, name);

=== modified file 'sql/tztime.cc'
--- a/sql/tztime.cc	2009-01-16 11:53:32 +0000
+++ b/sql/tztime.cc	2009-01-27 02:08:48 +0000
@@ -1580,17 +1580,17 @@ my_tz_init(THD *org_thd, const char *def
   thd->store_globals();
 
   /* Init all memory structures that require explicit destruction */
-  if (hash_init(&tz_names, &my_charset_latin1, 20,
-                0, 0, (hash_get_key) my_tz_names_get_key, 0, 0))
+  if (my_hash_init(&tz_names, &my_charset_latin1, 20,
+                   0, 0, (my_hash_get_key) my_tz_names_get_key, 0, 0))
   {
     sql_print_error("Fatal error: OOM while initializing time zones");
     goto end;
   }
-  if (hash_init(&offset_tzs, &my_charset_latin1, 26, 0, 0,
-                (hash_get_key)my_offset_tzs_get_key, 0, 0))
+  if (my_hash_init(&offset_tzs, &my_charset_latin1, 26, 0, 0,
+                   (my_hash_get_key)my_offset_tzs_get_key, 0, 0))
   {
     sql_print_error("Fatal error: OOM while initializing time zones");
-    hash_free(&tz_names);
+    my_hash_free(&tz_names);
     goto end;
   }
   init_sql_alloc(&tz_storage, 32 * 1024, 0);
@@ -1773,8 +1773,8 @@ void my_tz_free()
   {
     tz_inited= 0;
     pthread_mutex_destroy(&tz_LOCK);
-    hash_free(&offset_tzs);
-    hash_free(&tz_names);
+    my_hash_free(&offset_tzs);
+    my_hash_free(&tz_names);
     free_root(&tz_storage, MYF(0));
   }
 }
@@ -2238,9 +2238,9 @@ my_tz_find(THD *thd, const String *name)
   if (!str_to_offset(name->ptr(), name->length(), &offset))
   {
 
-    if (!(result_tz= (Time_zone_offset *)hash_search(&offset_tzs,
-                                                     (const uchar *)&offset,
-                                                     sizeof(long))))
+    if (!(result_tz= (Time_zone_offset *)my_hash_search(&offset_tzs,
+                                                        (const uchar *)&offset,
+                                                        sizeof(long))))
     {
       DBUG_PRINT("info", ("Creating new Time_zone_offset object"));
 
@@ -2256,9 +2256,10 @@ my_tz_find(THD *thd, const String *name)
   else
   {
     result_tz= 0;
-    if ((tmp_tzname= (Tz_names_entry *)hash_search(&tz_names,
-                                                   (const uchar *)name->ptr(),
-                                                   name->length())))
+    if ((tmp_tzname= (Tz_names_entry *)my_hash_search(&tz_names,
+                                                      (const uchar *)
+                                                      name->ptr(),
+                                                      name->length())))
       result_tz= tmp_tzname->tz;
     else if (time_zone_tables_exist)
     {

=== modified file 'storage/archive/ha_archive.cc'
--- a/storage/archive/ha_archive.cc	2009-01-19 13:16:25 +0000
+++ b/storage/archive/ha_archive.cc	2009-01-27 02:08:48 +0000
@@ -177,8 +177,8 @@ int archive_db_init(void *p)
 
   if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST))
     goto error;
-  if (hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0,
-                (hash_get_key) archive_get_key, 0, 0))
+  if (my_hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0,
+                (my_hash_get_key) archive_get_key, 0, 0))
   {
     pthread_mutex_destroy(&archive_mutex);
   }
@@ -203,7 +203,7 @@ error:
 
 int archive_db_done(void *p)
 {
-  hash_free(&archive_open_tables);
+  my_hash_free(&archive_open_tables);
   pthread_mutex_destroy(&archive_mutex);
 
   return 0;
@@ -293,9 +293,9 @@ ARCHIVE_SHARE *ha_archive::get_share(con
   pthread_mutex_lock(&archive_mutex);
   length=(uint) strlen(table_name);
 
-  if (!(share=(ARCHIVE_SHARE*) hash_search(&archive_open_tables,
-                                           (uchar*) table_name,
-                                           length)))
+  if (!(share=(ARCHIVE_SHARE*) my_hash_search(&archive_open_tables,
+                                              (uchar*) table_name,
+                                              length)))
   {
     char *tmp_name;
     azio_stream archive_tmp;
@@ -381,7 +381,7 @@ int ha_archive::free_share()
   pthread_mutex_lock(&archive_mutex);
   if (!--share->use_count)
   {
-    hash_delete(&archive_open_tables, (uchar*) share);
+    my_hash_delete(&archive_open_tables, (uchar*) share);
     thr_lock_delete(&share->lock);
     pthread_mutex_destroy(&share->mutex);
     /* 

=== modified file 'storage/blackhole/ha_blackhole.cc'
--- a/storage/blackhole/ha_blackhole.cc	2008-12-17 18:40:14 +0000
+++ b/storage/blackhole/ha_blackhole.cc	2009-01-27 02:08:48 +0000
@@ -277,8 +277,9 @@ static st_blackhole_share *get_share(con
   length= (uint) strlen(table_name);
   pthread_mutex_lock(&blackhole_mutex);
     
-  if (!(share= (st_blackhole_share*) hash_search(&blackhole_open_tables,
-                                                 (uchar*) table_name, length)))
+  if (!(share= (st_blackhole_share*)
+        my_hash_search(&blackhole_open_tables,
+                       (uchar*) table_name, length)))
   {
     if (!(share= (st_blackhole_share*) my_malloc(sizeof(st_blackhole_share) +
                                                  length,
@@ -308,7 +309,7 @@ static void free_share(st_blackhole_shar
 {
   pthread_mutex_lock(&blackhole_mutex);
   if (!--share->use_count)
-    hash_delete(&blackhole_open_tables, (uchar*) share);
+    my_hash_delete(&blackhole_open_tables, (uchar*) share);
   pthread_mutex_unlock(&blackhole_mutex);
 }
 
@@ -335,16 +336,16 @@ static int blackhole_init(void *p)
   blackhole_hton->flags= HTON_CAN_RECREATE;
   
   pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST);
-  (void) hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
-                   (hash_get_key) blackhole_get_key,
-                   (hash_free_key) blackhole_free_key, 0);
+  (void) my_hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
+                      (my_hash_get_key) blackhole_get_key,
+                      (my_hash_free_key) blackhole_free_key, 0);
 
   return 0;
 }
 
 static int blackhole_fini(void *p)
 {
-  hash_free(&blackhole_open_tables);
+  my_hash_free(&blackhole_open_tables);
   pthread_mutex_destroy(&blackhole_mutex);
 
   return 0;

=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc	2009-02-02 12:28:30 +0000
+++ b/storage/csv/ha_tina.cc	2009-02-05 12:49:39 +0000
@@ -109,8 +109,8 @@ static int tina_init_func(void *p)
 
   tina_hton= (handlerton *)p;
   pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST);
-  (void) hash_init(&tina_open_tables,system_charset_info,32,0,0,
-                   (hash_get_key) tina_get_key,0,0);
+  (void) my_hash_init(&tina_open_tables,system_charset_info,32,0,0,
+                      (my_hash_get_key) tina_get_key,0,0);
   tina_hton->state= SHOW_OPTION_YES;
   tina_hton->db_type= DB_TYPE_CSV_DB;
   tina_hton->create= tina_create_handler;
@@ -121,7 +121,7 @@ static int tina_init_func(void *p)
 
 static int tina_done_func(void *p)
 {
-  hash_free(&tina_open_tables);
+  my_hash_free(&tina_open_tables);
   pthread_mutex_destroy(&tina_mutex);
 
   return 0;
@@ -146,9 +146,9 @@ static TINA_SHARE *get_share(const char 
     If share is not present in the hash, create a new share and
     initialize its members.
   */
-  if (!(share=(TINA_SHARE*) hash_search(&tina_open_tables,
-                                        (uchar*) table_name,
-                                       length)))
+  if (!(share=(TINA_SHARE*) my_hash_search(&tina_open_tables,
+                                           (uchar*) table_name,
+                                           length)))
   {
     if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
                          &share, sizeof(*share),
@@ -376,7 +376,7 @@ static int free_share(TINA_SHARE *share)
       share->tina_write_opened= FALSE;
     }
 
-    hash_delete(&tina_open_tables, (uchar*) share);
+    my_hash_delete(&tina_open_tables, (uchar*) share);
     thr_lock_delete(&share->lock);
     pthread_mutex_destroy(&share->mutex);
     my_free((uchar*) share, MYF(0));

=== modified file 'storage/example/ha_example.cc'
--- a/storage/example/ha_example.cc	2008-04-09 00:56:49 +0000
+++ b/storage/example/ha_example.cc	2009-01-27 02:08:48 +0000
@@ -132,8 +132,8 @@ static int example_init_func(void *p)
 
   example_hton= (handlerton *)p;
   pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST);
-  (void) hash_init(&example_open_tables,system_charset_info,32,0,0,
-                   (hash_get_key) example_get_key,0,0);
+  (void) my_hash_init(&example_open_tables,system_charset_info,32,0,0,
+                      (my_hash_get_key) example_get_key,0,0);
 
   example_hton->state=   SHOW_OPTION_YES;
   example_hton->create=  example_create_handler;
@@ -150,7 +150,7 @@ static int example_done_func(void *p)
 
   if (example_open_tables.records)
     error= 1;
-  hash_free(&example_open_tables);
+  my_hash_free(&example_open_tables);
   pthread_mutex_destroy(&example_mutex);
 
   DBUG_RETURN(0);
@@ -174,9 +174,9 @@ static EXAMPLE_SHARE *get_share(const ch
   pthread_mutex_lock(&example_mutex);
   length=(uint) strlen(table_name);
 
-  if (!(share=(EXAMPLE_SHARE*) hash_search(&example_open_tables,
-                                           (uchar*) table_name,
-                                           length)))
+  if (!(share=(EXAMPLE_SHARE*) my_hash_search(&example_open_tables,
+                                              (uchar*) table_name,
+                                              length)))
   {
     if (!(share=(EXAMPLE_SHARE *)
           my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
@@ -221,7 +221,7 @@ static int free_share(EXAMPLE_SHARE *sha
   pthread_mutex_lock(&example_mutex);
   if (!--share->use_count)
   {
-    hash_delete(&example_open_tables, (uchar*) share);
+    my_hash_delete(&example_open_tables, (uchar*) share);
     thr_lock_delete(&share->lock);
     pthread_mutex_destroy(&share->mutex);
     my_free(share, MYF(0));

=== modified file 'storage/federated/ha_federated.cc'
--- a/storage/federated/ha_federated.cc	2009-01-26 16:03:39 +0000
+++ b/storage/federated/ha_federated.cc	2009-01-31 16:21:19 +0000
@@ -458,8 +458,8 @@ int federated_db_init(void *p)
 
   if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST))
     goto error;
-  if (!hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0,
-                    (hash_get_key) federated_get_key, 0, 0))
+  if (!my_hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0,
+                    (my_hash_get_key) federated_get_key, 0, 0))
   {
     DBUG_RETURN(FALSE);
   }
@@ -482,7 +482,7 @@ error:
 
 int federated_done(void *p)
 {
-  hash_free(&federated_open_tables);
+  my_hash_free(&federated_open_tables);
   pthread_mutex_destroy(&federated_mutex);
 
   return 0;
@@ -1492,10 +1492,10 @@ static FEDERATED_SHARE *get_share(const 
     goto error;
 
   /* TODO: change tmp_share.scheme to LEX_STRING object */
-  if (!(share= (FEDERATED_SHARE *) hash_search(&federated_open_tables,
-                                               (uchar*) tmp_share.share_key,
-                                               tmp_share.
-                                               share_key_length)))
+  if (!(share= (FEDERATED_SHARE *) my_hash_search(&federated_open_tables,
+                                                  (uchar*) tmp_share.share_key,
+                                                  tmp_share.
+                                                  share_key_length)))
   {
     query.set_charset(system_charset_info);
     query.append(STRING_WITH_LEN("SELECT "));
@@ -1557,7 +1557,7 @@ static int free_share(FEDERATED_SHARE *s
   pthread_mutex_lock(&federated_mutex);
   if (!--share->use_count)
   {
-    hash_delete(&federated_open_tables, (uchar*) share);
+    my_hash_delete(&federated_open_tables, (uchar*) share);
     thr_lock_delete(&share->lock);
     pthread_mutex_destroy(&share->mutex);
     free_root(&mem_root, MYF(0));

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2009-02-02 15:58:48 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2009-02-09 13:36:40 +0000
@@ -1790,8 +1790,8 @@ innobase_init(
 		goto error;
 	}
 
-	(void) hash_init(&innobase_open_tables,system_charset_info, 32, 0, 0,
-					(hash_get_key) innobase_get_key, 0, 0);
+        (void) my_hash_init(&innobase_open_tables,system_charset_info, 32, 0, 0,
+                            (my_hash_get_key) innobase_get_key, 0, 0);
 	pthread_mutex_init(&innobase_share_mutex, MY_MUTEX_INIT_FAST);
 	pthread_mutex_init(&prepare_commit_mutex, MY_MUTEX_INIT_FAST);
 	pthread_mutex_init(&commit_threads_m, MY_MUTEX_INIT_FAST);
@@ -1828,7 +1828,7 @@ innobase_end(handlerton *hton, ha_panic_
 		if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
 			err = 1;
 		}
-		hash_free(&innobase_open_tables);
+		my_hash_free(&innobase_open_tables);
 		my_free(internal_innobase_data_file_path,
 						MYF(MY_ALLOW_ZERO_PTR));
 		pthread_mutex_destroy(&innobase_share_mutex);
@@ -3468,7 +3468,6 @@ skip_field:
           prebuilt->idx_cond_func= NULL;
           prebuilt->n_index_fields= n_requested_fields;
         }
-       // file->in_range_read= FALSE;
 
 	if (index != clust_index && prebuilt->need_to_access_clustered) {
 		/* Change rec_field_no's to correspond to the clustered index
@@ -6675,7 +6674,6 @@ ha_innobase::extra(
                         /* Reset index condition pushdown state */
                         pushed_idx_cond= FALSE;
                         pushed_idx_cond_keyno= MAX_KEY;
-                        //in_range_read= FALSE;
                         prebuilt->idx_cond_func= NULL;
 			break;
 		case HA_EXTRA_NO_KEYREAD:
@@ -7342,7 +7340,7 @@ static INNOBASE_SHARE* get_share(const c
 	pthread_mutex_lock(&innobase_share_mutex);
 	uint length=(uint) strlen(table_name);
 
-	if (!(share=(INNOBASE_SHARE*) hash_search(&innobase_open_tables,
+	if (!(share=(INNOBASE_SHARE*) my_hash_search(&innobase_open_tables,
 				(uchar*) table_name,
 				length))) {
 
@@ -7376,7 +7374,7 @@ static void free_share(INNOBASE_SHARE* s
 	pthread_mutex_lock(&innobase_share_mutex);
 
 	if (!--share->use_count) {
-		hash_delete(&innobase_open_tables, (uchar*) share);
+		my_hash_delete(&innobase_open_tables, (uchar*) share);
 		thr_lock_delete(&share->lock);
 		pthread_mutex_destroy(&share->mutex);
 		my_free(share, MYF(0));
@@ -8497,13 +8495,12 @@ mysql_declare_plugin_end;
 int ha_innobase::multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
                           uint n_ranges, uint mode, HANDLER_BUFFER *buf)
 {
-  return ds_mrr.dsmrr_init(this, &table->key_info[active_index], 
-                           seq, seq_init_param, n_ranges, mode, buf);
+  return ds_mrr.dsmrr_init(this, seq, seq_init_param, n_ranges, mode, buf);
 }
 
 int ha_innobase::multi_range_read_next(char **range_info)
 {
-  return ds_mrr.dsmrr_next(this, range_info);
+  return ds_mrr.dsmrr_next(range_info);
 }
 
 ha_rows ha_innobase::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
@@ -8539,7 +8536,7 @@ C_MODE_START
 static my_bool index_cond_func_innodb(void *arg)
 {
   ha_innobase *h= (ha_innobase*)arg;
-  if (h->end_range) //was: h->in_range_read
+  if (h->end_range)
   {
     if (h->compare_key2(h->end_range) > 0)
       return 2; /* caller should return HA_ERR_END_OF_FILE already */
@@ -8569,11 +8566,7 @@ int ha_innobase::read_range_first(const 
                                 bool sorted /* ignored */)
 {
   int res;
-  //if (!eq_range_arg)
-    //in_range_read= TRUE;
   res= handler::read_range_first(start_key, end_key, eq_range_arg, sorted);
-  //if (res)
-  //  in_range_read= FALSE;
   return res;
 }
 
@@ -8581,8 +8574,6 @@ int ha_innobase::read_range_first(const 
 int ha_innobase::read_range_next()
 {
   int res= handler::read_range_next();
-  //if (res)
-  //  in_range_read= FALSE;
   return res;
 }
 

=== modified file 'storage/maria/ha_maria.cc'
--- a/storage/maria/ha_maria.cc	2009-01-13 15:26:20 +0000
+++ b/storage/maria/ha_maria.cc	2009-02-05 08:22:22 +0000
@@ -1457,7 +1457,7 @@ int ha_maria::preload_keys(THD * thd, HA
 
   if ((error= maria_preload(file, map, table_list->ignore_leaves)))
   {
-    char buf[ERRMSGSIZE+20];
+    char buf[MYSYS_ERRMSG_SIZE];
     const char *errmsg;
 
     switch (error) {
@@ -1468,7 +1468,7 @@ int ha_maria::preload_keys(THD * thd, HA
       errmsg= "Failed to allocate buffer";
       break;
     default:
-      my_snprintf(buf, ERRMSGSIZE,
+      my_snprintf(buf, sizeof(buf),
                   "Failed to read from index file (errno: %d)", my_errno);
       errmsg= buf;
     }
@@ -3198,13 +3198,12 @@ int ha_maria::multi_range_read_init(RANG
                                      uint n_ranges, uint mode, 
                                      HANDLER_BUFFER *buf)
 {
-  return ds_mrr.dsmrr_init(this, &table->key_info[active_index], 
-                           seq, seq_init_param, n_ranges, mode, buf);
+  return ds_mrr.dsmrr_init(this, seq, seq_init_param, n_ranges, mode, buf);
 }
 
 int ha_maria::multi_range_read_next(char **range_info)
 {
-  return ds_mrr.dsmrr_next(this, range_info);
+  return ds_mrr.dsmrr_next(range_info);
 }
 
 ha_rows ha_maria::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,

=== modified file 'storage/maria/ma_init.c'
--- a/storage/maria/ma_init.c	2008-10-09 20:03:54 +0000
+++ b/storage/maria/ma_init.c	2009-01-27 02:08:48 +0000
@@ -66,8 +66,8 @@ int maria_init(void)
     trnman_end_trans_hook= _ma_trnman_end_trans_hook;
     my_handler_error_register();
   }
-  hash_init(&maria_stored_state, &my_charset_bin, 32,
-            0, sizeof(LSN), 0, (hash_free_key) history_state_free, 0);
+  my_hash_init(&maria_stored_state, &my_charset_bin, 32,
+            0, sizeof(LSN), 0, (my_hash_free_key) history_state_free, 0);
   DBUG_PRINT("info",("dummy_transaction_object: %p",
                      &dummy_transaction_object));
   return 0;
@@ -99,6 +99,6 @@ void maria_end(void)
     end_pagecache(maria_pagecache, TRUE);
     ma_control_file_end();
     pthread_mutex_destroy(&THR_LOCK_maria);
-    hash_free(&maria_stored_state);
+    my_hash_free(&maria_stored_state);
   }
 }

=== modified file 'storage/maria/ma_open.c'
--- a/storage/maria/ma_open.c	2008-12-09 13:11:48 +0000
+++ b/storage/maria/ma_open.c	2009-01-27 02:08:48 +0000
@@ -791,8 +791,8 @@ MARIA_HA *maria_open(const char *name, i
       /* Setup initial state that is visible for all */
       MARIA_STATE_HISTORY_CLOSED *history;
       if ((history= (MARIA_STATE_HISTORY_CLOSED *)
-           hash_search(&maria_stored_state,
-                       (uchar*) &share->state.create_rename_lsn, 0)))
+           my_hash_search(&maria_stored_state,
+                          (uchar*) &share->state.create_rename_lsn, 0)))
       {
         /*
           Move history from hash to share. This is safe to do as we
@@ -801,7 +801,7 @@ MARIA_HA *maria_open(const char *name, i
         share->state_history=
           _ma_remove_not_visible_states(history->state_history, 0, 0);
         history->state_history= 0;
-        (void) hash_delete(&maria_stored_state, (uchar*) history);
+        (void) my_hash_delete(&maria_stored_state, (uchar*) history);
       }
       else
       {

=== modified file 'storage/maria/ma_pagecache.c'
--- a/storage/maria/ma_pagecache.c	2008-11-24 18:40:52 +0000
+++ b/storage/maria/ma_pagecache.c	2009-01-27 02:08:48 +0000
@@ -729,10 +729,10 @@ ulong init_pagecache(PAGECACHE *pagecach
   if (! pagecache->inited)
   {
     if (pthread_mutex_init(&pagecache->cache_lock, MY_MUTEX_INIT_FAST) ||
-        hash_init(&pagecache->files_in_flush, &my_charset_bin, 32,
-                  offsetof(struct st_file_in_flush, file),
-                  sizeof(((struct st_file_in_flush *)NULL)->file),
-                  NULL, NULL, 0))
+        my_hash_init(&pagecache->files_in_flush, &my_charset_bin, 32,
+                     offsetof(struct st_file_in_flush, file),
+                     sizeof(((struct st_file_in_flush *)NULL)->file),
+                     NULL, NULL, 0))
       goto err;
     pagecache->inited= 1;
     pagecache->in_init= 0;
@@ -1129,7 +1129,7 @@ void end_pagecache(PAGECACHE *pagecache,
 
   if (cleanup)
   {
-    hash_free(&pagecache->files_in_flush);
+    my_hash_free(&pagecache->files_in_flush);
     pthread_mutex_destroy(&pagecache->cache_lock);
     pagecache->inited= pagecache->can_be_used= 0;
     PAGECACHE_DEBUG_CLOSE;
@@ -4359,8 +4359,8 @@ static int flush_pagecache_blocks_int(PA
     us_flusher.flush_queue.last_thread= NULL;
     us_flusher.first_in_switch= FALSE;
     while ((other_flusher= (struct st_file_in_flush *)
-            hash_search(&pagecache->files_in_flush, (uchar *)&file->file,
-                        sizeof(file->file))))
+            my_hash_search(&pagecache->files_in_flush, (uchar *)&file->file,
+                           sizeof(file->file))))
     {
       /*
         File is in flush already: wait, unless FLUSH_KEEP_LAZY. "Flusher"
@@ -4586,7 +4586,7 @@ restart:
     }
 #ifdef THREAD
     /* wake up others waiting to flush this file */
-    hash_delete(&pagecache->files_in_flush, (uchar *)&us_flusher);
+    my_hash_delete(&pagecache->files_in_flush, (uchar *)&us_flusher);
     if (us_flusher.flush_queue.last_thread)
       wqueue_release_queue(&us_flusher.flush_queue);
 #endif
@@ -4727,7 +4727,7 @@ my_bool pagecache_collect_changed_blocks
     struct st_file_in_flush *other_flusher;
     for (file_hash= 0;
          (other_flusher= (struct st_file_in_flush *)
-          hash_element(&pagecache->files_in_flush, file_hash)) != NULL &&
+          my_hash_element(&pagecache->files_in_flush, file_hash)) != NULL &&
            !other_flusher->first_in_switch;
          file_hash++)
     {}

=== modified file 'storage/maria/ma_recovery.c'
--- a/storage/maria/ma_recovery.c	2008-12-09 13:11:48 +0000
+++ b/storage/maria/ma_recovery.c	2009-01-27 02:08:48 +0000
@@ -435,7 +435,7 @@ err:
     delete_all_transactions();
 end:
   error_handler_hook= save_error_handler_hook;
-  hash_free(&all_dirty_pages);
+  my_hash_free(&all_dirty_pages);
   bzero(&all_dirty_pages, sizeof(all_dirty_pages));
   my_free(dirty_pages_pool, MYF(MY_ALLOW_ZERO_PTR));
   dirty_pages_pool= NULL;
@@ -2534,7 +2534,7 @@ static uint end_of_redo_phase(my_bool pr
   char llbuf[22];
   LSN addr;
 
-  hash_free(&all_dirty_pages);
+  my_hash_free(&all_dirty_pages);
   /*
     hash_free() can be called multiple times probably, but be safe if that
     changes
@@ -3043,10 +3043,10 @@ static LSN parse_checkpoint_record(LSN l
 
   ptr+= 8;
   tprint(tracef, "%lu dirty pages\n", (ulong) nb_dirty_pages);
-  if (hash_init(&all_dirty_pages, &my_charset_bin, (ulong)nb_dirty_pages,
-                offsetof(struct st_dirty_page, file_and_page_id),
-                sizeof(((struct st_dirty_page *)NULL)->file_and_page_id),
-                NULL, NULL, 0))
+  if (my_hash_init(&all_dirty_pages, &my_charset_bin, (ulong)nb_dirty_pages,
+                   offsetof(struct st_dirty_page, file_and_page_id),
+                   sizeof(((struct st_dirty_page *)NULL)->file_and_page_id),
+                   NULL, NULL, 0))
     return LSN_ERROR;
   dirty_pages_pool=
     (struct st_dirty_page *)my_malloc((size_t)nb_dirty_pages *

=== modified file 'storage/maria/ma_recovery_util.c'
--- a/storage/maria/ma_recovery_util.c	2008-01-29 21:20:59 +0000
+++ b/storage/maria/ma_recovery_util.c	2009-01-27 02:08:48 +0000
@@ -124,8 +124,8 @@ my_bool _ma_redo_not_needed_for_page(uin
     uint64 file_and_page_id=
       (((uint64)((index << 16) | shortid)) << 40) | page;
     struct st_dirty_page *dirty_page= (struct st_dirty_page *)
-      hash_search(&all_dirty_pages,
-                  (uchar *)&file_and_page_id, sizeof(file_and_page_id));
+      my_hash_search(&all_dirty_pages,
+                     (uchar *)&file_and_page_id, sizeof(file_and_page_id));
     DBUG_PRINT("info", ("in dirty pages list: %d", dirty_page != NULL));
     if ((dirty_page == NULL) ||
         cmp_translog_addr(lsn, dirty_page->rec_lsn) < 0)

=== modified file 'storage/maria/tablockman.c'
--- a/storage/maria/tablockman.c	2008-01-10 12:21:53 +0000
+++ b/storage/maria/tablockman.c	2009-01-27 13:04:31 +0000
@@ -225,13 +225,12 @@ struct st_table_lock {
   uchar  lock_type;
 };
 
-#define hash_insert my_hash_insert /* for consistency :) */
 
 static inline
 TABLE_LOCK *find_by_loid(LOCKED_TABLE *table, uint16 loid)
 {
-  return (TABLE_LOCK *)hash_search(& table->latest_locks,
-                                   (uchar *)& loid, sizeof(loid));
+  return (TABLE_LOCK *)my_hash_search(& table->latest_locks,
+                                      (uchar *)& loid, sizeof(loid));
 }
 
 static inline
@@ -485,8 +484,8 @@ tablockman_getlock(TABLOCKMAN *lm, TABLE
 
   /* update the latest_locks hash */
   if (old)
-    hash_delete(& table->latest_locks, (uchar *)old);
-  hash_insert(& table->latest_locks, (uchar *)new);
+    my_hash_delete(& table->latest_locks, (uchar *)old);
+  my_hash_insert(& table->latest_locks, (uchar *)new);
 
   new->upgraded_from= old;
 
@@ -569,7 +568,7 @@ void tablockman_release_locks(TABLOCKMAN
 
     /* TODO ? group locks by table to reduce the number of mutex locks */
     pthread_mutex_lock(mutex);
-    hash_delete(& cur->table->latest_locks, (uchar *)cur);
+    my_hash_delete(& cur->table->latest_locks, (uchar *)cur);
 
     if (cur->prev)
       cur->prev->next= cur->next;
@@ -632,9 +631,9 @@ void tablockman_init_locked_table(LOCKED
 {
   bzero(lt, sizeof(*lt));
   pthread_mutex_init(& lt->mutex, MY_MUTEX_INIT_FAST);
-  hash_init(& lt->latest_locks, & my_charset_bin, initial_hash_size,
-            offsetof(TABLE_LOCK, loid),
-            sizeof(((TABLE_LOCK*)0)->loid), 0, 0, 0);
+  my_hash_init(& lt->latest_locks, & my_charset_bin, initial_hash_size,
+               offsetof(TABLE_LOCK, loid),
+               sizeof(((TABLE_LOCK*)0)->loid), 0, 0, 0);
 }
 
 void tablockman_destroy_locked_table(LOCKED_TABLE *lt)
@@ -647,7 +646,7 @@ void tablockman_destroy_locked_table(LOC
   for (i= 0; i<LOCK_TYPES; i++)
      DBUG_ASSERT(lt->active_locks[i] == 0);
 
-  hash_free(& lt->latest_locks);
+  my_hash_free(& lt->latest_locks);
   pthread_mutex_destroy(& lt->mutex);
 }
 

=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc	2009-01-29 21:17:59 +0000
+++ b/storage/myisam/ha_myisam.cc	2009-02-05 08:22:22 +0000
@@ -1121,7 +1121,7 @@ int ha_myisam::preload_keys(THD* thd, HA
   ulonglong map;
   TABLE_LIST *table_list= table->pos_in_table_list;
   my_bool ignore_leaves= table_list->ignore_leaves;
-  char buf[ERRMSGSIZE+20];
+  char buf[MYSQL_ERRMSG_SIZE];
 
   DBUG_ENTER("ha_myisam::preload_keys");
 
@@ -1149,7 +1149,7 @@ int ha_myisam::preload_keys(THD* thd, HA
       errmsg= "Failed to allocate buffer";
       break;
     default:
-      my_snprintf(buf, ERRMSGSIZE,
+      my_snprintf(buf, sizeof(buf),
                   "Failed to read from index file (errno: %d)", my_errno);
       errmsg= buf;
     }
@@ -2013,13 +2013,12 @@ int ha_myisam::multi_range_read_init(RAN
                                      uint n_ranges, uint mode, 
                                      HANDLER_BUFFER *buf)
 {
-  return ds_mrr.dsmrr_init(this, &table->key_info[active_index], 
-                           seq, seq_init_param, n_ranges, mode, buf);
+  return ds_mrr.dsmrr_init(this, seq, seq_init_param, n_ranges, mode, buf);
 }
 
 int ha_myisam::multi_range_read_next(char **range_info)
 {
-  return ds_mrr.dsmrr_next(this, range_info);
+  return ds_mrr.dsmrr_next(range_info);
 }
 
 ha_rows ha_myisam::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,

=== modified file 'storage/myisam/mi_create.c'
--- a/storage/myisam/mi_create.c	2008-11-12 15:23:22 +0000
+++ b/storage/myisam/mi_create.c	2009-01-31 16:21:19 +0000
@@ -651,8 +651,8 @@ int mi_create(const char *name,uint keys
     this would solve the problem.
  */
   DBUG_ASSERT((options & HA_OPTION_TMP_TABLE) || !mi_log_tables_physical ||
-              !hash_search(mi_log_tables_physical, filename,
-                           strlen(filename)));
+              !my_hash_search(mi_log_tables_physical, filename,
+                              strlen(filename)));
 
   if ((file= my_create_with_symlink(linkname_ptr, filename, 0, create_mode,
 				    MYF(MY_WME | create_flag))) < 0)

=== modified file 'storage/myisam/mi_log.c'
--- a/storage/myisam/mi_log.c	2008-07-09 07:12:43 +0000
+++ b/storage/myisam/mi_log.c	2009-01-27 02:08:48 +0000
@@ -667,7 +667,7 @@ static int mi_log_start_physical(const c
   int error;
   DBUG_ENTER("mi_log_start_physical");
   DBUG_ASSERT(log_filename != NULL);
-  DBUG_ASSERT(hash_inited(tables));
+  DBUG_ASSERT(my_hash_inited(tables));
 
   pthread_mutex_lock(&THR_LOCK_myisam);
   if (mi_log_tables_physical) /* physical logging already running */
@@ -690,8 +690,9 @@ static int mi_log_start_physical(const c
     MYISAM_SHARE *share= info->s;
     DBUG_PRINT("info",("table '%s' 0x%lx tested against hash",
                        share->unique_file_name, (ulong)info));
-    if (!hash_search(mi_log_tables_physical, (uchar *)share->unique_file_name,
-                     share->unique_name_length))
+    if (!my_hash_search(mi_log_tables_physical,
+                        (uchar *)share->unique_file_name,
+                        share->unique_name_length))
       continue;
     /* Backup kernel shouldn't ask for temporary table's backup */
     DBUG_ASSERT(!share->temporary);

=== modified file 'storage/myisam/mi_open.c'
--- a/storage/myisam/mi_open.c	2009-02-03 09:16:53 +0000
+++ b/storage/myisam/mi_open.c	2009-02-04 10:49:16 +0000
@@ -701,8 +701,8 @@ MI_INFO *mi_open(const char *name, int m
   thr_lock_data_init(&share->lock,&m_info->lock,(void*) m_info);
 #endif
   if (mi_log_tables_physical &&
-      hash_search(mi_log_tables_physical, (uchar *)share->unique_file_name,
-                  share->unique_name_length))
+      my_hash_search(mi_log_tables_physical, (uchar *)share->unique_file_name,
+                     share->unique_name_length))
     m_info->s->physical_logging= TRUE; /* set before publishing table */
   m_info->open_list.data=(void*) m_info;
   myisam_open_list=list_add(myisam_open_list,&m_info->open_list);

=== modified file 'storage/myisam/myisam_backup_engine.cc'
--- a/storage/myisam/myisam_backup_engine.cc	2009-01-21 15:00:23 +0000
+++ b/storage/myisam/myisam_backup_engine.cc	2009-02-04 10:49:16 +0000
@@ -466,7 +466,7 @@ Backup::~Backup()
   delete image;
   if (hash_of_tables)
   {
-    hash_free(hash_of_tables);
+    my_hash_free(hash_of_tables);
     delete hash_of_tables;
     hash_of_tables= NULL;
   }
@@ -542,9 +542,9 @@ result_t Backup::begin(const size_t)
   }
   hash_of_tables= new HASH;
   if (!hash_of_tables ||
-      hash_init(hash_of_tables, &my_charset_bin, m_tables.count(), 0, 0,
-                (hash_get_key)backup_get_table_from_hash_key,
-                (hash_free_key)backup_free_hash_key, 0))
+      my_hash_init(hash_of_tables, &my_charset_bin, m_tables.count(), 0, 0,
+                  (my_hash_get_key)backup_get_table_from_hash_key,
+                  (my_hash_free_key)backup_free_hash_key, 0))
     SET_STATE_TO_ERROR_AND_DBUG_RETURN;
   /* Build the hash of tables for the MyISAM layer (mi_backup_log.c etc) */
   for (uint n=0 ; n < m_tables.count() ; n++ )

=== modified file 'storage/ndb/include/ndbapi/NdbScanOperation.hpp'
--- a/storage/ndb/include/ndbapi/NdbScanOperation.hpp	2008-11-08 21:22:57 +0000
+++ b/storage/ndb/include/ndbapi/NdbScanOperation.hpp	2009-02-09 16:27:41 +0000
@@ -54,6 +54,12 @@ public:
       each fragment, to get a single sorted result set.
     */
     SF_OrderBy = (1 << 24),
+    /**
+     * Same as order by, except that it will automatically 
+     *   add all key columns into the read-mask
+     */
+    SF_OrderByFull = (16 << 24),
+
     /* Index scan in descending order, instead of default ascending. */
     SF_Descending = (2 << 24),
     /*

=== modified file 'storage/ndb/src/ndbapi/NdbScanOperation.cpp'
--- a/storage/ndb/src/ndbapi/NdbScanOperation.cpp	2009-02-05 11:03:46 +0000
+++ b/storage/ndb/src/ndbapi/NdbScanOperation.cpp	2009-02-09 16:27:41 +0000
@@ -867,7 +867,10 @@ NdbIndexScanOperation::scanIndexImpl(con
     return -1;
   }
 
-  if (scan_flags & NdbScanOperation::SF_OrderBy)
+  result_record->copyMask(m_read_mask, result_mask);
+
+  if (scan_flags & (NdbScanOperation::SF_OrderBy | 
+                    NdbScanOperation::SF_OrderByFull))
   {
     /**
      * For ordering, we need all keys in the result row.
@@ -875,19 +878,34 @@ NdbIndexScanOperation::scanIndexImpl(con
      * So for each key column, check that it is included in the result
      * NdbRecord.
      */
+#define MASKSZ ((NDB_MAX_ATTRIBUTES_IN_TABLE+31)>>5)
+    Uint32 keymask[MASKSZ];
+    BitmaskImpl::clear(MASKSZ, keymask);
+
     for (i = 0; i < key_record->key_index_length; i++)
     {
-      const NdbRecord::Attr *key_col =
-        &key_record->columns[key_record->key_indexes[i]];
-      if (key_col->attrId >= result_record->m_attrId_indexes_length ||
-          result_record->m_attrId_indexes[key_col->attrId] < 0)
+      Uint32 attrId = key_record->columns[key_record->key_indexes[i]].attrId;
+      if (attrId >= result_record->m_attrId_indexes_length ||
+          result_record->m_attrId_indexes[attrId] < 0)
       {
         setErrorCodeAbort(4292);
         return -1;
       }
+
+      BitmaskImpl::set(MASKSZ, keymask);
     }
-  }
 
+    if (scan_flags & NdbScanOperation::SF_OrderByFull)
+    {
+      BitmaskImpl::bitOR(MASKSZ, m_read_mask, keymask);
+    }
+    else if (!BitmaskImpl::contains(MASKSZ, m_read_mask, keymask))
+    {
+      setErrorCodeAbort(4341);
+      return -1;
+    }
+  }
+  
   if (!(key_record->flags & NdbRecord::RecIsIndex))
   {
     setErrorCodeAbort(4283);

=== modified file 'storage/ndb/src/ndbapi/ndberror.c'
--- a/storage/ndb/src/ndbapi/ndberror.c	2009-01-27 13:03:36 +0000
+++ b/storage/ndb/src/ndbapi/ndberror.c	2009-02-09 16:27:41 +0000
@@ -365,7 +365,7 @@ ErrorBundle ErrorCodes[] = {
   { 708,  DMEC, SE, "No more attribute metadata records (increase MaxNoOfAttributes)" },
   { 709,  HA_ERR_NO_SUCH_TABLE, SE, "No such table existed" },
   { 710,  DMEC, SE, "Internal: Get by table name not supported, use table id." },
-  { 721,  HA_ERR_TABLE_EXIST,   OE, "Table or index with given name already exists" },
+  { 721,  HA_ERR_TABLE_EXIST,   OE, "Schema object with given name already exists" },
   { 723,  HA_ERR_NO_SUCH_TABLE, SE, "No such table existed" },
   { 736,  DMEC, SE, "Unsupported array size" },
   { 737,  HA_WRONG_CREATE_OPTION, SE, "Attribute array size too big" },
@@ -679,6 +679,7 @@ ErrorBundle ErrorCodes[] = {
   { 4290, DMEC, AE, "Missing column specification in NdbDictionary::RecordSpecification" },
   { 4291, DMEC, AE, "Duplicate column specification in NdbDictionary::RecordSpecification" },
   { 4292, DMEC, AE, "NdbRecord for tuple access is not an index key NdbRecord" },
+  { 4341, DMEC, AE, "Not all keys read when using option SF_OrderBy" },
   { 4293, DMEC, AE, "Error returned from application scanIndex() callback" },
   { 4294, DMEC, AE, "Scan filter is too large, discarded" },
   { 4295, DMEC, AE, "Column is NULL in Get/SetValueSpec structure" },

Thread
bzr commit into mysql-6.0-telco-6.3 branch (tomas.ulin:2841) Tomas Ulin9 Feb