summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorDavi Arnaut <Davi.Arnaut@Sun.COM>2010-07-15 10:47:50 -0300
committerDavi Arnaut <Davi.Arnaut@Sun.COM>2010-07-15 10:47:50 -0300
commit711c318c072f6d5fd5c2877ccc736c7673d1711d (patch)
treeac8b15ac65b08a492c256369b73e372f6568c7a4 /sql
parent00538253b592522babe3609af29cb3eb87218b64 (diff)
parentfd64a0db45705ca5eb2ad34ffc2ed1d9ef961017 (diff)
downloadmariadb-git-711c318c072f6d5fd5c2877ccc736c7673d1711d.tar.gz
Merge of mysql-trunk-bugfixing into mysql-trunk-merge.
Diffstat (limited to 'sql')
-rw-r--r--sql/CMakeLists.txt5
-rw-r--r--sql/Makefile.am3
-rw-r--r--sql/debug_sync.cc4
-rw-r--r--sql/derror.cc5
-rw-r--r--sql/event_data_objects.cc6
-rw-r--r--sql/event_scheduler.cc2
-rw-r--r--sql/examples/CMakeLists.txt4
-rw-r--r--sql/filesort.cc47
-rw-r--r--sql/gstream.h2
-rw-r--r--sql/ha_ndbcluster.cc44
-rw-r--r--sql/ha_ndbcluster_binlog.cc18
-rw-r--r--sql/ha_partition.cc10
-rw-r--r--sql/handler.cc12
-rw-r--r--sql/handler.h4
-rw-r--r--sql/item.h1
-rw-r--r--sql/item_func.cc13
-rw-r--r--sql/item_strfunc.cc17
-rw-r--r--sql/item_strfunc.h13
-rw-r--r--sql/keycaches.cc6
-rw-r--r--sql/lock.cc12
-rw-r--r--sql/log.cc95
-rw-r--r--sql/log.h1
-rw-r--r--sql/log_event.cc44
-rw-r--r--sql/log_event.h12
-rw-r--r--sql/log_event_old.cc10
-rw-r--r--sql/mdl.cc4
-rw-r--r--sql/my_lock.c78
-rw-r--r--sql/mysqld.cc410
-rw-r--r--sql/net_serv.cc7
-rw-r--r--sql/opt_range.cc129
-rw-r--r--sql/opt_range.h12
-rw-r--r--sql/records.cc61
-rw-r--r--sql/records.h2
-rw-r--r--sql/repl_failsafe.cc4
-rw-r--r--sql/rpl_filter.cc4
-rw-r--r--sql/rpl_handler.cc4
-rw-r--r--sql/rpl_injector.cc2
-rw-r--r--sql/rpl_mi.cc24
-rw-r--r--sql/rpl_rli.cc2
-rw-r--r--sql/rpl_utility.cc2
-rw-r--r--sql/slave.cc8
-rw-r--r--sql/sp_pcontext.cc4
-rw-r--r--sql/sp_rcontext.cc4
-rw-r--r--sql/sql_base.cc27
-rw-r--r--sql/sql_binlog.cc2
-rw-r--r--sql/sql_bitmap.h9
-rw-r--r--sql/sql_cache.cc2
-rw-r--r--sql/sql_class.cc326
-rw-r--r--sql/sql_class.h135
-rw-r--r--sql/sql_connect.cc11
-rw-r--r--sql/sql_db.cc19
-rw-r--r--sql/sql_delete.cc29
-rw-r--r--sql/sql_handler.cc4
-rw-r--r--sql/sql_insert.cc12
-rw-r--r--sql/sql_lex.cc4
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_list.h2
-rw-r--r--sql/sql_load.cc6
-rw-r--r--sql/sql_locale.cc2
-rw-r--r--sql/sql_manager.cc2
-rw-r--r--sql/sql_map.cc2
-rw-r--r--sql/sql_parse.cc22
-rw-r--r--sql/sql_partition.cc2
-rw-r--r--sql/sql_plugin.cc30
-rw-r--r--sql/sql_plugin.h14
-rw-r--r--sql/sql_profile.cc6
-rw-r--r--sql/sql_profile.h4
-rw-r--r--sql/sql_select.cc685
-rw-r--r--sql/sql_select.h8
-rw-r--r--sql/sql_show.cc12
-rw-r--r--sql/sql_string.h2
-rw-r--r--sql/sql_table.cc22
-rw-r--r--sql/sql_test.cc5
-rw-r--r--sql/sql_truncate.cc2
-rw-r--r--sql/sql_update.cc41
-rw-r--r--sql/sys_vars.cc6
-rw-r--r--sql/sys_vars.h4
-rw-r--r--sql/table.cc96
-rw-r--r--sql/table.h4
-rw-r--r--sql/transaction.cc8
-rw-r--r--sql/tztime.cc5
-rw-r--r--sql/uniques.cc4
-rw-r--r--sql/unireg.cc22
83 files changed, 1415 insertions, 1336 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index ca5738f116e..7107a68ee84 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -156,7 +156,10 @@ IF(WITH_MYSQLD_LDFLAGS)
SET_TARGET_PROPERTIES(mysqld PROPERTIES LINK_FLAGS
"${MYSQLD_LINK_FLAGS} ${WITH_MYSQLD_LDFLAGS}")
ENDIF()
-INSTALL_DEBUG_TARGET(mysqld DESTINATION ${INSTALL_SBINDIR} RENAME mysqld-debug)
+INSTALL_DEBUG_TARGET(mysqld
+ DESTINATION ${INSTALL_SBINDIR}
+ PDB_DESTINATION ${INSTALL_SBINDIR}/debug
+ RENAME mysqld-debug)
# Handle out-of-source build from source package with possibly broken
# bison. Copy bison output to from source to build directory, if not already
diff --git a/sql/Makefile.am b/sql/Makefile.am
index 0616893a014..4b1ecbbc8da 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -135,8 +135,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
item_row.cc item_geofunc.cc item_xmlfunc.cc \
field.cc strfunc.cc key.cc sql_class.cc sql_list.cc \
net_serv.cc protocol.cc sql_state.c \
- lock.cc my_lock.c \
- sql_string.cc sql_manager.cc sql_map.cc \
+ lock.cc sql_string.cc sql_manager.cc sql_map.cc \
main.cc mysqld.cc password.c hash_filo.cc hostname.cc \
sql_connect.cc scheduler.cc sql_parse.cc \
keycaches.cc set_var.cc sql_yacc.yy sys_vars.cc \
diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc
index dde6267331f..74e5b2c70f3 100644
--- a/sql/debug_sync.cc
+++ b/sql/debug_sync.cc
@@ -626,7 +626,7 @@ void debug_sync_end_thread(THD *thd)
action->wait_for.free();
action->sync_point.free();
}
- my_free(ds_control->ds_action, MYF(0));
+ my_free(ds_control->ds_action);
}
/* Statistics. */
@@ -637,7 +637,7 @@ void debug_sync_end_thread(THD *thd)
debug_sync_global.dsp_max_active= ds_control->dsp_max_active;
mysql_mutex_unlock(&debug_sync_global.ds_mutex);
- my_free(ds_control, MYF(0));
+ my_free(ds_control);
thd->debug_sync_control= NULL;
}
diff --git a/sql/derror.cc b/sql/derror.cc
index 7f1435e89c1..bf8c589a65f 100644
--- a/sql/derror.cc
+++ b/sql/derror.cc
@@ -79,7 +79,7 @@ bool init_errmessage(void)
/* Register messages for use with my_error(). */
if (my_error_register(get_server_errmsgs, ER_ERROR_FIRST, ER_ERROR_LAST))
{
- x_free((uchar*) errmsgs);
+ my_free(errmsgs);
DBUG_RETURN(TRUE);
}
@@ -155,7 +155,8 @@ Check that the above file is the right version for this program!",
DBUG_RETURN(1);
}
- x_free((uchar*) *point); /* Free old language */
+ /* Free old language */
+ my_free(*point);
if (!(*point= (const char**)
my_malloc((size_t) (length+count*sizeof(char*)),MYF(0))))
{
diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc
index c778d72a016..dd1845b29bc 100644
--- a/sql/event_data_objects.cc
+++ b/sql/event_data_objects.cc
@@ -176,7 +176,7 @@ Event_queue_element_for_exec::init(LEX_STRING db, LEX_STRING n)
return TRUE;
if (!(name.str= my_strndup(n.str, name.length= n.length, MYF(MY_WME))))
{
- my_free((uchar*) dbname.str, MYF(0));
+ my_free(dbname.str);
return TRUE;
}
return FALSE;
@@ -192,8 +192,8 @@ Event_queue_element_for_exec::init(LEX_STRING db, LEX_STRING n)
Event_queue_element_for_exec::~Event_queue_element_for_exec()
{
- my_free((uchar*) dbname.str, MYF(0));
- my_free((uchar*) name.str, MYF(0));
+ my_free(dbname.str);
+ my_free(name.str);
}
diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc
index c646642dbba..aa4d376d86e 100644
--- a/sql/event_scheduler.cc
+++ b/sql/event_scheduler.cc
@@ -238,7 +238,7 @@ event_scheduler_thread(void *arg)
res= post_init_event_thread(thd);
DBUG_ENTER("event_scheduler_thread");
- my_free((char*)arg, MYF(0));
+ my_free(arg);
if (!res)
scheduler->run(thd);
diff --git a/sql/examples/CMakeLists.txt b/sql/examples/CMakeLists.txt
index 1a22e9a3efd..3c5cc23ec3b 100644
--- a/sql/examples/CMakeLists.txt
+++ b/sql/examples/CMakeLists.txt
@@ -13,8 +13,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
-SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
+SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFE_MUTEX")
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFE_MUTEX")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/sql
${CMAKE_SOURCE_DIR}/extra/yassl/include
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 3f3dc4e1e3e..2398785a038 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -264,7 +264,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
{
if (table_sort.buffpek && table_sort.buffpek_len < maxbuffer)
{
- x_free(table_sort.buffpek);
+ my_free(table_sort.buffpek);
table_sort.buffpek= 0;
}
if (!(table_sort.buffpek=
@@ -304,13 +304,12 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
error =0;
err:
- if (param.tmp_buffer)
- x_free(param.tmp_buffer);
+ my_free(param.tmp_buffer);
if (!subselect || !subselect->is_uncacheable())
{
- x_free((uchar*) sort_keys);
+ my_free(sort_keys);
table_sort.sort_keys= 0;
- x_free((uchar*) buffpek);
+ my_free(buffpek);
table_sort.buffpek= 0;
table_sort.buffpek_len= 0;
}
@@ -347,32 +346,22 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
void filesort_free_buffers(TABLE *table, bool full)
{
- if (table->sort.record_pointers)
- {
- my_free((uchar*) table->sort.record_pointers,MYF(0));
- table->sort.record_pointers=0;
- }
+ my_free(table->sort.record_pointers);
+ table->sort.record_pointers= NULL;
+
if (full)
{
- if (table->sort.sort_keys )
- {
- x_free((uchar*) table->sort.sort_keys);
- table->sort.sort_keys= 0;
- }
- if (table->sort.buffpek)
- {
- x_free((uchar*) table->sort.buffpek);
- table->sort.buffpek= 0;
- table->sort.buffpek_len= 0;
- }
- }
- if (table->sort.addon_buf)
- {
- my_free((char *) table->sort.addon_buf, MYF(0));
- my_free((char *) table->sort.addon_field, MYF(MY_ALLOW_ZERO_PTR));
- table->sort.addon_buf=0;
- table->sort.addon_field=0;
+ my_free(table->sort.sort_keys);
+ table->sort.sort_keys= NULL;
+ my_free(table->sort.buffpek);
+ table->sort.buffpek= NULL;
+ table->sort.buffpek_len= 0;
}
+
+ my_free(table->sort.addon_buf);
+ my_free(table->sort.addon_field);
+ table->sort.addon_buf= NULL;
+ table->sort.addon_field= NULL;
}
/** Make a array of string pointers. */
@@ -413,7 +402,7 @@ static uchar *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count,
if (reinit_io_cache(buffpek_pointers,READ_CACHE,0L,0,0) ||
my_b_read(buffpek_pointers, (uchar*) tmp, length))
{
- my_free((char*) tmp, MYF(0));
+ my_free(tmp);
tmp=0;
}
}
diff --git a/sql/gstream.h b/sql/gstream.h
index 65acc2ff193..6bb3c9bac10 100644
--- a/sql/gstream.h
+++ b/sql/gstream.h
@@ -45,7 +45,7 @@ public:
{}
~Gis_read_stream()
{
- my_free((uchar*) m_err_msg, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_err_msg);
}
enum enum_tok_types get_next_toc_type();
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 68b98c79a50..ecf2984a4c0 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -1035,7 +1035,7 @@ int get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
}
if (loop == 0 && offset > buffer_size)
{
- my_free(buffer, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(buffer);
buffer_size= 0;
DBUG_PRINT("info", ("allocate blobs buffer size %u", offset));
buffer= (uchar*) my_malloc(offset, MYF(MY_WME));
@@ -1188,8 +1188,8 @@ int ha_ndbcluster::get_metadata(const char *path)
if (readfrm(path, &data, &length) ||
packfrm(data, length, &pack_data, &pack_length))
{
- my_free(data, MYF(MY_ALLOW_ZERO_PTR));
- my_free(pack_data, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(data);
+ my_free(pack_data);
DBUG_RETURN(1);
}
@@ -1208,8 +1208,8 @@ int ha_ndbcluster::get_metadata(const char *path)
DBUG_DUMP("frm", (uchar*) tab->getFrmData(), tab->getFrmLength());
error= HA_ERR_TABLE_DEF_CHANGED;
}
- my_free((char*)data, MYF(0));
- my_free((char*)pack_data, MYF(0));
+ my_free(data);
+ my_free(pack_data);
if (error)
goto err;
@@ -1235,7 +1235,7 @@ static int fix_unique_index_attr_order(NDB_INDEX_DATA &data,
unsigned sz= index->getNoOfIndexColumns();
if (data.unique_index_attrid_map)
- my_free((char*)data.unique_index_attrid_map, MYF(0));
+ my_free(data.unique_index_attrid_map);
data.unique_index_attrid_map= (uchar*)my_malloc(sz,MYF(MY_WME));
if (data.unique_index_attrid_map == 0)
{
@@ -1313,7 +1313,7 @@ static void ndb_clear_index(NDB_INDEX_DATA &data)
{
if (data.unique_index_attrid_map)
{
- my_free((char*)data.unique_index_attrid_map, MYF(0));
+ my_free(data.unique_index_attrid_map);
}
if (data.index_stat)
{
@@ -5399,15 +5399,15 @@ int ha_ndbcluster::create(const char *name,
DBUG_RETURN(1);
if (packfrm(data, length, &pack_data, &pack_length))
{
- my_free((char*)data, MYF(0));
+ my_free(data);
DBUG_RETURN(2);
}
DBUG_PRINT("info",
("setFrm data: 0x%lx len: %lu", (long) pack_data,
(ulong) pack_length));
tab.setFrm(pack_data, pack_length);
- my_free((char*)data, MYF(0));
- my_free((char*)pack_data, MYF(0));
+ my_free(data);
+ my_free(pack_data);
/*
Check for disk options
@@ -5751,8 +5751,8 @@ int ha_ndbcluster::create_handler_files(const char *file,
packfrm(data, length, &pack_data, &pack_length))
{
DBUG_PRINT("info", ("Missing frm for %s", m_tabname));
- my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
- my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(data);
+ my_free(pack_data);
error= 1;
}
else
@@ -5766,8 +5766,8 @@ int ha_ndbcluster::create_handler_files(const char *file,
set_ndb_err(current_thd, dict->getNdbError());
error= ndb_to_mysql_error(&dict->getNdbError());
}
- my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
- my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(data);
+ my_free(pack_data);
}
set_ndb_share_state(m_share, NSS_INITIAL);
@@ -6565,7 +6565,7 @@ ha_ndbcluster::~ha_ndbcluster()
free_share(&m_share);
}
release_metadata(thd, ndb);
- my_free(m_blobs_buffer, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_blobs_buffer);
m_blobs_buffer= 0;
// Check for open cursor/transaction
@@ -6911,7 +6911,7 @@ int ndbcluster_discover(handlerton *hton, THD* thd, const char *db,
DBUG_RETURN(0);
err:
- my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(data);
if (share)
{
/* ndb_share reference temporary free */
@@ -7177,8 +7177,8 @@ int ndbcluster_find_all_files(THD *thd)
free_share(&share);
}
}
- my_free((char*) data, MYF(MY_ALLOW_ZERO_PTR));
- my_free((char*) pack_data, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(data);
+ my_free(pack_data);
mysql_mutex_lock(&LOCK_open);
if (discover)
@@ -8681,7 +8681,7 @@ NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table,
if (my_hash_insert(&ndbcluster_open_tables, (uchar*) share))
{
free_root(&share->mem_root, MYF(0));
- my_free((uchar*) share, 0);
+ my_free(share);
*root_ptr= old_root;
if (!have_lock)
mysql_mutex_unlock(&ndbcluster_mutex);
@@ -8752,7 +8752,7 @@ void ndbcluster_real_free_share(NDB_SHARE **share)
}
#endif
free_root(&(*share)->mem_root, MYF(0));
- my_free((uchar*) *share, MYF(0));
+ my_free(*share);
*share= 0;
dbug_print_open_tables();
@@ -10076,7 +10076,7 @@ int ha_ndbcluster::set_range_data(void *tab_ref, partition_info *part_info)
}
tab->setRangeListData(range_data, sizeof(int32)*part_info->num_parts);
error:
- my_free((char*)range_data, MYF(0));
+ my_free(range_data);
DBUG_RETURN(error);
}
@@ -10113,7 +10113,7 @@ int ha_ndbcluster::set_list_data(void *tab_ref, partition_info *part_info)
}
tab->setRangeListData(list_data, 2*sizeof(int32)*part_info->num_list_values);
error:
- my_free((char*)list_data, MYF(0));
+ my_free(list_data);
DBUG_RETURN(error);
}
diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc
index ab046164485..4f8bb66fcb0 100644
--- a/sql/ha_ndbcluster_binlog.cc
+++ b/sql/ha_ndbcluster_binlog.cc
@@ -1020,7 +1020,7 @@ static void ndbcluster_get_schema(NDB_SHARE *share,
ptrdiff);
if (ret != 0)
{
- my_free(blobs_buffer, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(blobs_buffer);
DBUG_PRINT("info", ("blob read error"));
DBUG_ASSERT(FALSE);
}
@@ -1071,7 +1071,7 @@ static void ndbcluster_get_schema(NDB_SHARE *share,
field++;
s->type= ((Field_long *)*field)->val_int();
/* free blobs buffer */
- my_free(blobs_buffer, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(blobs_buffer);
dbug_tmp_restore_column_map(table->read_set, old_map);
}
@@ -1739,7 +1739,7 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp,
old->getObjectVersion() != altered_table->getObjectVersion())
dict->putTable(altered_table);
- my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(data);
data= NULL;
if ((error= unpackfrm(&data, &length,
(const uchar*) altered_table->getFrmData())) ||
@@ -1772,8 +1772,8 @@ ndb_handle_schema_change(THD *thd, Ndb *ndb, NdbEventOperation *pOp,
mysql_mutex_unlock(&LOCK_open);
}
- my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
- my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(data);
+ my_free(pack_data);
}
// If only frm was changed continue replicating
@@ -3507,8 +3507,8 @@ ndb_binlog_thread_handle_data_event(Ndb *ndb, NdbEventOperation *pOp,
if (share->flags & NSF_BLOB_FLAG)
{
- my_free(blobs_buffer[0], MYF(MY_ALLOW_ZERO_PTR));
- my_free(blobs_buffer[1], MYF(MY_ALLOW_ZERO_PTR));
+ my_free(blobs_buffer[0]);
+ my_free(blobs_buffer[1]);
}
return 0;
@@ -3580,7 +3580,7 @@ static NDB_SCHEMA_OBJECT *ndb_get_schema_object(const char *key,
ndb_schema_object->key_length= length;
if (my_hash_insert(&ndb_schema_objects, (uchar*) ndb_schema_object))
{
- my_free((uchar*) ndb_schema_object, 0);
+ my_free(ndb_schema_object);
break;
}
mysql_mutex_init(key_ndb_schema_object_mutex, &ndb_schema_object->mutex, MY_MUTEX_INIT_FAST);
@@ -3612,7 +3612,7 @@ static void ndb_free_schema_object(NDB_SCHEMA_OBJECT **ndb_schema_object,
DBUG_PRINT("info", ("use_count: %d", (*ndb_schema_object)->use_count));
my_hash_delete(&ndb_schema_objects, (uchar*) *ndb_schema_object);
mysql_mutex_destroy(&(*ndb_schema_object)->mutex);
- my_free((uchar*) *ndb_schema_object, MYF(0));
+ my_free(*ndb_schema_object);
*ndb_schema_object= 0;
}
else
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 60f2d4d9dc5..bd3cd780bc5 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -287,7 +287,7 @@ ha_partition::~ha_partition()
for (i= 0; i < m_tot_parts; i++)
delete m_file[i];
}
- my_free((char*) m_ordered_rec_buffer, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_ordered_rec_buffer);
clear_handler_file();
DBUG_VOID_RETURN;
@@ -2267,7 +2267,7 @@ bool ha_partition::create_handler_file(const char *name)
}
else
result= TRUE;
- my_free((char*) file_buffer, MYF(0));
+ my_free(file_buffer);
DBUG_RETURN(result);
}
@@ -2285,8 +2285,8 @@ void ha_partition::clear_handler_file()
{
if (m_engine_array)
plugin_unlock_list(NULL, m_engine_array, m_tot_parts);
- my_free((char*) m_file_buffer, MYF(MY_ALLOW_ZERO_PTR));
- my_free((char*) m_engine_array, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_file_buffer);
+ my_free(m_engine_array);
m_file_buffer= NULL;
m_engine_array= NULL;
}
@@ -2495,7 +2495,7 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root)
err3:
my_afree((gptr) engine_array);
err2:
- my_free(file_buffer, MYF(0));
+ my_free(file_buffer);
err1:
(void) mysql_file_close(file, MYF(0));
DBUG_RETURN(TRUE);
diff --git a/sql/handler.cc b/sql/handler.cc
index 587490dd708..b42840c7b1b 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -392,7 +392,7 @@ static int ha_finish_errors(void)
/* Allocate a pointer array for the error message strings. */
if (! (errmsgs= my_error_unregister(HA_ERR_FIRST, HA_ERR_LAST)))
return 1;
- my_free((uchar*) errmsgs, MYF(0));
+ my_free(errmsgs);
return 0;
}
@@ -447,7 +447,7 @@ int ha_finalize_handlerton(st_plugin_int *plugin)
hton2plugin[hton->slot]= NULL;
}
- my_free((uchar*)hton, MYF(0));
+ my_free(hton);
end:
DBUG_RETURN(0);
@@ -580,7 +580,7 @@ err_deinit:
(void) plugin->plugin->deinit(NULL);
err:
- my_free((uchar*) hton, MYF(0));
+ my_free(hton);
err_no_hton_memory:
plugin->data= NULL;
DBUG_RETURN(1);
@@ -1630,7 +1630,7 @@ int ha_recover(HASH *commit_list)
plugin_foreach(NULL, xarecover_handlerton,
MYSQL_STORAGE_ENGINE_PLUGIN, &info);
- my_free((uchar*)info.list, MYF(0));
+ my_free(info.list);
if (info.found_foreign_xids)
sql_print_warning("Found %d prepared XA transactions",
info.found_foreign_xids);
@@ -3658,7 +3658,7 @@ int ha_create_table_from_engine(THD* thd, const char *db, const char *name)
build_table_filename(path, sizeof(path) - 1, db, name, "", 0);
// Save the frm file
error= writefrm(path, frmblob, frmlen);
- my_free(frmblob, MYF(0));
+ my_free(frmblob);
if (error)
DBUG_RETURN(2);
@@ -4865,7 +4865,7 @@ int fl_log_iterator_next(struct handler_iterator *iterator,
void fl_log_iterator_destroy(struct handler_iterator *iterator)
{
- my_free((uchar*)iterator->buffer, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(iterator->buffer);
}
diff --git a/sql/handler.h b/sql/handler.h
index d73bd949a02..96095798d18 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -461,11 +461,7 @@ typedef struct xid_t XID;
/* for recover() handlerton call */
#define MIN_XID_LIST_SIZE 128
-#ifdef SAFEMALLOC
-#define MAX_XID_LIST_SIZE 256
-#else
#define MAX_XID_LIST_SIZE (1024*128)
-#endif
/*
These structures are used to pass information from a set of SQL commands
diff --git a/sql/item.h b/sql/item.h
index e18fa43037a..35a0e8373f2 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -2791,6 +2791,7 @@ protected:
cached_field_type= item->field_type();
cached_result_type= item->result_type();
unsigned_flag= item->unsigned_flag;
+ fixed= item->fixed;
}
public:
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 4e6b3d7a241..833eac6893b 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -51,6 +51,7 @@
#include "sp_rcontext.h"
#include "sp.h"
#include "set_var.h"
+#include "debug_sync.h"
#ifdef NO_EMBEDDED_ACCESS_CHECKS
#define sp_restore_security_context(A,B) while (0) {}
@@ -1941,6 +1942,8 @@ double Item_func_pow::val_real()
double Item_func_acos::val_real()
{
DBUG_ASSERT(fixed == 1);
+ /* One can use this to defer SELECT processing. */
+ DEBUG_SYNC(current_thd, "before_acos_function");
// the volatile's for BUG #2338 to calm optimizer down (because of gcc's bug)
volatile double value= args[0]->val_real();
if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0))))
@@ -3557,7 +3560,7 @@ public:
{
if (my_hash_insert(&hash_user_locks,(uchar*) this))
{
- my_free(key,MYF(0));
+ my_free(key);
key=0;
}
}
@@ -3567,7 +3570,7 @@ public:
if (key)
{
my_hash_delete(&hash_user_locks,(uchar*) this);
- my_free(key, MYF(0));
+ my_free(key);
}
mysql_cond_destroy(&cond);
}
@@ -4076,7 +4079,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
memcpy(entry->name.str, name.str, name.length+1);
if (my_hash_insert(hash,(uchar*) entry))
{
- my_free((char*) entry,MYF(0));
+ my_free(entry);
return 0;
}
}
@@ -4214,7 +4217,7 @@ update_hash(user_var_entry *entry, bool set_null, void *ptr, uint length,
{
char *pos= (char*) entry+ ALIGN_SIZE(sizeof(user_var_entry));
if (entry->value && entry->value != pos)
- my_free(entry->value,MYF(0));
+ my_free(entry->value);
entry->value= 0;
entry->length= 0;
}
@@ -4229,7 +4232,7 @@ update_hash(user_var_entry *entry, bool set_null, void *ptr, uint length,
if (entry->value != pos)
{
if (entry->value)
- my_free(entry->value,MYF(0));
+ my_free(entry->value);
entry->value=pos;
}
}
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 61febb01e93..851d0e07a7e 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -72,7 +72,12 @@ String *Item_str_ascii_func::val_str(String *str)
DBUG_ASSERT(fixed == 1);
if (!(collation.collation->state & MY_CS_NONASCII))
- return val_str_ascii(str);
+ {
+ String *res= val_str_ascii(str);
+ if (res)
+ res->set_charset(collation.collation);
+ return res;
+ }
DBUG_ASSERT(str != &ascii_buf);
@@ -242,7 +247,7 @@ void Item_func_sha::fix_length_and_dec()
fix_length_and_charset(SHA1_HASH_SIZE * 2, default_charset());
}
-String *Item_func_sha2::val_str(String *str)
+String *Item_func_sha2::val_str_ascii(String *str)
{
DBUG_ASSERT(fixed == 1);
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
@@ -338,19 +343,19 @@ void Item_func_sha2::fix_length_and_dec()
switch (sha_variant) {
#ifndef OPENSSL_NO_SHA512
case 512:
- max_length= SHA512_DIGEST_LENGTH*2;
+ fix_length_and_charset(SHA512_DIGEST_LENGTH * 2, default_charset());
break;
case 384:
- max_length= SHA384_DIGEST_LENGTH*2;
+ fix_length_and_charset(SHA384_DIGEST_LENGTH * 2, default_charset());
break;
#endif
#ifndef OPENSSL_NO_SHA256
case 256:
case 0: // SHA-256 is the default
- max_length= SHA256_DIGEST_LENGTH*2;
+ fix_length_and_charset(SHA256_DIGEST_LENGTH * 2, default_charset());
break;
case 224:
- max_length= SHA224_DIGEST_LENGTH*2;
+ fix_length_and_charset(SHA224_DIGEST_LENGTH * 2, default_charset());
break;
#endif
default:
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 2a34babae87..df794ecaaf4 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -82,16 +82,13 @@ public:
const char *func_name() const { return "sha"; }
};
-class Item_func_sha2 :public Item_str_func
+class Item_func_sha2 :public Item_str_ascii_func
{
public:
- Item_func_sha2(Item *a, Item *b) :Item_str_func(a, b)
- {
- collation.set(&my_charset_bin);
- }
- String *val_str(String *);
- void fix_length_and_dec();
- const char *func_name() const { return "sha2"; }
+ Item_func_sha2(Item *a, Item *b) :Item_str_ascii_func(a, b) {}
+ String *val_str_ascii(String *);
+ void fix_length_and_dec();
+ const char *func_name() const { return "sha2"; }
};
class Item_func_aes_encrypt :public Item_str_func
diff --git a/sql/keycaches.cc b/sql/keycaches.cc
index d68e2bccd96..14551803cfc 100644
--- a/sql/keycaches.cc
+++ b/sql/keycaches.cc
@@ -44,7 +44,7 @@ public:
}
~NAMED_ILINK()
{
- my_free((uchar*) name, MYF(0));
+ my_free((void *) name);
}
};
@@ -104,7 +104,7 @@ KEY_CACHE *create_key_cache(const char *name, uint length)
{
if (!new NAMED_ILINK(&key_caches, name, length, (uchar*) key_cache))
{
- my_free((char*) key_cache, MYF(0));
+ my_free(key_cache);
key_cache= 0;
}
else
@@ -140,7 +140,7 @@ KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
void free_key_cache(const char *name, KEY_CACHE *key_cache)
{
end_key_cache(key_cache, 1); // Can never fail
- my_free((char*) key_cache, MYF(0));
+ my_free(key_cache);
}
diff --git a/sql/lock.cc b/sql/lock.cc
index 52d97a2422b..0743120ec6b 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -262,7 +262,7 @@ static void reset_lock_data(MYSQL_LOCK *sql_lock)
static void reset_lock_data_and_free(MYSQL_LOCK **mysql_lock)
{
reset_lock_data(*mysql_lock);
- my_free(*mysql_lock, MYF(0));
+ my_free(*mysql_lock);
*mysql_lock= 0;
}
@@ -384,7 +384,7 @@ void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock)
thr_multi_unlock(sql_lock->locks,sql_lock->lock_count);
if (sql_lock->table_count)
(void) unlock_external(thd,sql_lock->table,sql_lock->table_count);
- my_free((uchar*) sql_lock,MYF(0));
+ my_free(sql_lock);
DBUG_VOID_RETURN;
}
@@ -545,7 +545,7 @@ void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock)
{
for (uint i=0; i < locked->lock_count; i++)
thr_abort_locks(locked->locks[i]->lock, upgrade_lock);
- my_free((uchar*) locked,MYF(0));
+ my_free(locked);
}
DBUG_VOID_RETURN;
}
@@ -577,7 +577,7 @@ bool mysql_lock_abort_for_thread(THD *thd, TABLE *table)
table->in_use->thread_id))
result= TRUE;
}
- my_free((uchar*) locked,MYF(0));
+ my_free(locked);
}
DBUG_RETURN(result);
}
@@ -619,8 +619,8 @@ MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b)
}
/* Delete old, not needed locks */
- my_free((uchar*) a,MYF(0));
- my_free((uchar*) b,MYF(0));
+ my_free(a);
+ my_free(b);
thr_lock_merge_status(sql_lock->locks, sql_lock->lock_count);
DBUG_RETURN(sql_lock);
diff --git a/sql/log.cc b/sql/log.cc
index cbf6d2589b0..b398cb1e73f 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -209,7 +209,7 @@ class binlog_cache_data
{
public:
binlog_cache_data(): m_pending(0), before_stmt_pos(MY_OFF_T_UNDEF),
- incident(FALSE)
+ incident(FALSE), changes_to_non_trans_temp_table_flag(FALSE)
{
cache_log.end_of_file= max_binlog_cache_size;
}
@@ -245,9 +245,20 @@ public:
return(incident);
}
+ void set_changes_to_non_trans_temp_table()
+ {
+ changes_to_non_trans_temp_table_flag= TRUE;
+ }
+
+ bool changes_to_non_trans_temp_table()
+ {
+ return (changes_to_non_trans_temp_table_flag);
+ }
+
void reset()
{
truncate(0);
+ changes_to_non_trans_temp_table_flag= FALSE;
incident= FALSE;
before_stmt_pos= MY_OFF_T_UNDEF;
cache_log.end_of_file= max_binlog_cache_size;
@@ -305,6 +316,12 @@ private:
bool incident;
/*
+ This flag indicates if the cache has changes to temporary tables.
+ @TODO This a temporary fix and should be removed after BUG#54562.
+ */
+ bool changes_to_non_trans_temp_table_flag;
+
+ /*
It truncates the cache to a certain position. This includes deleting the
pending event.
*/
@@ -1484,7 +1501,7 @@ static int binlog_close_connection(handlerton *hton, THD *thd)
DBUG_ASSERT(cache_mngr->trx_cache.empty() && cache_mngr->stmt_cache.empty());
thd_set_ha_data(thd, binlog_hton, NULL);
cache_mngr->~binlog_cache_mngr();
- my_free((uchar*)cache_mngr, MYF(0));
+ my_free(cache_mngr);
return 0;
}
@@ -1772,13 +1789,23 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all)
/*
We flush the cache wrapped in a beging/rollback if:
. aborting a single or multi-statement transaction and;
- . the format is STMT and non-trans engines were updated or;
- . the OPTION_KEEP_LOG is activate.
+ . the OPTION_KEEP_LOG is active or;
+ . the format is STMT and a non-trans table was updated or;
+ . the format is MIXED and a temporary non-trans table was
+ updated or;
+ . the format is MIXED, non-trans table was updated and
+ aborting a single statement transaction;
*/
+
if (ending_trans(thd, all) &&
((thd->variables.option_bits & OPTION_KEEP_LOG) ||
(trans_has_updated_non_trans_table(thd) &&
- thd->variables.binlog_format == BINLOG_FORMAT_STMT)))
+ thd->variables.binlog_format == BINLOG_FORMAT_STMT) ||
+ (cache_mngr->trx_cache.changes_to_non_trans_temp_table() &&
+ thd->variables.binlog_format == BINLOG_FORMAT_MIXED) ||
+ (trans_has_updated_non_trans_table(thd) &&
+ ending_single_stmt_trans(thd,all) &&
+ thd->variables.binlog_format == BINLOG_FORMAT_MIXED)))
{
Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE, TRUE, 0);
error= binlog_flush_trx_cache(thd, cache_mngr, &qev);
@@ -1786,13 +1813,18 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all)
/*
Truncate the cache if:
. aborting a single or multi-statement transaction or;
- . the OPTION_KEEP_LOG is not activate and;
- . the format is not STMT or no non-trans were updated.
+ . the OPTION_KEEP_LOG is not active and;
+ . the format is not STMT or no non-trans table was
+ updated and;
+ . the format is not MIXED or no temporary non-trans table
+ was updated.
*/
else if (ending_trans(thd, all) ||
(!(thd->variables.option_bits & OPTION_KEEP_LOG) &&
- ((!stmt_has_updated_non_trans_table(thd) ||
- thd->variables.binlog_format != BINLOG_FORMAT_STMT))))
+ (!stmt_has_updated_non_trans_table(thd) ||
+ thd->variables.binlog_format != BINLOG_FORMAT_STMT) &&
+ (!cache_mngr->trx_cache.changes_to_non_trans_temp_table() ||
+ thd->variables.binlog_format != BINLOG_FORMAT_MIXED)))
error= binlog_truncate_trx_cache(thd, cache_mngr, all);
}
@@ -2213,7 +2245,8 @@ shutdown the MySQL server and restart it.", name, errno);
if (file >= 0)
mysql_file_close(file, MYF(0));
end_io_cache(&log_file);
- safeFree(name);
+ my_free(name);
+ name= NULL;
log_state= LOG_CLOSED;
DBUG_RETURN(1);
}
@@ -2274,7 +2307,8 @@ void MYSQL_LOG::close(uint exiting)
}
log_state= (exiting & LOG_CLOSE_TO_BE_OPENED) ? LOG_TO_BE_OPENED : LOG_CLOSED;
- safeFree(name);
+ my_free(name);
+ name= NULL;
DBUG_VOID_RETURN;
}
@@ -2352,7 +2386,7 @@ void MYSQL_QUERY_LOG::reopen_file()
*/
open(save_name, log_type, 0, io_cache_type);
- my_free(save_name, MYF(0));
+ my_free(save_name);
mysql_mutex_unlock(&LOCK_log);
@@ -2953,7 +2987,8 @@ shutdown the MySQL server and restart it.", name, errno);
mysql_file_close(file, MYF(0));
end_io_cache(&log_file);
end_io_cache(&index_file);
- safeFree(name);
+ my_free(name);
+ name= NULL;
log_state= LOG_CLOSED;
DBUG_RETURN(1);
}
@@ -3286,7 +3321,7 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd)
need_start_event=1;
if (!open_index_file(index_file_name, 0, FALSE))
open(save_name, log_type, 0, io_cache_type, no_auto_events, max_size, 0, FALSE);
- my_free((uchar*) save_name, MYF(0));
+ my_free((void *) save_name);
err:
if (error == 1)
@@ -3424,7 +3459,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
DBUG_ASSERT(!included || rli->linfo.index_file_start_offset == 0);
err:
- my_free(to_purge_if_included, MYF(0));
+ my_free(to_purge_if_included);
mysql_mutex_unlock(&LOCK_index);
DBUG_RETURN(error);
}
@@ -4064,7 +4099,7 @@ void MYSQL_BIN_LOG::new_file_impl(bool need_lock)
if (!open_index_file(index_file_name, 0, FALSE))
open(old_name, log_type, new_name_ptr,
io_cache_type, no_auto_events, max_size, 1, FALSE);
- my_free(old_name,MYF(0));
+ my_free(old_name);
end:
if (need_lock)
@@ -4254,7 +4289,23 @@ bool use_trans_cache(const THD* thd, bool is_transactional)
*/
bool ending_trans(THD* thd, const bool all)
{
- return (all || (!all && !thd->in_multi_stmt_transaction_mode()));
+ return (all || ending_single_stmt_trans(thd, all));
+}
+
+/**
+ This function checks if a single statement transaction is about
+ to commit or not.
+
+ @param thd The client thread that executed the current statement.
+ @param all Committing a transaction (i.e. TRUE) or a statement
+ (i.e. FALSE).
+ @return
+ @c true if committing a single statement transaction, otherwise
+ @c false.
+*/
+bool ending_single_stmt_trans(THD* thd, const bool all)
+{
+ return (!all && !thd->in_multi_stmt_transaction_mode());
}
/**
@@ -4306,7 +4357,7 @@ int THD::binlog_setup_trx_data()
open_cached_file(&cache_mngr->trx_cache.cache_log, mysql_tmpdir,
LOG_PREFIX, binlog_cache_size, MYF(MY_WME)))
{
- my_free((uchar*)cache_mngr, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(cache_mngr);
DBUG_RETURN(1); // Didn't manage to set it up
}
thd_set_ha_data(this, binlog_hton, cache_mngr);
@@ -4653,6 +4704,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
file= cache_mngr->get_binlog_cache_log(is_trans_cache);
cache_data= cache_mngr->get_binlog_cache_data(is_trans_cache);
+ if (thd->stmt_accessed_non_trans_temp_table())
+ cache_data->set_changes_to_non_trans_temp_table();
+
thd->binlog_start_trans_and_stmt();
}
DBUG_PRINT("info",("event type: %d",event_info->get_type_code()));
@@ -5310,7 +5364,8 @@ void MYSQL_BIN_LOG::close(uint exiting)
}
}
log_state= (exiting & LOG_CLOSE_TO_BE_OPENED) ? LOG_TO_BE_OPENED : LOG_CLOSED;
- safeFree(name);
+ my_free(name);
+ name= NULL;
DBUG_VOID_RETURN;
}
@@ -6001,7 +6056,7 @@ void TC_LOG_MMAP::close()
mysql_cond_destroy(&pages[i].cond);
}
case 3:
- my_free((uchar*)pages, MYF(0));
+ my_free(pages);
case 2:
my_munmap((char*)data, (size_t)file_length);
case 1:
diff --git a/sql/log.h b/sql/log.h
index d264f62fb64..4a58c3081d8 100644
--- a/sql/log.h
+++ b/sql/log.h
@@ -27,6 +27,7 @@ bool trans_has_updated_trans_table(const THD* thd);
bool stmt_has_updated_trans_table(const THD *thd);
bool use_trans_cache(const THD* thd, bool is_transactional);
bool ending_trans(THD* thd, const bool all);
+bool ending_single_stmt_trans(THD* thd, const bool all);
bool trans_has_updated_non_trans_table(const THD* thd);
bool stmt_has_updated_non_trans_table(const THD* thd);
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 90ec9eabcd1..5236a2794cf 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -678,8 +678,9 @@ Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans)
{
server_id= thd->server_id;
when= thd->start_time;
- cache_type= (using_trans || stmt_has_updated_trans_table(thd)
- || thd->thread_temporary_used
+ cache_type= ((using_trans || stmt_has_updated_trans_table(thd) ||
+ (thd->stmt_accessed_temp_table() &&
+ trans_has_updated_trans_table(thd)))
? Log_event::EVENT_TRANSACTIONAL_CACHE :
Log_event::EVENT_STMT_CACHE);
}
@@ -1148,7 +1149,7 @@ err:
sql_print_error("Error in Log_event::read_log_event(): "
"'%s', data_len: %d, event_type: %d",
error,data_len,head[EVENT_TYPE_OFFSET]);
- my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(buf);
/*
The SQL slave thread will check if file->error<0 to know
if there was an I/O error. Even if there is no "low-level" I/O errors
@@ -2065,7 +2066,7 @@ void Log_event::print_base64(IO_CACHE* file,
}
}
- my_free(tmp_str, MYF(0));
+ my_free(tmp_str);
DBUG_VOID_RETURN;
}
@@ -2145,7 +2146,7 @@ void Query_log_event::pack_info(Protocol *protocol)
pos+= q_len;
}
protocol->store(buf, pos-buf, &my_charset_bin);
- my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(buf);
}
#endif
@@ -2571,8 +2572,9 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
}
else
{
- cache_type= ((using_trans || stmt_has_updated_trans_table(thd)
- || trx_cache || thd->thread_temporary_used)
+ cache_type= ((using_trans || stmt_has_updated_trans_table(thd) || trx_cache ||
+ (thd->stmt_accessed_temp_table() &&
+ trans_has_updated_trans_table(thd)))
? Log_event::EVENT_TRANSACTIONAL_CACHE :
Log_event::EVENT_STMT_CACHE);
}
@@ -4040,7 +4042,7 @@ Format_description_log_event(const char* buf,
DBUG_PRINT("info", (" number_of_event_types=%d",
number_of_event_types));
/* this makes is_valid() return false. */
- my_free(post_header_len, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(post_header_len);
post_header_len= NULL;
DBUG_VOID_RETURN;
}
@@ -4363,7 +4365,7 @@ void Load_log_event::pack_info(Protocol *protocol)
return;
print_query(TRUE, NULL, buf, &end, 0, 0);
protocol->store(buf, end-buf, &my_charset_bin);
- my_free(buf, MYF(0));
+ my_free(buf);
}
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
@@ -5632,7 +5634,7 @@ void User_var_log_event::pack_info(Protocol* protocol)
buf[2+name_len]= '`';
buf[3+name_len]= '=';
protocol->store(buf, event_len, &my_charset_bin);
- my_free(buf, MYF(0));
+ my_free(buf);
}
#endif /* !MYSQL_CLIENT */
@@ -6047,7 +6049,7 @@ Slave_log_event::Slave_log_event(THD* thd_arg,
Slave_log_event::~Slave_log_event()
{
- my_free(mem_pool, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(mem_pool);
}
@@ -6868,7 +6870,7 @@ int Execute_load_log_event::do_apply_event(Relay_log_info const *rli)
{
rli->report(ERROR_LEVEL, rli->last_error().number,
"%s. Failed executing load from '%s'", tmp, fname);
- my_free(tmp,MYF(0));
+ my_free(tmp);
}
goto err;
}
@@ -7073,7 +7075,7 @@ void Execute_load_query_log_event::pack_info(Protocol *protocol)
pos= strmov(pos, " ;file_id=");
pos= int10_to_str((long) file_id, pos, 10);
protocol->store(buf, pos-buf, &my_charset_bin);
- my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(buf);
}
@@ -7089,7 +7091,7 @@ Execute_load_query_log_event::do_apply_event(Relay_log_info const *rli)
buf= (char*) my_malloc(q_len + 1 - (fn_pos_end - fn_pos_start) +
(FN_REFLEN + 10) + 10 + 8 + 5, MYF(MY_WME));
- DBUG_EXECUTE_IF("LOAD_DATA_INFILE_has_fatal_error", my_free(buf, MYF(0)); buf= NULL;);
+ DBUG_EXECUTE_IF("LOAD_DATA_INFILE_has_fatal_error", my_free(buf); buf= NULL;);
/* Replace filename and LOCAL keyword in query before executing it */
if (buf == NULL)
@@ -7132,7 +7134,7 @@ Execute_load_query_log_event::do_apply_event(Relay_log_info const *rli)
if (!error)
mysql_file_delete(key_file_log_event_data, fname, MYF(MY_WME));
- my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(buf);
return error;
}
#endif
@@ -7397,7 +7399,7 @@ Rows_log_event::~Rows_log_event()
if (m_cols.bitmap == m_bitbuf) // no my_malloc happened
m_cols.bitmap= 0; // so no my_free in bitmap_free
bitmap_free(&m_cols); // To pair with bitmap_init().
- my_free((uchar*)m_rows_buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_rows_buf);
}
int Rows_log_event::get_data_size()
@@ -8321,8 +8323,8 @@ Table_map_log_event::Table_map_log_event(const char *buf, uint event_len,
Table_map_log_event::~Table_map_log_event()
{
- my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
- my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_meta_memory);
+ my_free(m_memory);
}
/*
@@ -8372,7 +8374,7 @@ int Table_map_log_event::do_apply_event(Relay_log_info const *rli)
(!rpl_filter->db_ok(table_list->db) ||
(rpl_filter->is_on() && !rpl_filter->tables_ok("", table_list))))
{
- my_free(memory, MYF(MY_WME));
+ my_free(memory);
}
else
{
@@ -9427,7 +9429,7 @@ Delete_rows_log_event::do_after_row_operations(const Slave_reporting_capability
{
/*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
m_table->file->ha_index_or_rnd_end();
- my_free(m_key, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_key);
m_key= NULL;
return error;
@@ -9550,7 +9552,7 @@ Update_rows_log_event::do_after_row_operations(const Slave_reporting_capability
{
/*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
m_table->file->ha_index_or_rnd_end();
- my_free(m_key, MYF(MY_ALLOW_ZERO_PTR)); // Free for multi_malloc
+ my_free(m_key); // Free for multi_malloc
m_key= NULL;
return error;
diff --git a/sql/log_event.h b/sql/log_event.h
index 688bc3a9aa6..5d7250d8ebd 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -1034,7 +1034,7 @@ public:
static void operator delete(void *ptr, size_t size)
{
- my_free((uchar*) ptr, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
+ my_free(ptr);
}
/* Placement version of the above operators */
@@ -1091,7 +1091,7 @@ public:
{
if (temp_buf)
{
- my_free(temp_buf, MYF(0));
+ my_free(temp_buf);
temp_buf = 0;
}
}
@@ -1725,7 +1725,7 @@ public:
~Query_log_event()
{
if (data_buf)
- my_free((uchar*) data_buf, MYF(0));
+ my_free(data_buf);
}
Log_event_type get_type_code() { return QUERY_EVENT; }
#ifdef MYSQL_SERVER
@@ -2304,7 +2304,7 @@ public:
*description_event);
~Format_description_log_event()
{
- my_free((uchar*)post_header_len, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(post_header_len);
}
Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;}
#ifdef MYSQL_SERVER
@@ -2703,7 +2703,7 @@ public:
~Rotate_log_event()
{
if (flags & DUP_NAME)
- my_free((uchar*) new_log_ident, MYF(MY_ALLOW_ZERO_PTR));
+ my_free((void*) new_log_ident);
}
Log_event_type get_type_code() { return ROTATE_EVENT;}
int get_data_size() { return ident_len + ROTATE_HEADER_LEN;}
@@ -2765,7 +2765,7 @@ public:
const Format_description_log_event* description_event);
~Create_file_log_event()
{
- my_free((char*) event_buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free((void*) event_buf);
}
Log_event_type get_type_code()
diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc
index dd333b246e0..88df4970816 100644
--- a/sql/log_event_old.cc
+++ b/sql/log_event_old.cc
@@ -1017,7 +1017,7 @@ int Delete_rows_log_event_old::do_after_row_operations(TABLE *table, int error)
{
/*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
table->file->ha_index_or_rnd_end();
- my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR)); // Free for multi_malloc
+ my_free(m_memory); // Free for multi_malloc
m_memory= NULL;
m_after_image= NULL;
m_key= NULL;
@@ -1116,7 +1116,7 @@ int Update_rows_log_event_old::do_after_row_operations(TABLE *table, int error)
{
/*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
table->file->ha_index_or_rnd_end();
- my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_memory);
m_memory= NULL;
m_after_image= NULL;
m_key= NULL;
@@ -1360,7 +1360,7 @@ Old_rows_log_event::~Old_rows_log_event()
if (m_cols.bitmap == m_bitbuf) // no my_malloc happened
m_cols.bitmap= 0; // so no my_free in bitmap_free
bitmap_free(&m_cols); // To pair with bitmap_init().
- my_free((uchar*)m_rows_buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_rows_buf);
}
@@ -2698,7 +2698,7 @@ Delete_rows_log_event_old::do_after_row_operations(const Slave_reporting_capabil
{
/*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
m_table->file->ha_index_or_rnd_end();
- my_free(m_key, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(m_key);
m_key= NULL;
return error;
@@ -2797,7 +2797,7 @@ Update_rows_log_event_old::do_after_row_operations(const Slave_reporting_capabil
{
/*error= ToDo:find out what this should really be, this triggers close_scan in nbd, returning error?*/
m_table->file->ha_index_or_rnd_end();
- my_free(m_key, MYF(MY_ALLOW_ZERO_PTR)); // Free for multi_malloc
+ my_free(m_key); // Free for multi_malloc
m_key= NULL;
return error;
diff --git a/sql/mdl.cc b/sql/mdl.cc
index 184b3c6051d..0426a410d98 100644
--- a/sql/mdl.cc
+++ b/sql/mdl.cc
@@ -1935,7 +1935,7 @@ bool MDL_context::acquire_locks(MDL_request_list *mdl_requests,
if (acquire_lock(*p_req, lock_wait_timeout))
goto err;
}
- my_free(sort_buf, MYF(0));
+ my_free(sort_buf);
return FALSE;
err:
@@ -1951,7 +1951,7 @@ err:
{
(*p_req)->ticket= NULL;
}
- my_free(sort_buf, MYF(0));
+ my_free(sort_buf);
return TRUE;
}
diff --git a/sql/my_lock.c b/sql/my_lock.c
deleted file mode 100644
index f66d7282f72..00000000000
--- a/sql/my_lock.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* Copyright (C) 2000-2003 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#if defined(__NETWARE__)
-#include "../mysys/my_lock.c"
-#else
-
-#undef MAP_TO_USE_RAID /* Avoid RAID mappings */
-#include <my_global.h>
-#include <my_sys.h>
-#include <mysys_err.h>
-#include <my_pthread.h>
-#include <thr_alarm.h>
-#include <errno.h>
-
- /* Lock a part of a file */
-
-int my_lock(File fd,int locktype,my_off_t start,my_off_t length,myf MyFlags)
-{
- thr_alarm_t alarmed;
- ALARM alarm_buff;
- uint wait_for_alarm;
- struct flock m_lock;
- DBUG_ENTER("my_lock");
- DBUG_PRINT("my",("Fd: %d Op: %d start: %ld Length: %ld MyFlags: %d",
- fd,locktype,(ulong) start,(ulong) length,MyFlags));
- if (my_disable_locking)
- DBUG_RETURN(0); /* purecov: inspected */
- m_lock.l_type=(short) locktype;
- m_lock.l_whence=0L;
- m_lock.l_start=(long) start;
- m_lock.l_len=(long) length;
- wait_for_alarm=(MyFlags & MY_DONT_WAIT ? MY_HOW_OFTEN_TO_ALARM :
- (uint) 12*60*60);
- if (fcntl(fd,F_SETLK,&m_lock) != -1) /* Check if we can lock */
- DBUG_RETURN(0); /* Ok, file locked */
- DBUG_PRINT("info",("Was locked, trying with alarm"));
- if (!thr_alarm(&alarmed,wait_for_alarm,&alarm_buff))
- {
- int value;
- while ((value=fcntl(fd,F_SETLKW,&m_lock)) && !thr_got_alarm(&alarmed) &&
- errno == EINTR) ;
- thr_end_alarm(&alarmed);
- if (value != -1)
- DBUG_RETURN(0);
- }
- else
- {
- errno=EINTR;
- }
- if (errno == EINTR || errno == EACCES)
- my_errno=EAGAIN; /* Easier to check for this */
- else
- my_errno=errno;
-
- if (MyFlags & MY_WME)
- {
- if (locktype == F_UNLCK)
- my_error(EE_CANTUNLOCK,MYF(ME_BELL+ME_WAITTANG),errno);
- else
- my_error(EE_CANTLOCK,MYF(ME_BELL+ME_WAITTANG),errno);
- }
- DBUG_PRINT("error",("errno: %d",errno));
- DBUG_RETURN(-1);
-}
-#endif
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 1e5c3f43f5e..367d488a22c 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -126,14 +126,12 @@ extern "C" { // Because of SCO 3.2V4.2
#include <my_net.h>
#if !defined(__WIN__)
-# ifndef __NETWARE__
#include <sys/resource.h>
-# endif /* __NETWARE__ */
#ifdef HAVE_SYS_UN_H
-# include <sys/un.h>
+#include <sys/un.h>
#endif
#ifdef HAVE_SELECT_H
-# include <select.h>
+#include <select.h>
#endif
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
@@ -164,45 +162,6 @@ extern int memcntl(caddr_t, size_t, int, caddr_t, int, int);
#endif /* __sun__ ... */
#endif /* HAVE_SOLARIS_LARGE_PAGES */
-#ifdef __NETWARE__
-#define zVOLSTATE_ACTIVE 6
-#define zVOLSTATE_DEACTIVE 2
-#define zVOLSTATE_MAINTENANCE 3
-
-#undef __event_h__
-#include <../include/event.h>
-/*
- This #undef exists here because both libc of NetWare and MySQL have
- files named event.h which causes compilation errors.
-*/
-
-#include <nks/netware.h>
-#include <nks/vm.h>
-#include <library.h>
-#include <monitor.h>
-#include <zOmni.h> //For NEB
-#include <neb.h> //For NEB
-#include <nebpub.h> //For NEB
-#include <zEvent.h> //For NSS event structures
-#include <zPublics.h>
-
-static void *neb_consumer_id= NULL; //For storing NEB consumer id
-static char datavolname[256]= {0};
-static VolumeID_t datavolid;
-static event_handle_t eh;
-static Report_t ref;
-static void *refneb= NULL;
-my_bool event_flag= FALSE;
-static int volumeid= -1;
-
- /* NEB event callback */
-unsigned long neb_event_callback(struct EventBlock *eblock);
-static void registerwithneb();
-static void getvolumename();
-static void getvolumeID(BYTE *volumeName);
-#endif /* __NETWARE__ */
-
-
#ifdef _AIX41
int initgroups(const char *,unsigned int);
#endif
@@ -1031,7 +990,7 @@ static void close_connections(void)
flush_thread_cache();
/* kill connection thread */
-#if !defined(__WIN__) && !defined(__NETWARE__)
+#if !defined(__WIN__)
DBUG_PRINT("quit", ("waiting for select thread: 0x%lx",
(ulong) select_thread));
mysql_mutex_lock(&LOCK_thread_count);
@@ -1209,14 +1168,6 @@ static void close_server_sock()
ip_sock=INVALID_SOCKET;
DBUG_PRINT("info",("calling shutdown on TCP/IP socket"));
(void) shutdown(tmp_sock, SHUT_RDWR);
-#if defined(__NETWARE__)
- /*
- The following code is disabled for normal systems as it causes MySQL
- to hang on AIX 4.3 during shutdown
- */
- DBUG_PRINT("info",("calling closesocket on TCP/IP socket"));
- (void) closesocket(tmp_sock);
-#endif
}
tmp_sock=unix_sock;
if (tmp_sock != INVALID_SOCKET)
@@ -1224,14 +1175,6 @@ static void close_server_sock()
unix_sock=INVALID_SOCKET;
DBUG_PRINT("info",("calling shutdown on unix socket"));
(void) shutdown(tmp_sock, SHUT_RDWR);
-#if defined(__NETWARE__)
- /*
- The following code is disabled for normal systems as it may cause MySQL
- to hang on AIX 4.3 during shutdown
- */
- DBUG_PRINT("info",("calling closesocket on unix/IP socket"));
- (void) closesocket(tmp_sock);
-#endif
(void) unlink(mysqld_unix_port);
}
DBUG_VOID_RETURN;
@@ -1300,10 +1243,7 @@ void kill_mysql(void)
or stop, we just want to kill the server.
*/
-#if defined(__NETWARE__)
-extern "C" void kill_server(int sig_ptr)
-#define RETURN_FROM_KILL_SERVER return
-#elif !defined(__WIN__)
+#if !defined(__WIN__)
static void *kill_server(void *sig_ptr)
#define RETURN_FROM_KILL_SERVER return 0
#else
@@ -1349,11 +1289,6 @@ static void __cdecl kill_server(int sig_ptr)
unireg_end();
/* purecov: begin deadcode */
-#ifdef __NETWARE__
- if (!event_flag)
- pthread_join(select_thread, NULL); // wait for main thread
-#endif /* __NETWARE__ */
-
DBUG_LEAVE; // Must match DBUG_ENTER()
my_thread_end();
pthread_exit(0);
@@ -1370,7 +1305,7 @@ static void __cdecl kill_server(int sig_ptr)
}
-#if defined(USE_ONE_SIGNAL_HAND) || (defined(__NETWARE__) && defined(SIGNALS_DONT_BREAK_READ))
+#if defined(USE_ONE_SIGNAL_HAND)
pthread_handler_t kill_server_thread(void *arg __attribute__((unused)))
{
my_thread_init(); // Initialize new thread
@@ -1391,7 +1326,7 @@ extern "C" sig_handler print_signal_warning(int sig)
#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY
my_sigset(sig,print_signal_warning); /* int. thread system calls */
#endif
-#if !defined(__WIN__) && !defined(__NETWARE__)
+#if !defined(__WIN__)
if (sig == SIGALRM)
alarm(2); /* reschedule alarm */
#endif
@@ -1425,7 +1360,7 @@ void unireg_end(void)
{
clean_up(1);
my_thread_end();
-#if defined(SIGNALS_DONT_BREAK_READ) && !defined(__NETWARE__)
+#if defined(SIGNALS_DONT_BREAK_READ)
exit(0);
#else
pthread_exit(0); // Exit is in main thread
@@ -1523,7 +1458,7 @@ void clean_up(bool print_message)
if (defaults_argv)
free_defaults(defaults_argv);
free_tmpdir(&mysql_tmpdir_list);
- x_free(opt_bin_logname);
+ my_free(opt_bin_logname);
bitmap_free(&temp_pool);
free_max_user_conn();
#ifdef HAVE_REPLICATION
@@ -1579,7 +1514,6 @@ void clean_up(bool print_message)
*/
static void wait_for_signal_thread_to_end()
{
-#ifndef __NETWARE__
uint i;
/*
Wait up to 10 seconds for signal thread to die. We use this mainly to
@@ -1591,7 +1525,6 @@ static void wait_for_signal_thread_to_end()
break;
my_sleep(100); // Give it time to die
}
-#endif
}
@@ -1689,7 +1622,7 @@ static void set_ports()
static struct passwd *check_user(const char *user)
{
-#if !defined(__WIN__) && !defined(__NETWARE__)
+#if !defined(__WIN__)
struct passwd *tmp_user_info;
uid_t user_id= geteuid();
@@ -1754,7 +1687,7 @@ err:
static void set_user(const char *user, struct passwd *user_info_arg)
{
/* purecov: begin tested */
-#if !defined(__WIN__) && !defined(__NETWARE__)
+#if !defined(__WIN__)
DBUG_ASSERT(user_info_arg != 0);
#ifdef HAVE_INITGROUPS
/*
@@ -1784,7 +1717,7 @@ static void set_user(const char *user, struct passwd *user_info_arg)
static void set_effective_user(struct passwd *user_info_arg)
{
-#if !defined(__WIN__) && !defined(__NETWARE__)
+#if !defined(__WIN__)
DBUG_ASSERT(user_info_arg != 0);
if (setregid((gid_t)-1, user_info_arg->pw_gid) == -1)
{
@@ -1803,7 +1736,7 @@ static void set_effective_user(struct passwd *user_info_arg)
/** Change root user if started with @c --chroot . */
static void set_root(const char *path)
{
-#if !defined(__WIN__) && !defined(__NETWARE__)
+#if !defined(__WIN__)
if (chroot(path) == -1)
{
sql_perror("chroot");
@@ -2393,243 +2326,7 @@ static void start_signal_handler(void)
static void check_data_home(const char *path)
{}
-
-#elif defined(__NETWARE__)
-
-/// down server event callback.
-void mysql_down_server_cb(void *, void *)
-{
- event_flag= TRUE;
- kill_server(0);
-}
-
-
-/// destroy callback resources.
-void mysql_cb_destroy(void *)
-{
- UnRegisterEventNotification(eh); // cleanup down event notification
- NX_UNWRAP_INTERFACE(ref);
- /* Deregister NSS volume deactivation event */
- NX_UNWRAP_INTERFACE(refneb);
- if (neb_consumer_id)
- UnRegisterConsumer(neb_consumer_id, NULL);
-}
-
-
-/// initialize callbacks.
-void mysql_cb_init()
-{
- // register for down server event
- void *handle = getnlmhandle();
- rtag_t rt= AllocateResourceTag(handle, "MySQL Down Server Callback",
- EventSignature);
- NX_WRAP_INTERFACE((void *)mysql_down_server_cb, 2, (void **)&ref);
- eh= RegisterForEventNotification(rt, EVENT_PRE_DOWN_SERVER,
- EVENT_PRIORITY_APPLICATION,
- NULL, ref, NULL);
-
- /*
- Register for volume deactivation event
- Wrap the callback function, as it is called by non-LibC thread
- */
- (void *) NX_WRAP_INTERFACE(neb_event_callback, 1, &refneb);
- registerwithneb();
-
- NXVmRegisterExitHandler(mysql_cb_destroy, NULL); // clean-up
-}
-
-
-/** To get the name of the NetWare volume having MySQL data folder. */
-static void getvolumename()
-{
- char *p;
- /*
- We assume that data path is already set.
- If not it won't come here. Terminate after volume name
- */
- if ((p= strchr(mysql_real_data_home, ':')))
- strmake(datavolname, mysql_real_data_home,
- (uint) (p - mysql_real_data_home));
-}
-
-
-/**
- Registering with NEB for NSS Volume Deactivation event.
-*/
-
-static void registerwithneb()
-{
-
- ConsumerRegistrationInfo reg_info;
-
- /* Clear NEB registration structure */
- bzero((char*) &reg_info, sizeof(struct ConsumerRegistrationInfo));
-
- /* Fill the NEB consumer information structure */
- reg_info.CRIVersion= 1; // NEB version
- /* NEB Consumer name */
- reg_info.CRIConsumerName= (BYTE *) "MySQL Database Server";
- /* Event of interest */
- reg_info.CRIEventName= (BYTE *) "NSS.ChangeVolState.Enter";
- reg_info.CRIUserParameter= NULL; // Consumer Info
- reg_info.CRIEventFlags= 0; // Event flags
- /* Consumer NLM handle */
- reg_info.CRIOwnerID= (LoadDefinitionStructure *)getnlmhandle();
- reg_info.CRIConsumerESR= NULL; // No consumer ESR required
- reg_info.CRISecurityToken= 0; // No security token for the event
- reg_info.CRIConsumerFlags= 0; // SMP_ENABLED_BIT;
- reg_info.CRIFilterName= 0; // No event filtering
- reg_info.CRIFilterDataLength= 0; // No filtering data
- reg_info.CRIFilterData= 0; // No filtering data
- /* Callback function for the event */
- (void *)reg_info.CRIConsumerCallback= (void *) refneb;
- reg_info.CRIOrder= 0; // Event callback order
- reg_info.CRIConsumerType= CHECK_CONSUMER; // Consumer type
-
- /* Register for the event with NEB */
- if (RegisterConsumer(&reg_info))
- {
- consoleprintf("Failed to register for NSS Volume Deactivation event \n");
- return;
- }
- /* This ID is required for deregistration */
- neb_consumer_id= reg_info.CRIConsumerID;
-
- /* Get MySQL data volume name, stored in global variable datavolname */
- getvolumename();
-
- /*
- Get the NSS volume ID of the MySQL Data volume.
- Volume ID is stored in a global variable
- */
- getvolumeID((BYTE*) datavolname);
-}
-
-
-/**
- Callback for NSS Volume Deactivation event.
-*/
-
-ulong neb_event_callback(struct EventBlock *eblock)
-{
- EventChangeVolStateEnter_s *voldata;
- extern bool nw_panic;
-
- voldata= (EventChangeVolStateEnter_s *)eblock->EBEventData;
-
- /* Deactivation of a volume */
- if ((voldata->oldState == zVOLSTATE_ACTIVE &&
- voldata->newState == zVOLSTATE_DEACTIVE ||
- voldata->newState == zVOLSTATE_MAINTENANCE))
- {
- /*
- Ensure that we bring down MySQL server only for MySQL data
- volume deactivation
- */
- if (!memcmp(&voldata->volID, &datavolid, sizeof(VolumeID_t)))
- {
- consoleprintf("MySQL data volume is deactivated, shutting down MySQL Server \n");
- event_flag= TRUE;
- nw_panic = TRUE;
- event_flag= TRUE;
- kill_server(0);
- }
- }
- return 0;
-}
-
-
-#define ADMIN_VOL_PATH "_ADMIN:/Volumes/"
-
-/**
- Function to get NSS volume ID of the MySQL data.
-*/
-static void getvolumeID(BYTE *volumeName)
-{
- char path[zMAX_FULL_NAME];
- Key_t rootKey= 0, fileKey= 0;
- QUAD getInfoMask;
- zInfo_s info;
- STATUS status;
-
- /* Get the root key */
- if ((status= zRootKey(0, &rootKey)) != zOK)
- {
- consoleprintf("\nGetNSSVolumeProperties - Failed to get root key, status: %d\n.", (int) status);
- goto exit;
- }
-
- /*
- Get the file key. This is the key to the volume object in the
- NSS admin volumes directory.
- */
-
- strxmov(path, (const char *) ADMIN_VOL_PATH, (const char *) volumeName,
- NullS);
- if ((status= zOpen(rootKey, zNSS_TASK, zNSPACE_LONG|zMODE_UTF8,
- (BYTE *) path, zRR_READ_ACCESS, &fileKey)) != zOK)
- {
- consoleprintf("\nGetNSSVolumeProperties - Failed to get file, status: %d\n.", (int) status);
- goto exit;
- }
-
- getInfoMask= zGET_IDS | zGET_VOLUME_INFO ;
- if ((status= zGetInfo(fileKey, getInfoMask, sizeof(info),
- zINFO_VERSION_A, &info)) != zOK)
- {
- consoleprintf("\nGetNSSVolumeProperties - Failed in zGetInfo, status: %d\n.", (int) status);
- goto exit;
- }
-
- /* Copy the data to global variable */
- datavolid.timeLow= info.vol.volumeID.timeLow;
- datavolid.timeMid= info.vol.volumeID.timeMid;
- datavolid.timeHighAndVersion= info.vol.volumeID.timeHighAndVersion;
- datavolid.clockSeqHighAndReserved= info.vol.volumeID.clockSeqHighAndReserved;
- datavolid.clockSeqLow= info.vol.volumeID.clockSeqLow;
- /* This is guranteed to be 6-byte length (but sizeof() would be better) */
- memcpy(datavolid.node, info.vol.volumeID.node, (unsigned int) 6);
-
-exit:
- if (rootKey)
- zClose(rootKey);
- if (fileKey)
- zClose(fileKey);
-}
-
-
-static void init_signals(void)
-{
- int signals[] = {SIGINT,SIGILL,SIGFPE,SIGSEGV,SIGTERM,SIGABRT};
-
- for (uint i=0 ; i < sizeof(signals)/sizeof(int) ; i++)
- signal(signals[i], kill_server);
- mysql_cb_init(); // initialize callbacks
-
-}
-
-
-static void start_signal_handler(void)
-{
- // Save vm id of this process
- if (!opt_bootstrap)
- create_pid_file();
- // no signal handler
-}
-
-
-/**
- Warn if the data is on a Traditional volume.
-
- @note
- Already done by mysqld_safe
-*/
-
-static void check_data_home(const char *path)
-{
-}
-
-#endif /*__WIN__ || __NETWARE */
+#endif /* __WIN__ */
#ifdef HAVE_LINUXTHREADS
#define UNSAFE_DEFAULT_LINUX_THREADS 200
@@ -2799,7 +2496,7 @@ bugs.\n");
#endif
}
-#if !defined(__WIN__) && !defined(__NETWARE__)
+#if !defined(__WIN__)
#ifndef SA_RESETHAND
#define SA_RESETHAND 0
#endif
@@ -3136,7 +2833,7 @@ void *my_str_malloc_mysqld(size_t size)
void my_str_free_mysqld(void *ptr)
{
- my_free(ptr, MYF(MY_FAE));
+ my_free(ptr);
}
#endif /* EMBEDDED_LIBRARY */
@@ -3709,7 +3406,7 @@ static int init_common_variables()
#define FIX_LOG_VAR(VAR, ALT) \
if (!VAR || !*VAR) \
{ \
- x_free(VAR); /* it could be an allocated empty string "" */ \
+ my_free(VAR); /* it could be an allocated empty string "" */ \
VAR= my_strdup(ALT, MYF(0)); \
}
@@ -4145,7 +3842,7 @@ a file name for --log-bin-index option", opt_binlog_index_name);
}
if (ln == buf)
{
- my_free(opt_bin_logname, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(opt_bin_logname);
opt_bin_logname=my_strdup(buf, MYF(0));
}
if (mysql_bin_log.open_index_file(opt_binlog_index_name, ln, TRUE))
@@ -4323,10 +4020,6 @@ a file name for --log-bin-index option", opt_binlog_index_name);
mysql_bin_log.purge_logs_before_date(purge_time);
}
#endif
-#ifdef __NETWARE__
- /* Increasing stacksize of threads on NetWare */
- pthread_attr_setstacksize(&connection_attrib, NW_THD_STACKSIZE);
-#endif
if (opt_myisam_log)
(void) mi_log(1);
@@ -4715,10 +4408,6 @@ int mysqld_main(int argc, char **argv)
}
}
#endif
-#ifdef __NETWARE__
- /* Increasing stacksize of threads on NetWare */
- pthread_attr_setstacksize(&connection_attrib, NW_THD_STACKSIZE);
-#endif
(void) thr_setconcurrency(concurrency); // 10 by default
@@ -4796,9 +4485,9 @@ int mysqld_main(int argc, char **argv)
{
abort_loop=1;
select_thread_in_use=0;
-#ifndef __NETWARE__
+
(void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
-#endif /* __NETWARE__ */
+
if (!opt_bootstrap)
mysql_file_delete(key_file_pid, pidfile_name, MYF(MY_WME)); // Not needed anymore
@@ -5344,15 +5033,12 @@ static void create_new_thread(THD *thd)
inline void kill_broken_server()
{
/* hack to get around signals ignored in syscalls for problem OS's */
- if (
-#if !defined(__NETWARE__)
- unix_sock == INVALID_SOCKET ||
-#endif
+ if (unix_sock == INVALID_SOCKET ||
(!opt_disable_networking && ip_sock == INVALID_SOCKET))
{
select_thread_in_use = 0;
/* The following call will never return */
- kill_server(IF_NETWARE(MYSQL_KILL_SIGNAL, (void*) MYSQL_KILL_SIGNAL));
+ kill_server((void*) MYSQL_KILL_SIGNAL);
}
}
#define MAYBE_BROKEN_SYSCALL kill_broken_server();
@@ -5486,13 +5172,6 @@ void handle_connections_sockets()
size_socket length= sizeof(struct sockaddr_storage);
new_sock= accept(sock, (struct sockaddr *)(&cAddr),
&length);
-#ifdef __NETWARE__
- // TODO: temporary fix, waiting for TCP/IP fix - DEFECT000303149
- if ((new_sock == INVALID_SOCKET) && (socket_errno == EINVAL))
- {
- kill_server(SIGTERM);
- }
-#endif
if (new_sock != INVALID_SOCKET ||
(socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
break;
@@ -5932,7 +5611,7 @@ errorconn:
/* End shared memory handling */
error:
if (tmp)
- my_free(tmp, MYF(0));
+ my_free(tmp);
if (errmsg)
{
@@ -6232,14 +5911,6 @@ struct my_option my_long_options[]=
"Don't allow new user creation by the user who has no write privileges to the mysql.user table.",
&opt_safe_user_create, &opt_safe_user_create, 0, GET_BOOL,
NO_ARG, 0, 0, 0, 0, 0, 0},
-#if !defined(DBUG_OFF) && defined(SAFEMALLOC)
- {"safemalloc", 0, "Enable the memory allocation checking.",
- &sf_malloc_quick, &sf_malloc_quick, 0,
- GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
- {"safemalloc-mem-limit", 0, "Simulate memory shortage.",
- &sf_malloc_mem_limit, &sf_malloc_mem_limit, 0, GET_UINT,
- REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#endif
{"show-slave-auth-info", 0,
"Show user and password in SHOW SLAVE HOSTS on this master.",
&opt_show_slave_auth_info, &opt_show_slave_auth_info, 0,
@@ -7156,23 +6827,21 @@ static int mysql_init_variables(void)
shared_memory_base_name= default_shared_memory_base_name;
#endif
-#if defined(__WIN__) || defined(__NETWARE__)
- /* Allow Win32 and NetWare users to move MySQL anywhere */
+#if defined(__WIN__)
+ /* Allow Win32 users to move MySQL anywhere */
{
char prg_dev[LIBLEN];
-#if defined __WIN__
- char executing_path_name[LIBLEN];
- if (!test_if_hard_path(my_progname))
- {
- // we don't want to use GetModuleFileName inside of my_path since
- // my_path is a generic path dereferencing function and here we care
- // only about the executing binary.
- GetModuleFileName(NULL, executing_path_name, sizeof(executing_path_name));
- my_path(prg_dev, executing_path_name, NULL);
- }
- else
-#endif
- my_path(prg_dev,my_progname,"mysql/bin");
+ char executing_path_name[LIBLEN];
+ if (!test_if_hard_path(my_progname))
+ {
+ // we don't want to use GetModuleFileName inside of my_path since
+ // my_path is a generic path dereferencing function and here we care
+ // only about the executing binary.
+ GetModuleFileName(NULL, executing_path_name, sizeof(executing_path_name));
+ my_path(prg_dev, executing_path_name, NULL);
+ }
+ else
+ my_path(prg_dev, my_progname, "mysql/bin");
strcat(prg_dev,"/../"); // Remove 'bin' to get base dir
cleanup_dirname(mysql_home,prg_dev);
}
@@ -7590,13 +7259,8 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
}
if (opt_disable_networking)
- {
-#if defined(__NETWARE__)
- sql_print_error("Can't start server: skip-networking option is currently not supported on NetWare");
- return 1;
-#endif
mysqld_port= 0;
- }
+
if (opt_skip_show_db)
opt_specialflag|= SPECIAL_SKIP_SHOW_DB;
@@ -7868,7 +7532,7 @@ static int fix_paths(void)
}
char *secure_file_real_path= (char *)my_malloc(FN_REFLEN, MYF(MY_FAE));
convert_dirname(secure_file_real_path, buff, NullS);
- my_free(opt_secure_file_priv, MYF(0));
+ my_free(opt_secure_file_priv);
opt_secure_file_priv= secure_file_real_path;
}
}
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index 918798529de..6f0b7a817ca 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -44,9 +44,6 @@
#include <signal.h>
#include <errno.h>
#include "probes_mysql.h"
-#ifdef __NETWARE__
-#include <sys/select.h>
-#endif
#ifdef EMBEDDED_LIBRARY
#undef MYSQL_SERVER
@@ -152,7 +149,7 @@ my_bool my_net_init(NET *net, Vio* vio)
void net_end(NET *net)
{
DBUG_ENTER("net_end");
- my_free(net->buff,MYF(MY_ALLOW_ZERO_PTR));
+ my_free(net->buff);
net->buff=0;
DBUG_VOID_RETURN;
}
@@ -696,7 +693,7 @@ net_real_write(NET *net,const uchar *packet, size_t len)
#endif
#ifdef HAVE_COMPRESS
if (net->compress)
- my_free((char*) packet,MYF(0));
+ my_free((void*) packet);
#endif
if (thr_alarm_in_use(&alarmed))
{
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 96dbf39c3aa..af5b4b7c7d6 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -1091,7 +1091,7 @@ SQL_SELECT *make_select(TABLE *head, table_map const_tables,
select->file= *head->sort.io_cache;
select->records=(ha_rows) (select->file.end_of_file/
head->file->ref_length);
- my_free(head->sort.io_cache, MYF(0));
+ my_free(head->sort.io_cache);
head->sort.io_cache=0;
}
DBUG_RETURN(select);
@@ -1216,11 +1216,11 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT()
}
delete_dynamic(&ranges); /* ranges are allocated in alloc */
free_root(&alloc,MYF(0));
- my_free((char*) column_bitmap.bitmap, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(column_bitmap.bitmap);
}
head->column_bitmaps_set(save_read_set, save_write_set);
- x_free(multi_range);
- x_free(multi_range_buff);
+ my_free(multi_range);
+ my_free(multi_range_buff);
DBUG_VOID_RETURN;
}
@@ -1843,96 +1843,6 @@ SEL_ARG *SEL_ARG::clone_tree(RANGE_OPT_PARAM *param)
/*
- Find the best index to retrieve first N records in given order
-
- SYNOPSIS
- get_index_for_order()
- table Table to be accessed
- order Required ordering
- limit Number of records that will be retrieved
-
- DESCRIPTION
- Find the best index that allows to retrieve first #limit records in the
- given order cheaper then one would retrieve them using full table scan.
-
- IMPLEMENTATION
- Run through all table indexes and find the shortest index that allows
- records to be retrieved in given order. We look for the shortest index
- as we will have fewer index pages to read with it.
-
- This function is used only by UPDATE/DELETE, so we take into account how
- the UPDATE/DELETE code will work:
- * index can only be scanned in forward direction
- * HA_EXTRA_KEYREAD will not be used
- Perhaps these assumptions could be relaxed.
-
- RETURN
- Number of the index that produces the required ordering in the cheapest way
- MAX_KEY if no such index was found.
-*/
-
-uint get_index_for_order(TABLE *table, ORDER *order, ha_rows limit)
-{
- uint idx;
- uint match_key= MAX_KEY, match_key_len= MAX_KEY_LENGTH + 1;
- ORDER *ord;
-
- for (ord= order; ord; ord= ord->next)
- if (!ord->asc)
- return MAX_KEY;
-
- for (idx= 0; idx < table->s->keys; idx++)
- {
- if (!(table->keys_in_use_for_query.is_set(idx)))
- continue;
- KEY_PART_INFO *keyinfo= table->key_info[idx].key_part;
- uint n_parts= table->key_info[idx].key_parts;
- uint partno= 0;
-
- /*
- The below check is sufficient considering we now have either BTREE
- indexes (records are returned in order for any index prefix) or HASH
- indexes (records are not returned in order for any index prefix).
- */
- if (!(table->file->index_flags(idx, 0, 1) & HA_READ_ORDER))
- continue;
- for (ord= order; ord && partno < n_parts; ord= ord->next, partno++)
- {
- Item *item= order->item[0];
- if (!(item->type() == Item::FIELD_ITEM &&
- ((Item_field*)item)->field->eq(keyinfo[partno].field)))
- break;
- }
-
- if (!ord && table->key_info[idx].key_length < match_key_len)
- {
- /*
- Ok, the ordering is compatible and this key is shorter then
- previous match (we want shorter keys as we'll have to read fewer
- index pages for the same number of records)
- */
- match_key= idx;
- match_key_len= table->key_info[idx].key_length;
- }
- }
-
- if (match_key != MAX_KEY)
- {
- /*
- Found an index that allows records to be retrieved in the requested
- order. Now we'll check if using the index is cheaper then doing a table
- scan.
- */
- double full_scan_time= table->file->scan_time();
- double index_scan_time= table->file->read_time(match_key, 1, limit);
- if (index_scan_time > full_scan_time)
- match_key= MAX_KEY;
- }
- return match_key;
-}
-
-
-/*
Table rows retrieval plan. Range optimizer creates QUICK_SELECT_I-derived
objects from table read plans.
*/
@@ -8682,7 +8592,7 @@ int QUICK_RANGE_SELECT::reset()
}
if (! multi_range_buff)
{
- my_free((char*) multi_range, MYF(0));
+ my_free(multi_range);
multi_range= NULL;
multi_range_length= 0;
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
@@ -8980,7 +8890,6 @@ QUICK_SELECT_DESC::QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q,
}
rev_it.rewind();
q->dont_free=1; // Don't free shared mem
- delete q;
}
@@ -9070,6 +8979,27 @@ int QUICK_SELECT_DESC::get_next()
}
+/**
+ Create a compatible quick select with the result ordered in an opposite way
+
+ @param used_key_parts_arg Number of used key parts
+
+ @retval NULL in case of errors (OOM etc)
+ @retval pointer to a newly created QUICK_SELECT_DESC if success
+*/
+
+QUICK_SELECT_I *QUICK_RANGE_SELECT::make_reverse(uint used_key_parts_arg)
+{
+ QUICK_SELECT_DESC *new_quick= new QUICK_SELECT_DESC(this, used_key_parts_arg);
+ if (new_quick == NULL || new_quick->error != 0)
+ {
+ delete new_quick;
+ return NULL;
+ }
+ return new_quick;
+}
+
+
/*
Compare if found key is over max-value
Returns 0 if key <= range->max_key
@@ -9643,8 +9573,8 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
first Item? If so, then why? What is the array for?
*/
/* Above we already checked that all group items are fields. */
- DBUG_ASSERT((*tmp_group->item)->type() == Item::FIELD_ITEM);
- Item_field *group_field= (Item_field *) (*tmp_group->item);
+ DBUG_ASSERT((*tmp_group->item)->real_item()->type() == Item::FIELD_ITEM);
+ Item_field *group_field= (Item_field *) (*tmp_group->item)->real_item();
if (group_field->field->eq(cur_part->field))
{
cur_group_prefix_len+= cur_part->store_length;
@@ -11675,6 +11605,7 @@ void QUICK_RANGE_SELECT::dbug_dump(int indent, bool verbose)
/* purecov: end */
}
+
void QUICK_INDEX_MERGE_SELECT::dbug_dump(int indent, bool verbose)
{
List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects);
@@ -11763,7 +11694,7 @@ void QUICK_GROUP_MIN_MAX_SELECT::dbug_dump(int indent, bool verbose)
}
-#endif /* NOT_USED */
+#endif /* !DBUG_OFF */
/*****************************************************************************
** Instantiate templates
diff --git a/sql/opt_range.h b/sql/opt_range.h
index b15833a00e2..0d4000002b0 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -352,6 +352,11 @@ public:
*/
virtual void dbug_dump(int indent, bool verbose)= 0;
#endif
+
+ /*
+ Returns a QUICK_SELECT with reverse order of to the index.
+ */
+ virtual QUICK_SELECT_I *make_reverse(uint used_key_parts_arg) { return NULL; }
};
@@ -437,6 +442,7 @@ public:
#ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose);
#endif
+ QUICK_SELECT_I *make_reverse(uint used_key_parts_arg);
private:
/* Default copy ctor used by QUICK_SELECT_DESC */
};
@@ -783,6 +789,10 @@ public:
int get_next();
bool reverse_sorted() { return 1; }
int get_type() { return QS_TYPE_RANGE_DESC; }
+ QUICK_SELECT_I *make_reverse(uint used_key_parts_arg)
+ {
+ return this; // is already reverse sorted
+ }
private:
bool range_reads_after_key(QUICK_RANGE *range);
int reset(void) { rev_it.rewind(); return QUICK_RANGE_SELECT::reset(); }
@@ -808,6 +818,7 @@ class SQL_SELECT :public Sql_alloc {
SQL_SELECT();
~SQL_SELECT();
void cleanup();
+ void set_quick(QUICK_SELECT_I *new_quick) { delete quick; quick= new_quick; }
bool check_quick(THD *thd, bool force_quick_range, ha_rows limit)
{
key_map tmp;
@@ -834,7 +845,6 @@ public:
QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table,
struct st_table_ref *ref,
ha_rows records);
-uint get_index_for_order(TABLE *table, ORDER *order, ha_rows limit);
SQL_SELECT *make_select(TABLE *head, table_map const_tables,
table_map read_tables, COND *conds,
bool allow_null_cond, int *error);
diff --git a/sql/records.cc b/sql/records.cc
index d85cb49e013..ccacdc33b36 100644
--- a/sql/records.cc
+++ b/sql/records.cc
@@ -42,12 +42,14 @@ static int rr_from_cache(READ_RECORD *info);
static int init_rr_cache(THD *thd, READ_RECORD *info);
static int rr_cmp(uchar *a,uchar *b);
static int rr_index_first(READ_RECORD *info);
+static int rr_index_last(READ_RECORD *info);
static int rr_index(READ_RECORD *info);
+static int rr_index_desc(READ_RECORD *info);
/**
- Initialize READ_RECORD structure to perform full index scan (in forward
- direction) using read_record.read_record() interface.
+ Initialize READ_RECORD structure to perform full index scan in desired
+ direction using read_record.read_record() interface
This function has been added at late stage and is used only by
UPDATE/DELETE. Other statements perform index scans using
@@ -59,10 +61,11 @@ static int rr_index(READ_RECORD *info);
@param print_error If true, call table->file->print_error() if an error
occurs (except for end-of-records error)
@param idx index to scan
+ @param reverse Scan in the reverse direction
*/
void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
- bool print_error, uint idx)
+ bool print_error, uint idx, bool reverse)
{
empty_record(table);
bzero((char*) info,sizeof(*info));
@@ -77,7 +80,7 @@ void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
if (!table->file->inited)
table->file->ha_index_init(idx, 1);
/* read_record will be changed to rr_index in rr_index_first */
- info->read_record= rr_index_first;
+ info->read_record= reverse ? rr_index_last : rr_index_first;
}
@@ -290,7 +293,7 @@ void end_read_record(READ_RECORD *info)
{ /* free cache if used */
if (info->cache)
{
- my_free_lock((char*) info->cache,MYF(0));
+ my_free_lock(info->cache);
info->cache=0;
}
if (info->table)
@@ -365,6 +368,29 @@ static int rr_index_first(READ_RECORD *info)
/**
+ Reads last row in an index scan.
+
+ @param info Scan info
+
+ @retval
+ 0 Ok
+ @retval
+ -1 End of records
+ @retval
+ 1 Error
+*/
+
+static int rr_index_last(READ_RECORD *info)
+{
+ int tmp= info->file->index_last(info->record);
+ info->read_record= rr_index_desc;
+ if (tmp)
+ tmp= rr_handle_error(info, tmp);
+ return tmp;
+}
+
+
+/**
Reads index sequentially after first row.
Read the next index record (in forward direction) and translate return
@@ -389,6 +415,31 @@ static int rr_index(READ_RECORD *info)
}
+/**
+ Reads index sequentially from the last row to the first.
+
+ Read the prev index record (in backward direction) and translate return
+ value.
+
+ @param info Scan info
+
+ @retval
+ 0 Ok
+ @retval
+ -1 End of records
+ @retval
+ 1 Error
+*/
+
+static int rr_index_desc(READ_RECORD *info)
+{
+ int tmp= info->file->index_prev(info->record);
+ if (tmp)
+ tmp= rr_handle_error(info, tmp);
+ return tmp;
+}
+
+
int rr_sequential(READ_RECORD *info)
{
int tmp;
diff --git a/sql/records.h b/sql/records.h
index ae81a31ee1a..95464a11b4b 100644
--- a/sql/records.h
+++ b/sql/records.h
@@ -71,7 +71,7 @@ void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
SQL_SELECT *select, int use_record_cache,
bool print_errors, bool disable_rr_cache);
void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
- bool print_error, uint idx);
+ bool print_error, uint idx, bool reverse);
void end_read_record(READ_RECORD *info);
void rr_unlock_row(st_join_table *tab);
diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc
index 81366d55fc6..9a1f7fb826b 100644
--- a/sql/repl_failsafe.cc
+++ b/sql/repl_failsafe.cc
@@ -205,7 +205,7 @@ int register_slave(THD* thd, uchar* packet, uint packet_length)
return res;
err:
- my_free(si, MYF(MY_WME));
+ my_free(si);
my_message(ER_UNKNOWN_ERROR, errmsg, MYF(0)); /* purecov: inspected */
err2:
return 1;
@@ -221,7 +221,7 @@ extern "C" uint32
extern "C" void slave_info_free(void *s)
{
- my_free(s, MYF(MY_WME));
+ my_free(s);
}
#ifdef HAVE_PSI_INTERFACE
diff --git a/sql/rpl_filter.cc b/sql/rpl_filter.cc
index 63521c0398f..42a9a034efd 100644
--- a/sql/rpl_filter.cc
+++ b/sql/rpl_filter.cc
@@ -383,7 +383,7 @@ void free_table_ent(void* a)
{
TABLE_RULE_ENT *e= (TABLE_RULE_ENT *) a;
- my_free((uchar*) e, MYF(0));
+ my_free(e);
}
@@ -434,7 +434,7 @@ Rpl_filter::free_string_array(DYNAMIC_ARRAY *a)
{
char* p;
get_dynamic(a, (uchar*) &p, i);
- my_free(p, MYF(MY_WME));
+ my_free(p);
}
delete_dynamic(a);
}
diff --git a/sql/rpl_handler.cc b/sql/rpl_handler.cc
index a7b963d186c..5d2a3f61b1e 100644
--- a/sql/rpl_handler.cc
+++ b/sql/rpl_handler.cc
@@ -216,7 +216,7 @@ int Trans_delegate::after_commit(THD *thd, bool all)
if (is_real_trans && log_info)
{
my_pthread_setspecific_ptr(RPL_TRANS_BINLOG_INFO, NULL);
- my_free(log_info, MYF(0));
+ my_free(log_info);
}
return ret;
}
@@ -244,7 +244,7 @@ int Trans_delegate::after_rollback(THD *thd, bool all)
if (is_real_trans && log_info)
{
my_pthread_setspecific_ptr(RPL_TRANS_BINLOG_INFO, NULL);
- my_free(log_info, MYF(0));
+ my_free(log_info);
}
return ret;
}
diff --git a/sql/rpl_injector.cc b/sql/rpl_injector.cc
index 0f636f5b2ab..75ccb617e9e 100644
--- a/sql/rpl_injector.cc
+++ b/sql/rpl_injector.cc
@@ -58,7 +58,7 @@ injector::transaction::~transaction()
*/
*the_memory= '\0';
- my_free(the_memory, MYF(0));
+ my_free(the_memory);
}
/**
diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc
index a775d3485c9..cda876ee764 100644
--- a/sql/rpl_mi.cc
+++ b/sql/rpl_mi.cc
@@ -164,7 +164,29 @@ int init_master_info(Master_info* mi, const char* master_info_fname,
*/
if (thread_mask & SLAVE_SQL)
{
+ bool hot_log= FALSE;
+ /*
+ my_b_seek does an implicit flush_io_cache, so we need to:
+
+ 1. check if this log is active (hot)
+ 2. if it is we keep log_lock until the seek ends, otherwise
+ release it right away.
+
+ If we did not take log_lock, SQL thread might race with IO
+ thread for the IO_CACHE mutex.
+
+ */
+ mysql_mutex_t *log_lock= mi->rli.relay_log.get_log_lock();
+ mysql_mutex_lock(log_lock);
+ hot_log= mi->rli.relay_log.is_active(mi->rli.linfo.log_file_name);
+
+ if (!hot_log)
+ mysql_mutex_unlock(log_lock);
+
my_b_seek(mi->rli.cur_log, (my_off_t) 0);
+
+ if (hot_log)
+ mysql_mutex_unlock(log_lock);
}
DBUG_RETURN(0);
}
@@ -495,7 +517,7 @@ int flush_master_info(Master_info* mi,
(int)(mi->ssl), mi->ssl_ca, mi->ssl_capath, mi->ssl_cert,
mi->ssl_cipher, mi->ssl_key, mi->ssl_verify_server_cert,
heartbeat_buf, "", ignore_server_ids_buf);
- my_free(ignore_server_ids_buf, MYF(0));
+ my_free(ignore_server_ids_buf);
err= flush_io_cache(file);
if (sync_masterinfo_period && !err &&
++(mi->sync_counter) >= sync_masterinfo_period)
diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc
index c1139599241..03c369394bf 100644
--- a/sql/rpl_rli.cc
+++ b/sql/rpl_rli.cc
@@ -1250,7 +1250,7 @@ void Relay_log_info::clear_tables_to_lock()
tables_to_lock=
static_cast<RPL_TABLE_LIST*>(tables_to_lock->next_global);
tables_to_lock_count--;
- my_free(to_free, MYF(MY_WME));
+ my_free(to_free);
}
DBUG_ASSERT(tables_to_lock == NULL && tables_to_lock_count == 0);
}
diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc
index 7479e58fd98..6f66905eb5d 100644
--- a/sql/rpl_utility.cc
+++ b/sql/rpl_utility.cc
@@ -1049,7 +1049,7 @@ table_def::table_def(unsigned char *types, ulong size,
table_def::~table_def()
{
- my_free(m_memory, MYF(0));
+ my_free(m_memory);
#ifndef DBUG_OFF
m_type= 0;
m_size= 0;
diff --git a/sql/slave.cc b/sql/slave.cc
index 383627a7fd1..d41d0479dde 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -1154,7 +1154,7 @@ int init_dynarray_intvar_from_file(DYNAMIC_ARRAY* arr, IO_CACHE* f)
}
err:
if (buf_act != buf)
- my_free(buf_act, MYF(0));
+ my_free(buf_act);
DBUG_RETURN(ret);
}
@@ -3686,7 +3686,7 @@ static int queue_binlog_ver_1_event(Master_info *mi, const char *buf,
sql_print_error("Read invalid event from master: '%s',\
master could be corrupt but a more likely cause of this is a bug",
errmsg);
- my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(tmp_buf);
DBUG_RETURN(1);
}
@@ -3723,7 +3723,7 @@ static int queue_binlog_ver_1_event(Master_info *mi, const char *buf,
mi->master_log_pos += inc_pos;
DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos));
mysql_mutex_unlock(&mi->data_lock);
- my_free((char*)tmp_buf, MYF(0));
+ my_free(tmp_buf);
DBUG_RETURN(error);
}
default:
@@ -3774,7 +3774,7 @@ static int queue_binlog_ver_3_event(Master_info *mi, const char *buf,
sql_print_error("Read invalid event from master: '%s',\
master could be corrupt but a more likely cause of this is a bug",
errmsg);
- my_free((char*) tmp_buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(tmp_buf);
DBUG_RETURN(1);
}
mysql_mutex_lock(&mi->data_lock);
diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc
index 74dda9f456b..bbf38f52efb 100644
--- a/sql/sp_pcontext.cc
+++ b/sql/sp_pcontext.cc
@@ -19,10 +19,6 @@
#pragma implementation
#endif
-#if defined(WIN32) || defined(__WIN__)
-#undef SAFEMALLOC /* Problems with threads */
-#endif
-
#include "sp_pcontext.h"
#include "sp_head.h"
diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc
index e3cdf328659..047cec76486 100644
--- a/sql/sp_rcontext.cc
+++ b/sql/sp_rcontext.cc
@@ -19,10 +19,6 @@
#pragma implementation
#endif
-#if defined(WIN32) || defined(__WIN__)
-#undef SAFEMALLOC /* Problems with threads */
-#endif
-
#include "mysql.h"
#include "sp_head.h"
#include "sql_cursor.h"
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 47aebc37241..f746edef83f 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -885,7 +885,7 @@ static void free_cache_entry(TABLE *table)
intern_close_table(table);
- my_free((uchar*) table,MYF(0));
+ my_free(table);
DBUG_VOID_RETURN;
}
@@ -897,7 +897,7 @@ void free_io_cache(TABLE *table)
if (table->sort.io_cache)
{
close_cached_file(table->sort.io_cache);
- my_free((uchar*) table->sort.io_cache,MYF(0));
+ my_free(table->sort.io_cache);
table->sort.io_cache=0;
}
DBUG_VOID_RETURN;
@@ -1636,6 +1636,7 @@ static inline uint tmpkeyval(THD *thd, TABLE *table)
void close_temporary_tables(THD *thd)
{
+ DBUG_ENTER("close_temporary_tables");
TABLE *table;
TABLE *next= NULL;
TABLE *prev_table;
@@ -1643,10 +1644,9 @@ void close_temporary_tables(THD *thd)
bool was_quote_show= TRUE;
if (!thd->temporary_tables)
- return;
+ DBUG_VOID_RETURN;
- if (!mysql_bin_log.is_open() ||
- (thd->is_current_stmt_binlog_format_row() && thd->variables.binlog_format == BINLOG_FORMAT_ROW))
+ if (!mysql_bin_log.is_open())
{
TABLE *tmp_next;
for (table= thd->temporary_tables; table; table= tmp_next)
@@ -1655,7 +1655,7 @@ void close_temporary_tables(THD *thd)
close_temporary(table, 1, 1);
}
thd->temporary_tables= 0;
- return;
+ DBUG_VOID_RETURN;
}
/* Better add "if exists", in case a RESET MASTER has been done */
@@ -1771,6 +1771,7 @@ void close_temporary_tables(THD *thd)
if (!was_quote_show)
thd->variables.option_bits&= ~OPTION_QUOTE_SHOW_CREATE; /* restore option */
thd->temporary_tables=0;
+ DBUG_VOID_RETURN;
}
/*
@@ -2135,7 +2136,7 @@ void close_temporary(TABLE *table, bool free_share, bool delete_table)
if (free_share)
{
free_table_share(table->s);
- my_free((char*) table,MYF(0));
+ my_free(table);
}
DBUG_VOID_RETURN;
}
@@ -3017,7 +3018,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
if (error)
{
- my_free(table, MYF(0));
+ my_free(table);
if (error == 7)
(void) ot_ctx->request_backoff_action(Open_table_context::OT_DISCOVER,
@@ -3032,7 +3033,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
if (open_table_entry_fini(thd, share, table))
{
closefrm(table, 0);
- my_free((uchar*)table, MYF(0));
+ my_free(table);
goto err_lock;
}
@@ -3778,10 +3779,10 @@ static bool open_table_entry_fini(THD *thd, TABLE_SHARE *share, TABLE *entry)
query, (ulong)(end-query),
FALSE, FALSE, FALSE, errcode))
{
- my_free(query, MYF(0));
+ my_free(query);
return TRUE;
}
- my_free(query, MYF(0));
+ my_free(query);
}
else
{
@@ -3866,7 +3867,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list)
closefrm(entry, 0);
result= FALSE;
}
- my_free(entry, MYF(0));
+ my_free(entry);
mysql_mutex_lock(&LOCK_open);
release_table_share(share);
@@ -5750,7 +5751,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
{
/* No need to lock share->mutex as this is not needed for tmp tables */
free_table_share(share);
- my_free((char*) tmp_table,MYF(0));
+ my_free(tmp_table);
DBUG_RETURN(0);
}
diff --git a/sql/sql_binlog.cc b/sql/sql_binlog.cc
index e5ac1a3f1af..6f59c3f51e1 100644
--- a/sql/sql_binlog.cc
+++ b/sql/sql_binlog.cc
@@ -247,6 +247,6 @@ void mysql_client_binlog_statement(THD* thd)
end:
rli->slave_close_thread_tables(thd);
- my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(buf);
DBUG_VOID_RETURN;
}
diff --git a/sql/sql_bitmap.h b/sql/sql_bitmap.h
index 8d00c984d14..54a207c8adf 100644
--- a/sql/sql_bitmap.h
+++ b/sql/sql_bitmap.h
@@ -102,16 +102,7 @@ template <> class Bitmap<64>
ulonglong map;
public:
Bitmap<64>() { }
-#if defined(__NETWARE__) || defined(__MWERKS__)
- /*
- Metwork compiler gives error on Bitmap<64>
- Changed to Bitmap, since in this case also it will proper construct
- this class
- */
- explicit Bitmap(uint prefix_to_set) { set_prefix(prefix_to_set); }
-#else
explicit Bitmap<64>(uint prefix_to_set) { set_prefix(prefix_to_set); }
-#endif
void init() { }
void init(uint prefix_to_set) { set_prefix(prefix_to_set); }
uint length() const { return 64; }
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 92d54c8e71b..b73de320ef5 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -2223,7 +2223,7 @@ void Query_cache::free_cache()
{
DBUG_ENTER("Query_cache::free_cache");
- my_free((uchar*) cache, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(cache);
make_disabled();
my_hash_free(&queries);
my_hash_free(&tables);
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index b1e416257ec..eb4d353db81 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -100,8 +100,8 @@ extern "C" void free_user_var(user_var_entry *entry)
{
char *pos= (char*) entry+ALIGN_SIZE(sizeof(*entry));
if (entry->value && entry->value != pos)
- my_free(entry->value, MYF(0));
- my_free((char*) entry,MYF(0));
+ my_free(entry->value);
+ my_free(entry);
}
bool Key_part_spec::operator==(const Key_part_spec& other) const
@@ -493,7 +493,9 @@ THD::THD()
rli_fake(0),
lock_id(&main_lock_id),
user_time(0), in_sub_stmt(0),
- binlog_unsafe_warning_flags(0), binlog_table_maps(0),
+ binlog_unsafe_warning_flags(0),
+ stmt_accessed_table_flag(0),
+ binlog_table_maps(0),
table_map_for_update(0),
arg_of_last_insert_id_function(FALSE),
first_successful_insert_id_in_prev_stmt(0),
@@ -537,7 +539,7 @@ THD::THD()
count_cuted_fields= CHECK_FIELD_IGNORE;
killed= NOT_KILLED;
col_access=0;
- is_slave_error= thread_specific_used= thread_temporary_used= FALSE;
+ is_slave_error= thread_specific_used= FALSE;
my_hash_clear(&handler_tables_hash);
tmp_table=0;
used_tables=0;
@@ -1123,7 +1125,8 @@ THD::~THD()
DBUG_PRINT("info", ("freeing security context"));
main_security_ctx.destroy();
- safeFree(db);
+ my_free(db);
+ db= NULL;
free_root(&transaction.mem_root,MYF(0));
mysys_var=0; // Safety (shouldn't be needed)
mysql_mutex_destroy(&LOCK_thd_data);
@@ -2962,10 +2965,18 @@ void Security_context::destroy()
{
// If not pointer to constant
if (host != my_localhost)
- safeFree(host);
+ {
+ my_free(host);
+ host= NULL;
+ }
if (user != delayed_user)
- safeFree(user);
- safeFree(ip);
+ {
+ my_free(user);
+ user= NULL;
+ }
+
+ my_free(ip);
+ ip= NULL;
}
@@ -2981,7 +2992,7 @@ void Security_context::skip_grants()
bool Security_context::set_user(char *user_arg)
{
- safeFree(user);
+ my_free(user);
user= my_strdup(user_arg, MYF(0));
return user == 0;
}
@@ -3473,7 +3484,7 @@ uchar *xid_get_hash_key(const uchar *ptr, size_t *length,
void xid_free_hash(void *ptr)
{
if (!((XID_STATE*)ptr)->in_thd)
- my_free((uchar*)ptr, MYF(0));
+ my_free(ptr);
}
#ifdef HAVE_PSI_INTERFACE
@@ -3689,7 +3700,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
capabilities.
*/
handler::Table_flags flags_write_some_set= 0;
- handler::Table_flags flags_some_set= 0;
+ handler::Table_flags flags_access_some_set= 0;
handler::Table_flags flags_write_all_set=
HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE;
@@ -3704,17 +3715,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
Innodb and Falcon; Innodb and MyIsam.
*/
my_bool multi_access_engine= FALSE;
- /*
- If non-transactional and transactional engines are about
- to be accessed and any of them is about to be updated.
- For example: Innodb and MyIsam.
- */
- my_bool trans_non_trans_access_engines= FALSE;
- /*
- If all engines that are about to be updated are
- transactional.
- */
- my_bool all_trans_write_engines= TRUE;
+
TABLE* prev_write_table= NULL;
TABLE* prev_access_table= NULL;
@@ -3738,9 +3739,12 @@ int THD::decide_logging_format(TABLE_LIST *tables)
{
if (table->placeholder())
continue;
+
if (table->table->s->table_category == TABLE_CATEGORY_PERFORMANCE)
lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_TABLE);
+
handler::Table_flags const flags= table->table->file->ha_table_flags();
+
DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx",
table->table_name, flags));
if (table->lock_type >= TL_WRITE_ALLOW_WRITE)
@@ -3748,177 +3752,171 @@ int THD::decide_logging_format(TABLE_LIST *tables)
if (prev_write_table && prev_write_table->file->ht !=
table->table->file->ht)
multi_write_engine= TRUE;
- /*
- Every temporary table must be always written to the binary
- log in transaction boundaries and as such we artificially
- classify them as transactional.
- Indirectly, this avoids classifying a temporary table created
- on a non-transactional engine as unsafe when it is modified
- after any transactional table:
+ my_bool trans= table->table->file->has_transactions();
- BEGIN;
- INSERT INTO innodb_t VALUES (1);
- INSERT INTO myisam_t_temp VALUES (1);
- COMMIT;
-
- BINARY LOG:
+ if (table->table->s->tmp_table)
+ set_stmt_accessed_table(trans ? STMT_WRITES_TEMP_TRANS_TABLE :
+ STMT_WRITES_TEMP_NON_TRANS_TABLE);
+ else
+ set_stmt_accessed_table(trans ? STMT_WRITES_TRANS_TABLE :
+ STMT_WRITES_NON_TRANS_TABLE);
- BEGIN;
- INSERT INTO innodb_t VALUES (1);
- INSERT INTO myisam_t_temp VALUES (1);
- COMMIT;
- */
- all_trans_write_engines= all_trans_write_engines &&
- (table->table->file->has_transactions() ||
- table->table->s->tmp_table);
- prev_write_table= table->table;
flags_write_all_set &= flags;
flags_write_some_set |= flags;
- }
- flags_some_set |= flags;
- /*
- The mixture of non-transactional and transactional tables must
- identified and classified as unsafe. However, a temporary table
- must be always handled as a transactional table. Based on that,
- we have the following statements classified as mixed and by
- consequence as unsafe:
-
- 1: INSERT INTO myisam_t SELECT * FROM innodb_t;
-
- 2: INSERT INTO innodb_t SELECT * FROM myisam_t;
-
- 3: INSERT INTO myisam_t SELECT * FROM myisam_t_temp;
-
- 4: INSERT INTO myisam_t_temp SELECT * FROM myisam_t;
- 5: CREATE TEMPORARY TABLE myisam_t_temp SELECT * FROM mysiam_t;
-
- The following statements are not considered mixed and as such
- are safe:
-
- 1: INSERT INTO innodb_t SELECT * FROM myisam_t_temp;
+ prev_write_table= table->table;
+ }
+ flags_access_some_set |= flags;
- 2: INSERT INTO myisam_t_temp SELECT * FROM innodb_t_temp;
- */
- if (!trans_non_trans_access_engines && prev_access_table &&
- (lex->sql_command != SQLCOM_CREATE_TABLE ||
+ if (lex->sql_command != SQLCOM_CREATE_TABLE ||
(lex->sql_command == SQLCOM_CREATE_TABLE &&
- (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))))
+ (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)))
{
- my_bool prev_trans;
- my_bool act_trans;
- if (prev_access_table->s->tmp_table || table->table->s->tmp_table)
- {
- prev_trans= prev_access_table->s->tmp_table ? TRUE :
- prev_access_table->file->has_transactions();
- act_trans= table->table->s->tmp_table ? TRUE :
- table->table->file->has_transactions();
- }
+ my_bool trans= table->table->file->has_transactions();
+
+ if (table->table->s->tmp_table)
+ set_stmt_accessed_table(trans ? STMT_READS_TEMP_TRANS_TABLE :
+ STMT_READS_TEMP_NON_TRANS_TABLE);
else
- {
- prev_trans= prev_access_table->file->has_transactions();
- act_trans= table->table->file->has_transactions();
- }
- trans_non_trans_access_engines= (prev_trans != act_trans);
- multi_access_engine= TRUE;
+ set_stmt_accessed_table(trans ? STMT_READS_TRANS_TABLE :
+ STMT_READS_NON_TRANS_TABLE);
}
- thread_temporary_used |= table->table->s->tmp_table;
+
+ if (prev_access_table && prev_access_table->file->ht !=
+ table->table->file->ht)
+ multi_access_engine= TRUE;
+
prev_access_table= table->table;
}
DBUG_PRINT("info", ("flags_write_all_set: 0x%llx", flags_write_all_set));
DBUG_PRINT("info", ("flags_write_some_set: 0x%llx", flags_write_some_set));
- DBUG_PRINT("info", ("flags_some_set: 0x%llx", flags_some_set));
+ DBUG_PRINT("info", ("flags_access_some_set: 0x%llx", flags_access_some_set));
DBUG_PRINT("info", ("multi_write_engine: %d", multi_write_engine));
DBUG_PRINT("info", ("multi_access_engine: %d", multi_access_engine));
- DBUG_PRINT("info", ("trans_non_trans_access_engines: %d",
- trans_non_trans_access_engines));
int error= 0;
int unsafe_flags;
/*
- Set the statement as unsafe if:
-
- . it is a mixed statement, i.e. access transactional and non-transactional
- tables, and update any of them;
-
- or:
-
- . an early statement updated a transactional table;
- . and, the current statement updates a non-transactional table.
-
- Any mixed statement is classified as unsafe to ensure that mixed mode is
- completely safe. Consider the following example to understand why we
- decided to do this:
-
- Note that mixed statements such as
-
- 1: INSERT INTO myisam_t SELECT * FROM innodb_t;
-
- 2: INSERT INTO innodb_t SELECT * FROM myisam_t;
-
- 3: INSERT INTO myisam_t SELECT * FROM myisam_t_temp;
-
- 4: INSERT INTO myisam_t_temp SELECT * FROM myisam_t;
-
- 5: CREATE TEMPORARY TABLE myisam_t_temp SELECT * FROM mysiam_t;
+ Classify a statement as unsafe when there is a mixed statement and an
+ on-going transaction at any point of the execution if:
- are classified as unsafe to ensure that in mixed mode the execution is
- completely safe and equivalent to the row mode. Consider the following
- statements and sessions (connections) to understand the reason:
+ 1. The mixed statement is about to update a transactional table and
+ a non-transactional table.
- con1: INSERT INTO innodb_t VALUES (1);
- con1: INSERT INTO innodb_t VALUES (100);
+ 2. The mixed statement is about to update a temporary transactional
+ table and a non-transactional table.
+
+ 3. The mixed statement is about to update a transactional table and
+ read from a non-transactional table.
- con1: BEGIN
- con2: INSERT INTO myisam_t SELECT * FROM innodb_t;
- con1: INSERT INTO innodb_t VALUES (200);
- con1: COMMIT;
+ 4. The mixed statement is about to update a temporary transactional
+ table and read from a non-transactional table.
- The point is that the concurrent statements may be written into the binary log
- in a way different from the execution. For example,
+ 5. The mixed statement is about to update a non-transactional table
+ and read from a transactional table when the isolation level is
+ lower than repeatable read.
- BINARY LOG:
+ After updating a transactional table if:
- con2: BEGIN;
- con2: INSERT INTO myisam_t SELECT * FROM innodb_t;
- con2: COMMIT;
- con1: BEGIN
- con1: INSERT INTO innodb_t VALUES (200);
- con1: COMMIT;
-
- ....
-
- or
-
- BINARY LOG:
-
- con1: BEGIN
- con1: INSERT INTO innodb_t VALUES (200);
- con1: COMMIT;
- con2: BEGIN;
- con2: INSERT INTO myisam_t SELECT * FROM innodb_t;
- con2: COMMIT;
-
- Clearly, this may become a problem in STMT mode and setting the statement
- as unsafe will make rows to be written into the binary log in MIXED mode
- and as such the problem will not stand.
-
- In STMT mode, although such statement is classified as unsafe, i.e.
+ 6. The mixed statement is about to update a non-transactional table
+ and read from a temporary transactional table.
+
+ 7. The mixed statement is about to update a non-transactional table
+ and read from a temporary transactional table.
+
+ 8. The mixed statement is about to update a non-transactionala table
+ and read from a temporary non-transactional table.
+
+ 9. The mixed statement is about to update a temporary non-transactional
+ table and update a non-transactional table.
+
+ 10. The mixed statement is about to update a temporary non-transactional
+ table and read from a non-transactional table.
+
+ 11. A statement is about to update a non-transactional table and the
+ option variables.binlog_direct_non_trans_update is OFF.
+
+ The reason for this is that locks acquired may not protected a concurrent
+ transaction of interfering in the current execution and by consequence in
+ the result. In particular, if there is an on-going transaction and a
+ transactional table was already updated, a temporary table must be written
+ to the binary log in the boundaries of the on-going transaction and as
+ such we artificially classify them as transactional.
+ */
+ if (in_multi_stmt_transaction_mode())
+ {
+ my_bool mixed_unsafe= FALSE;
+ my_bool non_trans_unsafe= FALSE;
+
+ /* Case 1. */
+ if (stmt_accessed_table(STMT_WRITES_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_WRITES_NON_TRANS_TABLE))
+ mixed_unsafe= TRUE;
+ /* Case 2. */
+ else if (stmt_accessed_table(STMT_WRITES_TEMP_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_WRITES_NON_TRANS_TABLE))
+ mixed_unsafe= TRUE;
+ /* Case 3. */
+ else if (stmt_accessed_table(STMT_WRITES_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_READS_NON_TRANS_TABLE))
+ mixed_unsafe= TRUE;
+ /* Case 4. */
+ else if (stmt_accessed_table(STMT_WRITES_TEMP_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_READS_NON_TRANS_TABLE))
+ mixed_unsafe= TRUE;
+ /* Case 5. */
+ else if (stmt_accessed_table(STMT_WRITES_NON_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_READS_TRANS_TABLE) &&
+ tx_isolation < ISO_REPEATABLE_READ)
+ /*
+ By default, InnoDB operates in REPEATABLE READ and with the option
+ --innodb-locks-unsafe-for-binlog disabled. In this case, InnoDB uses
+ next-key locks for searches and index scans, which prevents phantom
+ rows.
+
+ This is scenario is safe for Innodb. However, there are no means to
+ transparently get this information. Therefore, we need to improve this
+ and change the storage engines to report somehow when an execution is
+ safe under an isolation level & binary logging format.
+ */
+ mixed_unsafe= TRUE;
- INSERT INTO myisam_t SELECT * FROM innodb_t;
+ if (trans_has_updated_trans_table(this))
+ {
+ /* Case 6. */
+ if (stmt_accessed_table(STMT_WRITES_NON_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_READS_TRANS_TABLE))
+ mixed_unsafe= TRUE;
+ /* Case 7. */
+ else if (stmt_accessed_table(STMT_WRITES_NON_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_READS_TEMP_TRANS_TABLE))
+ mixed_unsafe= TRUE;
+ /* Case 8. */
+ else if (stmt_accessed_table(STMT_WRITES_NON_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_READS_TEMP_NON_TRANS_TABLE))
+ mixed_unsafe= TRUE;
+ /* Case 9. */
+ else if (stmt_accessed_table(STMT_WRITES_TEMP_NON_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_WRITES_NON_TRANS_TABLE))
+ mixed_unsafe= TRUE;
+ /* Case 10. */
+ else if (stmt_accessed_table(STMT_WRITES_TEMP_NON_TRANS_TABLE) &&
+ stmt_accessed_table(STMT_READS_NON_TRANS_TABLE))
+ mixed_unsafe= TRUE;
+ /* Case 11. */
+ else if (!variables.binlog_direct_non_trans_update &&
+ stmt_accessed_table(STMT_WRITES_NON_TRANS_TABLE))
+ non_trans_unsafe= TRUE;
+ }
- there is no enough information to avoid writing it outside the boundaries
- of a transaction. This is not a problem if we are considering snapshot
- isolation level but if we have pure repeatable read or serializable the
- lock history on the slave will be different from the master.
- */
- if (trans_non_trans_access_engines)
- lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_MIXED_STATEMENT);
- else if (trans_has_updated_trans_table(this) && !all_trans_write_engines)
- lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS);
+ if (mixed_unsafe)
+ lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_MIXED_STATEMENT);
+ else if (non_trans_unsafe)
+ lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS);
+ }
/*
If more than one engine is involved in the statement and at
@@ -3930,7 +3928,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
(flags_write_some_set & HA_HAS_OWN_BINLOGGING))
my_error((error= ER_BINLOG_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE),
MYF(0));
- else if (multi_access_engine && flags_some_set & HA_HAS_OWN_BINLOGGING)
+ else if (multi_access_engine && flags_access_some_set & HA_HAS_OWN_BINLOGGING)
lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE);
/* both statement-only and row-only engines involved */
@@ -4293,7 +4291,7 @@ CPP_UNNAMED_NS_START
~Row_data_memory()
{
if (m_memory != 0 && m_release_memory_on_destruction)
- my_free((uchar*) m_memory, MYF(MY_WME));
+ my_free(m_memory);
}
/**
diff --git a/sql/sql_class.h b/sql/sql_class.h
index d90279454ee..c095fee6232 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1570,6 +1570,125 @@ public:
return current_stmt_binlog_format == BINLOG_FORMAT_ROW;
}
+ enum enum_stmt_accessed_table
+ {
+ /*
+ If a transactional table is about to be read. Note that
+ a write implies a read.
+ */
+ STMT_READS_TRANS_TABLE= 0,
+ /*
+ If a transactional table is about to be updated.
+ */
+ STMT_WRITES_TRANS_TABLE,
+ /*
+ If a non-transactional table is about to be read. Note that
+ a write implies a read.
+ */
+ STMT_READS_NON_TRANS_TABLE,
+ /*
+ If a non-transactional table is about to be updated.
+ */
+ STMT_WRITES_NON_TRANS_TABLE,
+ /*
+ If a temporary transactional table is about to be read. Note
+ that a write implies a read.
+ */
+ STMT_READS_TEMP_TRANS_TABLE,
+ /*
+ If a temporary transactional table is about to be updated.
+ */
+ STMT_WRITES_TEMP_TRANS_TABLE,
+ /*
+ If a temporary non-transactional table is about to be read. Note
+ that a write implies a read.
+ */
+ STMT_READS_TEMP_NON_TRANS_TABLE,
+ /*
+ If a temporary non-transactional table is about to be updated.
+ */
+ STMT_WRITES_TEMP_NON_TRANS_TABLE,
+ /*
+ The last element of the enumeration. Please, if necessary add
+ anything before this.
+ */
+ STMT_ACCESS_TABLE_COUNT
+ };
+
+ /**
+ Sets the type of table that is about to be accessed while executing a
+ statement.
+
+ @param accessed_table Enumeration type that defines the type of table,
+ e.g. temporary, transactional, non-transactional.
+ */
+ inline void set_stmt_accessed_table(enum_stmt_accessed_table accessed_table)
+ {
+ DBUG_ENTER("THD::set_stmt_accessed_table");
+
+ DBUG_ASSERT(accessed_table >= 0 && accessed_table < STMT_ACCESS_TABLE_COUNT);
+ stmt_accessed_table_flag |= (1U << accessed_table);
+
+ DBUG_VOID_RETURN;
+ }
+
+ /**
+ Checks if a type of table is about to be accessed while executing a
+ statement.
+
+ @param accessed_table Enumeration type that defines the type of table,
+ e.g. temporary, transactional, non-transactional.
+
+ @return
+ @retval TRUE if the type of the table is about to be accessed
+ @retval FALSE otherwise
+ */
+ inline bool stmt_accessed_table(enum_stmt_accessed_table accessed_table)
+ {
+ DBUG_ENTER("THD::stmt_accessed_table");
+
+ DBUG_ASSERT(accessed_table >= 0 && accessed_table < STMT_ACCESS_TABLE_COUNT);
+
+ DBUG_RETURN((stmt_accessed_table_flag & (1U << accessed_table)) != 0);
+ }
+
+ /**
+ Checks if a temporary table is about to be accessed while executing a
+ statement.
+
+ @return
+ @retval TRUE if a temporary table is about to be accessed
+ @retval FALSE otherwise
+ */
+ inline bool stmt_accessed_temp_table()
+ {
+ DBUG_ENTER("THD::stmt_accessed_temp_table");
+
+ DBUG_RETURN((stmt_accessed_table_flag &
+ ((1U << STMT_READS_TEMP_TRANS_TABLE) |
+ (1U << STMT_WRITES_TEMP_TRANS_TABLE) |
+ (1U << STMT_READS_TEMP_NON_TRANS_TABLE) |
+ (1U << STMT_WRITES_TEMP_NON_TRANS_TABLE))) != 0);
+ }
+
+ /**
+ Checks if a temporary non-transactional table is about to be accessed
+ while executing a statement.
+
+ @return
+ @retval TRUE if a temporary non-transactional table is about to be
+ accessed
+ @retval FALSE otherwise
+ */
+ inline bool stmt_accessed_non_trans_temp_table()
+ {
+ DBUG_ENTER("THD::stmt_accessed_non_trans_temp_table");
+
+ DBUG_RETURN((stmt_accessed_table_flag &
+ ((1U << STMT_READS_TEMP_NON_TRANS_TABLE) |
+ (1U << STMT_WRITES_TEMP_NON_TRANS_TABLE))) != 0);
+ }
+
private:
/**
Indicates the format in which the current statement will be
@@ -1607,6 +1726,12 @@ private:
*/
uint32 binlog_unsafe_warning_flags;
+ /**
+ Bit field that determines the type of tables that are about to be
+ be accessed while executing a statement.
+ */
+ uint32 stmt_accessed_table_flag;
+
void issue_unsafe_warnings();
/*
@@ -2025,7 +2150,6 @@ public:
is set if a statement accesses a temporary table created through
CREATE TEMPORARY TABLE.
*/
- bool thread_temporary_used;
bool charset_is_system_charset, charset_is_collation_connection;
bool charset_is_character_set_filesystem;
bool enable_slow_log; /* enable slow log for current statement */
@@ -2339,7 +2463,12 @@ public:
/** Return FALSE if connection to client is broken. */
bool is_connected()
{
- return vio_ok() ? vio_is_connected(net.vio) : FALSE;
+ /*
+ All system threads (e.g., the slave IO thread) are connected but
+ not using vio. So this function always returns true for all
+ system threads.
+ */
+ return system_thread || (vio_ok() ? vio_is_connected(net.vio) : FALSE);
}
#else
inline bool vio_ok() const { return TRUE; }
@@ -2537,7 +2666,7 @@ public:
memcpy(db, new_db, new_db_len+1);
else
{
- x_free(db);
+ my_free(db);
if (new_db)
db= my_strndup(new_db, new_db_len, MYF(MY_WME | ME_FATALERROR));
else
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc
index 35ba39afd81..003203b5466 100644
--- a/sql/sql_connect.cc
+++ b/sql/sql_connect.cc
@@ -98,7 +98,7 @@ static int get_or_create_user_conn(THD *thd, const char *user,
if (my_hash_insert(&hash_user_connections, (uchar*) uc))
{
/* The only possible error is out of memory, MY_WME sets an error. */
- my_free((char*) uc,0);
+ my_free(uc);
return_val= 1;
goto end;
}
@@ -555,7 +555,7 @@ extern "C" uchar *get_key_conn(user_conn *buff, size_t *length,
extern "C" void free_user(struct user_conn *uc)
{
- my_free((char*) uc,MYF(0));
+ my_free(uc);
}
@@ -940,8 +940,7 @@ static int check_connection(THD *thd)
user_len-= 2;
}
- if (thd->main_security_ctx.user)
- x_free(thd->main_security_ctx.user);
+ my_free(thd->main_security_ctx.user);
if (!(thd->main_security_ctx.user= my_strdup(user, MYF(MY_WME))))
return 1; /* The error is set by my_strdup(). */
return check_user(thd, COM_CONNECT, passwd, passwd_len, db, TRUE);
@@ -1073,10 +1072,6 @@ static void prepare_new_connection_state(THD* thd)
{
Security_context *sctx= thd->security_ctx;
-#ifdef __NETWARE__
- netware_reg_user(sctx->ip, sctx->user, "MySQL");
-#endif
-
if (thd->client_capabilities & CLIENT_COMPRESS)
thd->net.compress=1; // Use compression
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 2e48475f298..1040fc92851 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -94,7 +94,7 @@ extern "C" void lock_db_free_element(void *ptr);
void lock_db_free_element(void *ptr)
{
- my_free(ptr, MYF(0));
+ my_free(ptr);
}
@@ -136,7 +136,7 @@ static my_bool lock_db_insert(const char *dbname, uint length)
opt->name_length= length;
if ((error= my_hash_insert(&lock_db_cache, (uchar*) opt)))
- my_free(opt, MYF(0));
+ my_free(opt);
}
end:
@@ -209,7 +209,7 @@ extern "C" void free_dbopt(void *dbopt);
void free_dbopt(void *dbopt)
{
- my_free((uchar*) dbopt, MYF(0));
+ my_free(dbopt);
}
#ifdef HAVE_PSI_INTERFACE
@@ -377,7 +377,7 @@ static my_bool put_dbopt(const char *dbname, HA_CREATE_INFO *create)
if ((error= my_hash_insert(&dboptions, (uchar*) opt)))
{
- my_free(opt, MYF(0));
+ my_free(opt);
goto end;
}
}
@@ -1438,8 +1438,7 @@ static void mysql_change_db_impl(THD *thd,
we just call THD::reset_db(). Since THD::reset_db() does not releases
the previous database name, we should do it explicitly.
*/
-
- x_free(thd->db);
+ my_free(thd->db);
thd->reset_db(new_db_name->str, new_db_name->length);
}
@@ -1652,7 +1651,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch)
if (check_db_name(&new_db_file_name))
{
my_error(ER_WRONG_DB_NAME, MYF(0), new_db_file_name.str);
- my_free(new_db_file_name.str, MYF(0));
+ my_free(new_db_file_name.str);
if (force_switch)
mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server);
@@ -1682,7 +1681,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch)
new_db_file_name.str);
general_log_print(thd, COM_INIT_DB, ER(ER_DBACCESS_DENIED_ERROR),
sctx->priv_user, sctx->priv_host, new_db_file_name.str);
- my_free(new_db_file_name.str, MYF(0));
+ my_free(new_db_file_name.str);
DBUG_RETURN(TRUE);
}
#endif
@@ -1697,7 +1696,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch)
ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR),
new_db_file_name.str);
- my_free(new_db_file_name.str, MYF(0));
+ my_free(new_db_file_name.str);
/* Change db to NULL. */
@@ -1712,7 +1711,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch)
/* Report an error and free new_db_file_name. */
my_error(ER_BAD_DB_ERROR, MYF(0), new_db_file_name.str);
- my_free(new_db_file_name.str, MYF(0));
+ my_free(new_db_file_name.str);
/* The operation failed. */
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index c4a773fee9c..c94ea1302c8 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -47,7 +47,7 @@
*/
bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
- SQL_I_List<ORDER> *order, ha_rows limit, ulonglong options)
+ SQL_I_List<ORDER> *order_list, ha_rows limit, ulonglong options)
{
bool will_batch;
int error, loc_error;
@@ -58,6 +58,9 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
bool transactional_table, safe_update, const_cond;
bool const_cond_result;
ha_rows deleted= 0;
+ bool reverse= FALSE;
+ ORDER *order= (ORDER *) ((order_list && order_list->elements) ?
+ order_list->first : NULL);
uint usable_index= MAX_KEY;
SELECT_LEX *select_lex= &thd->lex->select_lex;
THD::killed_state killed_status= THD::NOT_KILLED;
@@ -79,7 +82,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
DBUG_RETURN(TRUE);
/* check ORDER BY even if it can be ignored */
- if (order && order->elements)
+ if (order)
{
TABLE_LIST tables;
List<Item> fields;
@@ -89,9 +92,9 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
tables.table = table;
tables.alias = table_list->alias;
- if (select_lex->setup_ref_array(thd, order->elements) ||
+ if (select_lex->setup_ref_array(thd, order_list->elements) ||
setup_order(thd, select_lex->ref_pointer_array, &tables,
- fields, all_fields, order->first))
+ fields, all_fields, order))
{
delete select;
free_underlaid_joins(thd, &thd->lex->select_lex);
@@ -182,6 +185,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
table->covering_keys.clear_all();
table->quick_keys.clear_all(); // Can't use 'only index'
+
select=make_select(table, 0, 0, conds, 0, &error);
if (error)
DBUG_RETURN(TRUE);
@@ -217,22 +221,25 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (options & OPTION_QUICK)
(void) table->file->extra(HA_EXTRA_QUICK);
- if (order && order->elements)
+ if (order)
{
uint length= 0;
SORT_FIELD *sortorder;
ha_rows examined_rows;
- if ((!select || table->quick_keys.is_clear_all()) && limit != HA_POS_ERROR)
- usable_index= get_index_for_order(table, order->first, limit);
+ table->update_const_key_parts(conds);
+ order= simple_remove_const(order, conds);
- if (usable_index == MAX_KEY)
+ bool need_sort;
+ usable_index= get_index_for_order(order, table, select, limit,
+ &need_sort, &reverse);
+ if (need_sort)
{
+ DBUG_ASSERT(usable_index == MAX_KEY);
table->sort.io_cache= (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
MYF(MY_FAE | MY_ZEROFILL));
- if (!(sortorder= make_unireg_sortorder(order->first,
- &length, NULL)) ||
+ if (!(sortorder= make_unireg_sortorder(order, &length, NULL)) ||
(table->sort.found_records = filesort(thd, table, sortorder, length,
select, HA_POS_ERROR, 1,
&examined_rows))
@@ -263,7 +270,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (usable_index==MAX_KEY || (select && select->quick))
init_read_record(&info, thd, table, select, 1, 1, FALSE);
else
- init_read_record_idx(&info, thd, table, 1, usable_index);
+ init_read_record_idx(&info, thd, table, 1, usable_index, reverse);
init_ftfuncs(thd, select_lex, 1);
thd_proc_info(thd, "updating");
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index d6f2a472e05..06a453f7b12 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -109,7 +109,7 @@ static char *mysql_ha_hash_get_key(TABLE_LIST *tables, size_t *key_len_p,
static void mysql_ha_hash_free(TABLE_LIST *tables)
{
- my_free((char*) tables, MYF(0));
+ my_free(tables);
}
/**
@@ -259,7 +259,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
/* add to hash */
if (my_hash_insert(&thd->handler_tables_hash, (uchar*) hash_tables))
{
- my_free((char*) hash_tables, MYF(0));
+ my_free(hash_tables);
DBUG_PRINT("exit",("ERROR"));
DBUG_RETURN(TRUE);
}
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 24a418f8f25..c783d74b363 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -93,7 +93,7 @@ static bool check_view_insertability(THD *thd, TABLE_LIST *view);
#define my_safe_afree(ptr, size, min_length) my_afree(ptr)
#else
#define my_safe_alloca(size, min_length) ((size <= min_length) ? my_alloca(size) : my_malloc(size,MYF(0)))
-#define my_safe_afree(ptr, size, min_length) if (size > min_length) my_free(ptr,MYF(0))
+#define my_safe_afree(ptr, size, min_length) if (size > min_length) my_free(ptr)
#endif
/*
@@ -1779,8 +1779,8 @@ public:
{}
~delayed_row()
{
- x_free(query.str);
- x_free(record);
+ my_free(query.str);
+ my_free(record);
}
};
@@ -1868,7 +1868,7 @@ public:
mysql_cond_destroy(&cond);
mysql_cond_destroy(&cond_client);
thd.unlink(); // Must be unlinked under lock
- x_free(thd.query());
+ my_free(thd.query());
thd.security_ctx->user= thd.security_ctx->host=0;
thread_count--;
delayed_insert_threads--;
@@ -2276,7 +2276,7 @@ int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic,
row= new delayed_row(query, duplic, ignore, log_on);
if (row == NULL)
{
- my_free(query.str, MYF(MY_WME));
+ my_free(query.str);
goto err;
}
@@ -2680,7 +2680,7 @@ static void free_delayed_insert_blobs(register TABLE *table)
{
uchar *str;
((Field_blob *) (*ptr))->get_ptr(&str);
- my_free(str,MYF(MY_ALLOW_ZERO_PTR));
+ my_free(str);
((Field_blob *) (*ptr))->reset();
}
}
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 5f8b1148dcb..aefddc0b6a5 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -457,8 +457,8 @@ Yacc_state::~Yacc_state()
{
if (yacc_yyss)
{
- my_free(yacc_yyss, MYF(0));
- my_free(yacc_yyvs, MYF(0));
+ my_free(yacc_yyss);
+ my_free(yacc_yyvs);
}
}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 05af1237be8..b8bf3b220c9 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -998,7 +998,7 @@ extern const LEX_STRING null_lex_str;
extern const LEX_STRING empty_lex_str;
-struct Sroutine_hash_entry;
+class Sroutine_hash_entry;
/*
Class representing list of all tables used by statement and other
diff --git a/sql/sql_list.h b/sql/sql_list.h
index 5b63e80ae94..5cd24236644 100644
--- a/sql/sql_list.h
+++ b/sql/sql_list.h
@@ -534,7 +534,7 @@ struct ilink
}
static void operator delete(void* ptr_arg, size_t size)
{
- my_free((uchar*)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
+ my_free(ptr_arg);
}
inline ilink()
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 17c86602583..b2a816a69dd 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -355,7 +355,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
(void) fn_format(name, ex->file_name, mysql_real_data_home, "",
MY_RELATIVE_PATH | MY_UNPACK_FILENAME |
MY_RETURN_REAL_PATH);
-#if !defined(__WIN__) && ! defined(__NETWARE__)
+#if !defined(__WIN__)
MY_STAT stat_info;
if (!mysql_file_stat(key_file_load, name, &stat_info, MYF(MY_WME)))
DBUG_RETURN(TRUE);
@@ -1337,7 +1337,7 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs,
(is_fifo ? READ_FIFO : READ_CACHE),0L,1,
MYF(MY_WME)))
{
- my_free((uchar*) buffer,MYF(0)); /* purecov: inspected */
+ my_free(buffer); /* purecov: inspected */
error=1;
}
else
@@ -1368,7 +1368,7 @@ READ_INFO::~READ_INFO()
{
if (need_end_io_cache)
::end_io_cache(&cache);
- my_free((uchar*) buffer,MYF(0));
+ my_free(buffer);
error=1;
}
List_iterator<XML_TAG> xmlit(taglist);
diff --git a/sql/sql_locale.cc b/sql/sql_locale.cc
index abd9c395083..c8aee307362 100644
--- a/sql/sql_locale.cc
+++ b/sql/sql_locale.cc
@@ -3442,6 +3442,6 @@ void cleanup_errmsgs()
{
for (MY_LOCALE_ERRMSGS *msgs= global_errmsgs; msgs->language; msgs++)
{
- my_free(msgs->errmsgs, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
+ my_free(msgs->errmsgs);
}
}
diff --git a/sql/sql_manager.cc b/sql/sql_manager.cc
index 2189b1e124f..e3929066361 100644
--- a/sql/sql_manager.cc
+++ b/sql/sql_manager.cc
@@ -117,7 +117,7 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused)))
{
struct handler_cb *next= cb->next;
cb->action();
- my_free((uchar*)cb, MYF(0));
+ my_free(cb);
cb= next;
}
}
diff --git a/sql/sql_map.cc b/sql/sql_map.cc
index 35a248e5465..ca8a88bcbf8 100644
--- a/sql/sql_map.cc
+++ b/sql/sql_map.cc
@@ -74,7 +74,7 @@ mapped_files::~mapped_files()
(void) mysql_file_close(file, MYF(0));
file= -1; map=0;
}
- my_free(name,MYF(0));
+ my_free(name);
#endif
}
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index c3daf3b9520..28a867cfcd8 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1058,7 +1058,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if (res)
{
- x_free(thd->security_ctx->user);
+ my_free(thd->security_ctx->user);
*thd->security_ctx= save_security_ctx;
thd->user_connect= save_user_connect;
thd->db= save_db;
@@ -1071,8 +1071,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if (save_user_connect)
decrease_user_connections(save_user_connect);
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
- x_free(save_db);
- x_free(save_security_ctx.user);
+ my_free(save_db);
+ my_free(save_security_ctx.user);
if (cs_number)
{
@@ -1415,18 +1415,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
#ifdef EMBEDDED_LIBRARY
/* Store the buffer in permanent memory */
my_ok(thd, 0, 0, buff);
-#endif
-#ifdef SAFEMALLOC
- if (sf_malloc_cur_memory) // Using SAFEMALLOC
- {
- char *end= buff + length;
- length+= my_snprintf(end, buff_len - length - 1,
- end," Memory in use: %ldK Max memory used: %ldK",
- (sf_malloc_cur_memory+1023L)/1024L,
- (sf_malloc_max_memory+1023L)/1024L);
- }
-#endif
-#ifndef EMBEDDED_LIBRARY
+#else
(void) my_net_write(net, (uchar*) buff, length);
(void) net_flush(net);
thd->stmt_da->disable_status();
@@ -5633,7 +5622,7 @@ void THD::reset_for_next_command()
thd->transaction.all.modified_non_trans_table= FALSE;
}
DBUG_ASSERT(thd->security_ctx== &thd->main_security_ctx);
- thd->thread_specific_used= thd->thread_temporary_used= FALSE;
+ thd->thread_specific_used= FALSE;
if (opt_bin_log)
{
@@ -5648,6 +5637,7 @@ void THD::reset_for_next_command()
thd->reset_current_stmt_binlog_format_row();
thd->binlog_unsafe_warning_flags= 0;
+ thd->stmt_accessed_table_flag= 0;
DBUG_PRINT("debug",
("is_current_stmt_binlog_format_row(): %d",
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index bc9a7d8ee65..d7ff753dfd0 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -2624,7 +2624,7 @@ char *generate_partition_syntax(partition_info *part_info,
if (unlikely(mysql_file_read(fptr, (uchar*)buf, *buf_length, MYF(MY_FNABP))))
{
if (!use_sql_alloc)
- my_free(buf, MYF(0));
+ my_free(buf);
else
buf= NULL;
}
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 97c480ea0bd..2b6be403fc6 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -254,10 +254,9 @@ static void plugin_vars_free_values(sys_var *vars);
static void restore_pluginvar_names(sys_var *first);
static void plugin_opt_set_limits(struct my_option *,
const struct st_mysql_sys_var *);
-#define my_intern_plugin_lock(A,B) intern_plugin_lock(A,B CALLER_INFO)
-#define my_intern_plugin_lock_ci(A,B) intern_plugin_lock(A,B ORIG_CALLER_INFO)
-static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin
- CALLER_INFO_PROTO);
+#define my_intern_plugin_lock(A,B) intern_plugin_lock(A,B)
+#define my_intern_plugin_lock_ci(A,B) intern_plugin_lock(A,B)
+static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin);
static void intern_plugin_unlock(LEX *lex, plugin_ref plugin);
static void reap_plugins(void);
@@ -392,9 +391,9 @@ static inline void free_plugin_mem(struct st_plugin_dl *p)
if (p->handle)
dlclose(p->handle);
#endif
- my_free(p->dl.str, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(p->dl.str);
if (p->version != MYSQL_PLUGIN_INTERFACE_VERSION)
- my_free((uchar*)p->plugins, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(p->plugins);
}
@@ -660,7 +659,7 @@ SHOW_COMP_OPTION plugin_status(const char *name, int len, size_t type)
}
-static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO)
+static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc)
{
st_plugin_int *pi= plugin_ref_to_int(rc);
DBUG_ENTER("intern_plugin_lock");
@@ -682,7 +681,7 @@ static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO)
memory manager and/or valgrind to track locked references and
double unlocks to aid resolving reference counting problems.
*/
- if (!(plugin= (plugin_ref) my_malloc_ci(sizeof(pi), MYF(MY_WME))))
+ if (!(plugin= (plugin_ref) my_malloc(sizeof(pi), MYF(MY_WME))))
DBUG_RETURN(NULL);
*plugin= pi;
@@ -699,7 +698,7 @@ static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO)
}
-plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
+plugin_ref plugin_lock(THD *thd, plugin_ref *ptr)
{
LEX *lex= thd ? thd->lex : 0;
plugin_ref rc;
@@ -711,8 +710,7 @@ plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
}
-plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type
- CALLER_INFO_PROTO)
+plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type)
{
LEX *lex= thd ? thd->lex : 0;
plugin_ref rc= NULL;
@@ -973,7 +971,7 @@ static void intern_plugin_unlock(LEX *lex, plugin_ref plugin)
if (!pi->plugin_dl)
DBUG_VOID_RETURN;
#else
- my_free((uchar*) plugin, MYF(MY_WME));
+ my_free(plugin);
#endif
DBUG_PRINT("info",("unlocking plugin, name= %s, ref_count= %d",
@@ -2245,7 +2243,7 @@ static void update_func_str(THD *thd, struct st_mysql_sys_var *var,
if (var->flags & PLUGIN_VAR_MEMALLOC)
{
*(char **)tgt= my_strdup(*(char **) save, MYF(0));
- my_free(old, MYF(0));
+ my_free(old);
}
}
@@ -2637,7 +2635,7 @@ static void cleanup_variables(THD *thd, struct system_variables *vars)
flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
{
char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
- my_free(*ptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
+ my_free(*ptr);
*ptr= NULL;
}
}
@@ -2645,7 +2643,7 @@ static void cleanup_variables(THD *thd, struct system_variables *vars)
DBUG_ASSERT(vars->table_plugin == NULL);
- my_free(vars->dynamic_variables_ptr, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(vars->dynamic_variables_ptr);
vars->dynamic_variables_ptr= NULL;
vars->dynamic_variables_size= 0;
vars->dynamic_variables_version= 0;
@@ -2706,7 +2704,7 @@ static void plugin_vars_free_values(sys_var *vars)
char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
DBUG_PRINT("plugin", ("freeing value for: '%s' addr: 0x%lx",
var->name.str, (long) valptr));
- my_free(*valptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
+ my_free(*valptr);
*valptr= NULL;
}
}
diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h
index e7ecca029b9..079dc4e6dca 100644
--- a/sql/sql_plugin.h
+++ b/sql/sql_plugin.h
@@ -30,8 +30,6 @@
#include "m_string.h" /* LEX_STRING */
#include "my_alloc.h" /* MEM_ROOT */
-#include "my_sys.h" /* CALLER_INFO_PROTO */
-
class sys_var;
enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED};
@@ -134,13 +132,13 @@ extern int plugin_init(int *argc, char **argv, int init_flags);
extern void plugin_shutdown(void);
void add_plugin_options(DYNAMIC_ARRAY *options, MEM_ROOT *mem_root);
extern bool plugin_is_ready(const LEX_STRING *name, int type);
-#define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C CALLER_INFO)
-#define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C ORIG_CALLER_INFO)
-#define my_plugin_lock(A,B) plugin_lock(A,B CALLER_INFO)
-#define my_plugin_lock_ci(A,B) plugin_lock(A,B ORIG_CALLER_INFO)
-extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO);
+#define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C)
+#define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C)
+#define my_plugin_lock(A,B) plugin_lock(A,B)
+#define my_plugin_lock_ci(A,B) plugin_lock(A,B)
+extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr);
extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name,
- int type CALLER_INFO_PROTO);
+ int type);
extern void plugin_unlock(THD *thd, plugin_ref plugin);
extern void plugin_unlock_list(THD *thd, plugin_ref *list, uint count);
extern bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc
index 4a0d3d944ad..ce3d786cf92 100644
--- a/sql/sql_profile.cc
+++ b/sql/sql_profile.cc
@@ -177,8 +177,7 @@ PROF_MEASUREMENT::PROF_MEASUREMENT(QUERY_PROFILE *profile_arg,
PROF_MEASUREMENT::~PROF_MEASUREMENT()
{
- if (allocated_status_memory != NULL)
- my_free(allocated_status_memory, MYF(0));
+ my_free(allocated_status_memory);
status= function= file= NULL;
}
@@ -268,8 +267,7 @@ QUERY_PROFILE::~QUERY_PROFILE()
while (! entries.is_empty())
delete entries.pop();
- if (query_source != NULL)
- my_free(query_source, MYF(0));
+ my_free(query_source);
}
/**
diff --git a/sql/sql_profile.h b/sql/sql_profile.h
index ff16a2da19b..7d17dc69b88 100644
--- a/sql/sql_profile.h
+++ b/sql/sql_profile.h
@@ -82,7 +82,7 @@ public:
for (i= first; i != NULL; i= after_i)
{
after_i= i->next;
- my_free((char *) i, MYF(0));
+ my_free(i);
}
elements= 0;
}
@@ -129,7 +129,7 @@ public:
last= NULL;
first= first->next;
- my_free((char *)old_item, MYF(0));
+ my_free(old_item);
elements--;
return ret;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index d3db6bd89c3..11378ac0d11 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -137,7 +137,6 @@ static uint build_bitmap_for_nested_joins(List<TABLE_LIST> *join_list,
static COND *optimize_cond(JOIN *join, COND *conds,
List<TABLE_LIST> *join_list,
Item::cond_result *cond_value);
-static bool const_expression_in_where(COND *conds,Item *item, Item **comp_item);
static bool open_tmp_table(TABLE *table);
static bool create_myisam_tmp_table(TABLE *,TMP_TABLE_PARAM *, ulonglong, my_bool);
static int do_select(JOIN *join,List<Item> *fields,TABLE *tmp_table,
@@ -190,6 +189,14 @@ static COND *make_cond_for_table(COND *cond,table_map table,
table_map used_table);
static Item* part_of_refkey(TABLE *form,Field *field);
uint find_shortest_key(TABLE *table, const key_map *usable_keys);
+static bool test_if_cheaper_ordering(const JOIN_TAB *tab,
+ ORDER *order, TABLE *table,
+ key_map usable_keys, int key,
+ ha_rows select_limit,
+ int *new_key, int *new_key_direction,
+ ha_rows *new_select_limit,
+ uint *new_used_key_parts= NULL,
+ uint *saved_best_key_parts= NULL);
static bool test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,
ha_rows select_limit, bool no_changes,
key_map *map);
@@ -6959,7 +6966,7 @@ void JOIN_TAB::cleanup()
select= 0;
delete quick;
quick= 0;
- x_free(cache.buff);
+ my_free(cache.buff);
cache.buff= 0;
limit= 0;
if (table)
@@ -7370,8 +7377,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
*simple_order=0;
else
{
- Item *comp_item=0;
- if (cond && const_expression_in_where(cond,order->item[0], &comp_item))
+ if (cond && const_expression_in_where(cond,order->item[0]))
{
DBUG_PRINT("info",("removing: %s", order->item[0]->full_name()));
continue;
@@ -7401,6 +7407,46 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
}
+/**
+ Filter out ORDER items those are equal to constants in WHERE
+
+ This function is a limited version of remove_const() for use
+ with non-JOIN statements (i.e. single-table UPDATE and DELETE).
+
+
+ @param order Linked list of ORDER BY arguments
+ @param cond WHERE expression
+
+ @return pointer to new filtered ORDER list or NULL if whole list eliminated
+
+ @note
+ This function overwrites input order list.
+*/
+
+ORDER *simple_remove_const(ORDER *order, COND *where)
+{
+ if (!order || !where)
+ return order;
+
+ ORDER *first= NULL, *prev= NULL;
+ for (; order; order= order->next)
+ {
+ DBUG_ASSERT(!order->item[0]->with_sum_func); // should never happen
+ if (!const_expression_in_where(where, order->item[0]))
+ {
+ if (!first)
+ first= order;
+ if (prev)
+ prev->next= order;
+ prev= order;
+ }
+ }
+ if (prev)
+ prev->next= NULL;
+ return first;
+}
+
+
static int
return_zero_rows(JOIN *join, select_result *result,TABLE_LIST *tables,
List<Item> &fields, bool send_row, ulonglong select_options,
@@ -8593,10 +8639,9 @@ change_cond_ref_to_const(THD *thd, I_List<COND_CMP> *save_list,
left_item->collation.collation == value->collation.collation))
{
Item *tmp=value->clone_item();
- tmp->collation.set(right_item->collation);
-
if (tmp)
{
+ tmp->collation.set(right_item->collation);
thd->change_item_tree(args + 1, tmp);
func->update_used_tables();
if ((functype == Item_func::EQ_FUNC || functype == Item_func::EQUAL_FUNC)
@@ -8617,10 +8662,9 @@ change_cond_ref_to_const(THD *thd, I_List<COND_CMP> *save_list,
right_item->collation.collation == value->collation.collation))
{
Item *tmp= value->clone_item();
- tmp->collation.set(left_item->collation);
-
if (tmp)
{
+ tmp->collation.set(left_item->collation);
thd->change_item_tree(args, tmp);
value= tmp;
func->update_used_tables();
@@ -9602,13 +9646,50 @@ test_if_equality_guarantees_uniqueness(Item *l, Item *r)
l->collation.collation == r->collation.collation)));
}
-/**
- Return TRUE if the item is a const value in all the WHERE clause.
+
+/*
+ Return TRUE if i1 and i2 (if any) are equal items,
+ or if i1 is a wrapper item around the f2 field.
*/
-static bool
-const_expression_in_where(COND *cond, Item *comp_item, Item **const_item)
+static bool equal(Item *i1, Item *i2, Field *f2)
+{
+ DBUG_ASSERT((i2 == NULL) ^ (f2 == NULL));
+
+ if (i2 != NULL)
+ return i1->eq(i2, 1);
+ else if (i1->type() == Item::FIELD_ITEM)
+ return f2->eq(((Item_field *) i1)->field);
+ else
+ return FALSE;
+}
+
+
+/**
+ Test if a field or an item is equal to a constant value in WHERE
+
+ @param cond WHERE clause expression
+ @param comp_item Item to find in WHERE expression
+ (if comp_field != NULL)
+ @param comp_field Field to find in WHERE expression
+ (if comp_item != NULL)
+ @param[out] const_item intermediate arg, set to Item pointer to NULL
+
+ @return TRUE if the field is a constant value in WHERE
+
+ @note
+ comp_item and comp_field parameters are mutually exclusive.
+*/
+bool
+const_expression_in_where(COND *cond, Item *comp_item, Field *comp_field,
+ Item **const_item)
{
+ DBUG_ASSERT((comp_item == NULL) ^ (comp_field == NULL));
+
+ Item *intermediate= NULL;
+ if (const_item == NULL)
+ const_item= &intermediate;
+
if (cond->type() == Item::COND_ITEM)
{
bool and_level= (((Item_cond*) cond)->functype()
@@ -9617,7 +9698,8 @@ const_expression_in_where(COND *cond, Item *comp_item, Item **const_item)
Item *item;
while ((item=li++))
{
- bool res=const_expression_in_where(item, comp_item, const_item);
+ bool res=const_expression_in_where(item, comp_item, comp_field,
+ const_item);
if (res) // Is a const value
{
if (and_level)
@@ -9629,14 +9711,14 @@ const_expression_in_where(COND *cond, Item *comp_item, Item **const_item)
return and_level ? 0 : 1;
}
else if (cond->eq_cmp_result() != Item::COND_OK)
- { // boolan compare function
+ { // boolean compare function
Item_func* func= (Item_func*) cond;
if (func->functype() != Item_func::EQUAL_FUNC &&
func->functype() != Item_func::EQ_FUNC)
return 0;
Item *left_item= ((Item_func*) cond)->arguments()[0];
Item *right_item= ((Item_func*) cond)->arguments()[1];
- if (left_item->eq(comp_item,1))
+ if (equal(left_item, comp_item, comp_field))
{
if (test_if_equality_guarantees_uniqueness (left_item, right_item))
{
@@ -9646,7 +9728,7 @@ const_expression_in_where(COND *cond, Item *comp_item, Item **const_item)
return 1;
}
}
- else if (right_item->eq(comp_item,1))
+ else if (equal(right_item, comp_item, comp_field))
{
if (test_if_equality_guarantees_uniqueness (right_item, left_item))
{
@@ -9660,6 +9742,7 @@ const_expression_in_where(COND *cond, Item *comp_item, Item **const_item)
return 0;
}
+
/****************************************************************************
Create internal temporary table
****************************************************************************/
@@ -13113,7 +13196,8 @@ part_of_refkey(TABLE *table,Field *field)
@param order Sort order
@param table Table to sort
@param idx Index to check
- @param used_key_parts Return value for used key parts.
+ @param used_key_parts [out] NULL by default, otherwise return value for
+ used key parts.
@note
@@ -13132,13 +13216,14 @@ part_of_refkey(TABLE *table,Field *field)
*/
static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
- uint *used_key_parts)
+ uint *used_key_parts= NULL)
{
KEY_PART_INFO *key_part,*key_part_end;
key_part=table->key_info[idx].key_part;
key_part_end=key_part+table->key_info[idx].key_parts;
key_part_map const_key_parts=table->const_key_parts[idx];
int reverse=0;
+ uint key_parts;
my_bool on_pk_suffix= FALSE;
DBUG_ENTER("test_if_order_by_key");
@@ -13179,8 +13264,9 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
*/
if (key_part == key_part_end && reverse == 0)
{
- *used_key_parts= 0;
- DBUG_RETURN(1);
+ key_parts= 0;
+ reverse= 1;
+ goto ok;
}
}
else
@@ -13203,7 +13289,7 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
uint used_key_parts_secondary= table->key_info[idx].key_parts;
uint used_key_parts_pk=
(uint) (key_part - table->key_info[table->s->primary_key].key_part);
- *used_key_parts= used_key_parts_pk + used_key_parts_secondary;
+ key_parts= used_key_parts_pk + used_key_parts_secondary;
if (reverse == -1 &&
(!(table->file->index_flags(idx, used_key_parts_secondary - 1, 1) &
@@ -13214,11 +13300,14 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
}
else
{
- *used_key_parts= (uint) (key_part - table->key_info[idx].key_part);
+ key_parts= (uint) (key_part - table->key_info[idx].key_part);
if (reverse == -1 &&
- !(table->file->index_flags(idx, *used_key_parts-1, 1) & HA_READ_PREV))
+ !(table->file->index_flags(idx, key_parts-1, 1) & HA_READ_PREV))
reverse= 0; // Index can't be used
}
+ok:
+ if (used_key_parts != NULL)
+ *used_key_parts= key_parts;
DBUG_RETURN(reverse);
}
@@ -13312,7 +13401,6 @@ test_if_subkey(ORDER *order, TABLE *table, uint ref, uint ref_key_parts,
uint nr;
uint min_length= (uint) ~0;
uint best= MAX_KEY;
- uint not_used;
KEY_PART_INFO *ref_key_part= table->key_info[ref].key_part;
KEY_PART_INFO *ref_key_part_end= ref_key_part + ref_key_parts;
@@ -13323,7 +13411,7 @@ test_if_subkey(ORDER *order, TABLE *table, uint ref, uint ref_key_parts,
table->key_info[nr].key_parts >= ref_key_parts &&
is_subkey(table->key_info[nr].key_part, ref_key_part,
ref_key_part_end) &&
- test_if_order_by_key(order, table, nr, &not_used))
+ test_if_order_by_key(order, table, nr))
{
min_length= table->key_info[nr].key_length;
best= nr;
@@ -13615,185 +13703,18 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
goto check_reverse_order;
}
{
- /*
- Check whether there is an index compatible with the given order
- usage of which is cheaper than usage of the ref_key index (ref_key>=0)
- or a table scan.
- It may be the case if ORDER/GROUP BY is used with LIMIT.
- */
- uint nr;
- key_map keys;
uint best_key_parts= 0;
uint saved_best_key_parts= 0;
int best_key_direction= 0;
- ha_rows best_records= 0;
- double read_time;
int best_key= -1;
- bool is_best_covering= FALSE;
- double fanout= 1;
JOIN *join= tab->join;
- uint tablenr= tab - join->join_tab;
ha_rows table_records= table->file->stats.records;
- bool group= join->group && order == join->group_list;
- ha_rows ref_key_quick_rows= HA_POS_ERROR;
-
- /*
- If not used with LIMIT, only use keys if the whole query can be
- resolved with a key; This is because filesort() is usually faster than
- retrieving all rows through an index.
- */
- if (select_limit >= table_records)
- {
- keys= *table->file->keys_to_use_for_scanning();
- keys.merge(table->covering_keys);
- /*
- We are adding here also the index specified in FORCE INDEX clause,
- if any.
- This is to allow users to use index in ORDER BY.
- */
- if (table->force_index)
- keys.merge(group ? table->keys_in_use_for_group_by :
- table->keys_in_use_for_order_by);
- keys.intersect(usable_keys);
- }
- else
- keys= usable_keys;
-
- if (ref_key >= 0 && table->covering_keys.is_set(ref_key))
- ref_key_quick_rows= table->quick_rows[ref_key];
-
- read_time= join->best_positions[tablenr].read_time;
- for (uint i= tablenr+1; i < join->tables; i++)
- fanout*= join->best_positions[i].records_read; // fanout is always >= 1
-
- for (nr=0; nr < table->s->keys ; nr++)
- {
- int direction;
-
- if (keys.is_set(nr) &&
- (direction= test_if_order_by_key(order, table, nr, &used_key_parts)))
- {
- /*
- At this point we are sure that ref_key is a non-ordering
- key (where "ordering key" is a key that will return rows
- in the order required by ORDER BY).
- */
- DBUG_ASSERT (ref_key != (int) nr);
-
- bool is_covering= table->covering_keys.is_set(nr) ||
- (nr == table->s->primary_key &&
- table->file->primary_key_is_clustered());
-
- /*
- Don't use an index scan with ORDER BY without limit.
- For GROUP BY without limit always use index scan
- if there is a suitable index.
- Why we hold to this asymmetry hardly can be explained
- rationally. It's easy to demonstrate that using
- temporary table + filesort could be cheaper for grouping
- queries too.
- */
- if (is_covering ||
- select_limit != HA_POS_ERROR ||
- (ref_key < 0 && (group || table->force_index)))
- {
- double rec_per_key;
- double index_scan_time;
- KEY *keyinfo= tab->table->key_info+nr;
- if (select_limit == HA_POS_ERROR)
- select_limit= table_records;
- if (group)
- {
- /*
- Used_key_parts can be larger than keyinfo->key_parts
- when using a secondary index clustered with a primary
- key (e.g. as in Innodb).
- See Bug #28591 for details.
- */
- rec_per_key= used_key_parts &&
- used_key_parts <= keyinfo->key_parts ?
- keyinfo->rec_per_key[used_key_parts-1] : 1;
- set_if_bigger(rec_per_key, 1);
- /*
- With a grouping query each group containing on average
- rec_per_key records produces only one row that will
- be included into the result set.
- */
- if (select_limit > table_records/rec_per_key)
- select_limit= table_records;
- else
- select_limit= (ha_rows) (select_limit*rec_per_key);
- }
- /*
- If tab=tk is not the last joined table tn then to get first
- L records from the result set we can expect to retrieve
- only L/fanout(tk,tn) where fanout(tk,tn) says how many
- rows in the record set on average will match each row tk.
- Usually our estimates for fanouts are too pessimistic.
- So the estimate for L/fanout(tk,tn) will be too optimistic
- and as result we'll choose an index scan when using ref/range
- access + filesort will be cheaper.
- */
- select_limit= (ha_rows) (select_limit < fanout ?
- 1 : select_limit/fanout);
- /*
- We assume that each of the tested indexes is not correlated
- with ref_key. Thus, to select first N records we have to scan
- N/selectivity(ref_key) index entries.
- selectivity(ref_key) = #scanned_records/#table_records =
- table->quick_condition_rows/table_records.
- In any case we can't select more than #table_records.
- N/(table->quick_condition_rows/table_records) > table_records
- <=> N > table->quick_condition_rows.
- */
- if (select_limit > table->quick_condition_rows)
- select_limit= table_records;
- else
- select_limit= (ha_rows) (select_limit *
- (double) table_records /
- table->quick_condition_rows);
- rec_per_key= keyinfo->rec_per_key[keyinfo->key_parts-1];
- set_if_bigger(rec_per_key, 1);
- /*
- Here we take into account the fact that rows are
- accessed in sequences rec_per_key records in each.
- Rows in such a sequence are supposed to be ordered
- by rowid/primary key. When reading the data
- in a sequence we'll touch not more pages than the
- table file contains.
- TODO. Use the formula for a disk sweep sequential access
- to calculate the cost of accessing data rows for one
- index entry.
- */
- index_scan_time= select_limit/rec_per_key *
- min(rec_per_key, table->file->scan_time());
- if ((ref_key < 0 && is_covering) ||
- (ref_key < 0 && (group || table->force_index)) ||
- index_scan_time < read_time)
- {
- ha_rows quick_records= table_records;
- if ((is_best_covering && !is_covering) ||
- (is_covering && ref_key_quick_rows < select_limit))
- continue;
- if (table->quick_keys.is_set(nr))
- quick_records= table->quick_rows[nr];
- if (best_key < 0 ||
- (select_limit <= min(quick_records,best_records) ?
- keyinfo->key_parts < best_key_parts :
- quick_records < best_records))
- {
- best_key= nr;
- best_key_parts= keyinfo->key_parts;
- saved_best_key_parts= used_key_parts;
- best_records= quick_records;
- is_best_covering= is_covering;
- best_key_direction= direction;
- }
- }
- }
- }
- }
+ test_if_cheaper_ordering(tab, order, table, usable_keys,
+ ref_key, select_limit,
+ &best_key, &best_key_direction,
+ &select_limit, &best_key_parts,
+ &saved_best_key_parts);
/*
filesort() and join cache are usually faster than reading in
@@ -13897,7 +13818,7 @@ check_reverse_order:
*/
if (!select->quick->reverse_sorted())
{
- QUICK_SELECT_DESC *tmp;
+ QUICK_SELECT_I *tmp;
int quick_type= select->quick->get_type();
if (quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE ||
quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT ||
@@ -13910,16 +13831,14 @@ check_reverse_order:
}
/* ORDER BY range_key DESC */
- tmp= new QUICK_SELECT_DESC((QUICK_RANGE_SELECT*)(select->quick),
- used_key_parts);
- if (!tmp || tmp->error)
+ tmp= select->quick->make_reverse(used_key_parts);
+ if (!tmp)
{
- delete tmp;
select->quick= save_quick;
tab->limit= 0;
DBUG_RETURN(0); // Reverse sort not supported
}
- select->quick=tmp;
+ select->set_quick(tmp);
}
}
else if (tab->type != JT_NEXT && tab->type != JT_REF_OR_NULL &&
@@ -14351,7 +14270,7 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table,
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));
+ my_free(key_buffer);
DBUG_RETURN(1);
}
@@ -14403,14 +14322,14 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table,
}
key_pos+=extra_length;
}
- my_free((char*) key_buffer,MYF(0));
+ my_free(key_buffer);
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));
+ my_free(key_buffer);
my_hash_free(&hash);
file->extra(HA_EXTRA_NO_CACHE);
(void) file->ha_rnd_end();
@@ -14493,7 +14412,7 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count)
sizeof(CACHE_FIELD*))))
{
- my_free((uchar*) cache->buff,MYF(0)); /* purecov: inspected */
+ my_free(cache->buff); /* purecov: inspected */
cache->buff=0; /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
@@ -17457,5 +17376,357 @@ void JOIN::cache_const_exprs()
/**
+ Find a cheaper access key than a given @a key
+
+ @param tab NULL or JOIN_TAB of the accessed table
+ @param order Linked list of ORDER BY arguments
+ @param table Table if tab == NULL or tab->table
+ @param usable_keys Key map to find a cheaper key in
+ @param ref_key
+ * 0 <= key < MAX_KEY - key number (hint) to start the search
+ * -1 - no key number provided
+ @param select_limit LIMIT value
+ @param [out] new_key Key number if success, otherwise undefined
+ @param [out] new_key_direction Return -1 (reverse) or +1 if success,
+ otherwise undefined
+ @param [out] new_select_limit Return adjusted LIMIT
+ @param [out] new_used_key_parts NULL by default, otherwise return number
+ of new_key prefix columns if success
+ or undefined if the function fails
+ @param [out] saved_best_key_parts NULL by default, otherwise preserve the
+ value for further use in QUICK_SELECT_DESC
+
+ @note
+ This function takes into account table->quick_condition_rows statistic
+ (that is calculated by the make_join_statistics function).
+ However, single table procedures such as mysql_update() and mysql_delete()
+ never call make_join_statistics, so they have to update it manually
+ (@see get_index_for_order()).
+*/
+
+static bool
+test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
+ key_map usable_keys, int ref_key,
+ ha_rows select_limit,
+ int *new_key, int *new_key_direction,
+ ha_rows *new_select_limit, uint *new_used_key_parts,
+ uint *saved_best_key_parts)
+{
+ DBUG_ENTER("test_if_cheaper_ordering");
+ /*
+ Check whether there is an index compatible with the given order
+ usage of which is cheaper than usage of the ref_key index (ref_key>=0)
+ or a table scan.
+ It may be the case if ORDER/GROUP BY is used with LIMIT.
+ */
+ ha_rows best_select_limit= HA_POS_ERROR;
+ JOIN *join= tab ? tab->join : NULL;
+ uint nr;
+ key_map keys;
+ uint best_key_parts= 0;
+ int best_key_direction= 0;
+ ha_rows best_records= 0;
+ double read_time;
+ int best_key= -1;
+ bool is_best_covering= FALSE;
+ double fanout= 1;
+ ha_rows table_records= table->file->stats.records;
+ bool group= join && join->group && order == join->group_list;
+ ha_rows ref_key_quick_rows= HA_POS_ERROR;
+
+ /*
+ If not used with LIMIT, only use keys if the whole query can be
+ resolved with a key; This is because filesort() is usually faster than
+ retrieving all rows through an index.
+ */
+ if (select_limit >= table_records)
+ {
+ keys= *table->file->keys_to_use_for_scanning();
+ keys.merge(table->covering_keys);
+
+ /*
+ We are adding here also the index specified in FORCE INDEX clause,
+ if any.
+ This is to allow users to use index in ORDER BY.
+ */
+ if (table->force_index)
+ keys.merge(group ? table->keys_in_use_for_group_by :
+ table->keys_in_use_for_order_by);
+ keys.intersect(usable_keys);
+ }
+ else
+ keys= usable_keys;
+
+ if (ref_key >= 0 && table->covering_keys.is_set(ref_key))
+ ref_key_quick_rows= table->quick_rows[ref_key];
+
+ if (join)
+ {
+ uint tablenr= tab - join->join_tab;
+ read_time= join->best_positions[tablenr].read_time;
+ for (uint i= tablenr+1; i < join->tables; i++)
+ fanout*= join->best_positions[i].records_read; // fanout is always >= 1
+ }
+ else
+ read_time= table->file->scan_time();
+
+ for (nr=0; nr < table->s->keys ; nr++)
+ {
+ int direction;
+ uint used_key_parts;
+
+ if (keys.is_set(nr) &&
+ (direction= test_if_order_by_key(order, table, nr, &used_key_parts)))
+ {
+ /*
+ At this point we are sure that ref_key is a non-ordering
+ key (where "ordering key" is a key that will return rows
+ in the order required by ORDER BY).
+ */
+ DBUG_ASSERT (ref_key != (int) nr);
+
+ bool is_covering= table->covering_keys.is_set(nr) ||
+ (nr == table->s->primary_key &&
+ table->file->primary_key_is_clustered());
+
+ /*
+ Don't use an index scan with ORDER BY without limit.
+ For GROUP BY without limit always use index scan
+ if there is a suitable index.
+ Why we hold to this asymmetry hardly can be explained
+ rationally. It's easy to demonstrate that using
+ temporary table + filesort could be cheaper for grouping
+ queries too.
+ */
+ if (is_covering ||
+ select_limit != HA_POS_ERROR ||
+ (ref_key < 0 && (group || table->force_index)))
+ {
+ double rec_per_key;
+ double index_scan_time;
+ KEY *keyinfo= table->key_info+nr;
+ if (select_limit == HA_POS_ERROR)
+ select_limit= table_records;
+ if (group)
+ {
+ /*
+ Used_key_parts can be larger than keyinfo->key_parts
+ when using a secondary index clustered with a primary
+ key (e.g. as in Innodb).
+ See Bug #28591 for details.
+ */
+ rec_per_key= used_key_parts &&
+ used_key_parts <= keyinfo->key_parts ?
+ keyinfo->rec_per_key[used_key_parts-1] : 1;
+ set_if_bigger(rec_per_key, 1);
+ /*
+ With a grouping query each group containing on average
+ rec_per_key records produces only one row that will
+ be included into the result set.
+ */
+ if (select_limit > table_records/rec_per_key)
+ select_limit= table_records;
+ else
+ select_limit= (ha_rows) (select_limit*rec_per_key);
+ }
+ /*
+ If tab=tk is not the last joined table tn then to get first
+ L records from the result set we can expect to retrieve
+ only L/fanout(tk,tn) where fanout(tk,tn) says how many
+ rows in the record set on average will match each row tk.
+ Usually our estimates for fanouts are too pessimistic.
+ So the estimate for L/fanout(tk,tn) will be too optimistic
+ and as result we'll choose an index scan when using ref/range
+ access + filesort will be cheaper.
+ */
+ select_limit= (ha_rows) (select_limit < fanout ?
+ 1 : select_limit/fanout);
+ /*
+ We assume that each of the tested indexes is not correlated
+ with ref_key. Thus, to select first N records we have to scan
+ N/selectivity(ref_key) index entries.
+ selectivity(ref_key) = #scanned_records/#table_records =
+ table->quick_condition_rows/table_records.
+ In any case we can't select more than #table_records.
+ N/(table->quick_condition_rows/table_records) > table_records
+ <=> N > table->quick_condition_rows.
+ */
+ if (select_limit > table->quick_condition_rows)
+ select_limit= table_records;
+ else
+ select_limit= (ha_rows) (select_limit *
+ (double) table_records /
+ table->quick_condition_rows);
+ rec_per_key= keyinfo->rec_per_key[keyinfo->key_parts-1];
+ set_if_bigger(rec_per_key, 1);
+ /*
+ Here we take into account the fact that rows are
+ accessed in sequences rec_per_key records in each.
+ Rows in such a sequence are supposed to be ordered
+ by rowid/primary key. When reading the data
+ in a sequence we'll touch not more pages than the
+ table file contains.
+ TODO. Use the formula for a disk sweep sequential access
+ to calculate the cost of accessing data rows for one
+ index entry.
+ */
+ index_scan_time= select_limit/rec_per_key *
+ min(rec_per_key, table->file->scan_time());
+ if ((ref_key < 0 && is_covering) ||
+ (ref_key < 0 && (group || table->force_index)) ||
+ index_scan_time < read_time)
+ {
+ ha_rows quick_records= table_records;
+ if ((is_best_covering && !is_covering) ||
+ (is_covering && ref_key_quick_rows < select_limit))
+ continue;
+ if (table->quick_keys.is_set(nr))
+ quick_records= table->quick_rows[nr];
+ if (best_key < 0 ||
+ (select_limit <= min(quick_records,best_records) ?
+ keyinfo->key_parts < best_key_parts :
+ quick_records < best_records))
+ {
+ best_key= nr;
+ best_key_parts= keyinfo->key_parts;
+ if (saved_best_key_parts)
+ *saved_best_key_parts= used_key_parts;
+ best_records= quick_records;
+ is_best_covering= is_covering;
+ best_key_direction= direction;
+ best_select_limit= select_limit;
+ }
+ }
+ }
+ }
+ }
+
+ if (best_key < 0 || best_key == ref_key)
+ DBUG_RETURN(FALSE);
+
+ *new_key= best_key;
+ *new_key_direction= best_key_direction;
+ *new_select_limit= best_select_limit;
+ if (new_used_key_parts != NULL)
+ *new_used_key_parts= best_key_parts;
+
+ DBUG_RETURN(TRUE);
+}
+
+
+/**
+ Find a key to apply single table UPDATE/DELETE by a given ORDER
+
+ @param order Linked list of ORDER BY arguments
+ @param table Table to find a key
+ @param select Pointer to access/update select->quick (if any)
+ @param limit LIMIT clause parameter
+ @param [out] need_sort TRUE if filesort needed
+ @param [out] reverse
+ TRUE if the key is reversed again given ORDER (undefined if key == MAX_KEY)
+
+ @return
+ - MAX_KEY if no key found (need_sort == TRUE)
+ - MAX_KEY if quick select result order is OK (need_sort == FALSE)
+ - key number (either index scan or quick select) (need_sort == FALSE)
+
+ @note
+ Side effects:
+ - may deallocate or deallocate and replace select->quick;
+ - may set table->quick_condition_rows and table->quick_rows[...]
+ to table->file->stats.records.
+*/
+
+uint get_index_for_order(ORDER *order, TABLE *table, SQL_SELECT *select,
+ ha_rows limit, bool *need_sort, bool *reverse)
+{
+ if (select && select->quick && select->quick->unique_key_range())
+ { // Single row select (always "ordered"): Ok to use with key field UPDATE
+ *need_sort= FALSE;
+ /*
+ Returning of MAX_KEY here prevents updating of used_key_is_modified
+ in mysql_update(). Use quick select "as is".
+ */
+ return MAX_KEY;
+ }
+
+ if (!order)
+ {
+ *need_sort= FALSE;
+ if (select && select->quick)
+ return select->quick->index; // index or MAX_KEY, use quick select as is
+ else
+ return table->file->key_used_on_scan; // MAX_KEY or index for some engines
+ }
+
+ if (!is_simple_order(order)) // just to cut further expensive checks
+ {
+ *need_sort= TRUE;
+ return MAX_KEY;
+ }
+
+ if (select && select->quick)
+ {
+ if (select->quick->index == MAX_KEY)
+ {
+ *need_sort= TRUE;
+ return MAX_KEY;
+ }
+
+ uint used_key_parts;
+ switch (test_if_order_by_key(order, table, select->quick->index,
+ &used_key_parts)) {
+ case 1: // desired order
+ *need_sort= FALSE;
+ return select->quick->index;
+ case 0: // unacceptable order
+ *need_sort= TRUE;
+ return MAX_KEY;
+ case -1: // desired order, but opposite direction
+ {
+ QUICK_SELECT_I *reverse_quick;
+ if ((reverse_quick=
+ select->quick->make_reverse(used_key_parts)))
+ {
+ select->set_quick(reverse_quick);
+ *need_sort= FALSE;
+ return select->quick->index;
+ }
+ else
+ {
+ *need_sort= TRUE;
+ return MAX_KEY;
+ }
+ }
+ }
+ DBUG_ASSERT(0);
+ }
+ else if (limit != HA_POS_ERROR)
+ { // check if some index scan & LIMIT is more efficient than filesort
+
+ /*
+ Update quick_condition_rows since single table UPDATE/DELETE procedures
+ don't call make_join_statistics() and leave this variable uninitialized.
+ */
+ table->quick_condition_rows= table->file->stats.records;
+
+ int key, direction;
+ if (test_if_cheaper_ordering(NULL, order, table,
+ table->keys_in_use_for_order_by, -1,
+ limit,
+ &key, &direction, &limit) &&
+ !is_key_used(table, key, table->write_set))
+ {
+ *need_sort= FALSE;
+ *reverse= (direction < 0);
+ return key;
+ }
+ }
+ *need_sort= TRUE;
+ return MAX_KEY;
+}
+
+
+/**
@} (end of group Query_Optimizer)
*/
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 2c44dba74c3..0496870bb3f 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -847,4 +847,12 @@ inline bool optimizer_flag(THD *thd, uint flag)
return (thd->variables.optimizer_switch & flag);
}
+uint get_index_for_order(ORDER *order, TABLE *table, SQL_SELECT *select,
+ ha_rows limit, bool *need_sort, bool *reverse);
+ORDER *simple_remove_const(ORDER *order, COND *where);
+bool const_expression_in_where(COND *cond, Item *comp_item,
+ Field *comp_field= NULL,
+ Item **const_item= NULL);
+
+
#endif /* SQL_SELECT_INCLUDED */
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 90aa39fecb4..8a60dd730a3 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -1353,7 +1353,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
packet->append(STRING_WITH_LEN(" /*!50100 TABLESPACE "));
packet->append(for_str, strlen(for_str));
packet->append(STRING_WITH_LEN(" STORAGE DISK */"));
- my_free(for_str, MYF(0));
+ my_free(for_str);
}
/*
@@ -1495,7 +1495,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
table->part_info->set_show_version_string(packet);
packet->append(part_syntax, part_syntax_len);
packet->append(STRING_WITH_LEN(" */"));
- my_free(part_syntax, MYF(0));
+ my_free(part_syntax);
}
}
#endif
@@ -3347,7 +3347,7 @@ static int fill_schema_table_from_frm(THD *thd, TABLE_LIST *tables,
res= schema_table->process_table(thd, &table_list, table,
res, db_name, table_name);
free_root(&tbl.mem_root, MYF(0));
- my_free((char*) tbl.alias, MYF(MY_ALLOW_ZERO_PTR));
+ my_free((void *) tbl.alias);
}
end_share:
@@ -5400,7 +5400,7 @@ static void store_schema_partitions_record(THD *thd, TABLE *schema_table,
if(ts)
{
table->field[24]->store(ts, strlen(ts), cs);
- my_free(ts, MYF(0));
+ my_free(ts);
}
else
table->field[24]->set_null();
@@ -7495,7 +7495,7 @@ int initialize_schema_table(st_plugin_int *plugin)
sql_print_error("Plugin '%s' init function returned error.",
plugin->name.str);
plugin->data= NULL;
- my_free(schema_table, MYF(0));
+ my_free(schema_table);
DBUG_RETURN(1);
}
@@ -7518,7 +7518,7 @@ int finalize_schema_table(st_plugin_int *plugin)
DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
plugin->name.str));
}
- my_free(schema_table, MYF(0));
+ my_free(schema_table);
}
DBUG_RETURN(0);
}
diff --git a/sql/sql_string.h b/sql/sql_string.h
index debfb7aa9c6..0ce67108423 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -205,7 +205,7 @@ public:
{
alloced=0;
Alloced_length=0;
- my_free(Ptr,MYF(0));
+ my_free(Ptr);
Ptr=0;
str_length=0; /* Safety */
}
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 902e7fa7b5f..fa9f9b7f633 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1534,13 +1534,13 @@ void release_ddl_log()
while (used_list)
{
DDL_LOG_MEMORY_ENTRY *tmp= used_list->next_log_entry;
- my_free(used_list, MYF(0));
+ my_free(used_list);
used_list= tmp;
}
while (free_list)
{
DDL_LOG_MEMORY_ENTRY *tmp= free_list->next_log_entry;
- my_free(free_list, MYF(0));
+ my_free(free_list);
free_list= tmp;
}
close_ddl_log();
@@ -1696,8 +1696,8 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
if (readfrm(shadow_path, &data, &length) ||
packfrm(data, length, &lpt->pack_frm_data, &lpt->pack_frm_len))
{
- my_free(data, MYF(MY_ALLOW_ZERO_PTR));
- my_free(lpt->pack_frm_data, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(data);
+ my_free(lpt->pack_frm_data);
mem_alloc_error(length);
error= 1;
goto end;
@@ -2202,7 +2202,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
if (some_tables_deleted || tmp_table_deleted || !error)
{
query_cache_invalidate3(thd, tables, 0);
- if (!dont_log_query)
+ if (!dont_log_query && mysql_bin_log.is_open())
{
if (!thd->is_current_stmt_binlog_format_row() ||
(non_temp_tables_count > 0 && !tmp_table_deleted))
@@ -4882,6 +4882,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
if (wait_while_table_is_used(thd, table->table,
HA_EXTRA_PREPARE_FOR_RENAME))
goto err;
+ DEBUG_SYNC(thd, "after_admin_flush");
/* Flush entries in the query cache involving this table. */
query_cache_invalidate3(thd, table->table, 0);
/*
@@ -4929,6 +4930,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
*/
if (thd->stmt_da->is_ok())
thd->stmt_da->reset_diagnostics_area();
+ table->table= NULL;
+ result_code= result_code ? HA_ADMIN_FAILED : HA_ADMIN_OK;
goto send_result;
}
}
@@ -5059,6 +5062,7 @@ send_result_message:
trans_commit_stmt(thd);
trans_commit(thd);
close_thread_tables(thd);
+ table->table= NULL;
thd->mdl_context.release_transactional_locks();
if (!result_code) // recreation went ok
{
@@ -5149,7 +5153,11 @@ send_result_message:
{
if (table->table->s->tmp_table)
{
- if (open_for_modify)
+ /*
+ If the table was not opened successfully, do not try to get
+ status information. (Bug#47633)
+ */
+ if (open_for_modify && !open_error)
table->table->file->info(HA_STATUS_CONST);
}
else if (open_for_modify || fatal_error)
@@ -7526,7 +7534,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (t_table)
{
intern_close_table(t_table);
- my_free(t_table, MYF(0));
+ my_free(t_table);
}
else
sql_print_warning("Could not open table %s.%s after rename\n",
diff --git a/sql/sql_test.cc b/sql/sql_test.cc
index 48fd5f9dff8..501c4cf6a94 100644
--- a/sql/sql_test.cc
+++ b/sql/sql_test.cc
@@ -555,11 +555,6 @@ Next alarm time: %lu\n",
#endif
display_table_locks();
fflush(stdout);
- my_checkmalloc();
- fprintf(stdout,"\nBegin safemalloc memory dump:\n"); // tag needed for test suite
- TERMINATE(stdout, 1); // Write malloc information
- fprintf(stdout,"\nEnd safemalloc memory dump.\n");
- fflush(stdout);
#ifdef HAVE_MALLINFO
struct mallinfo info= mallinfo();
printf("\nMemory status:\n\
diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc
index 901ab8e987d..c2482ef1ce0 100644
--- a/sql/sql_truncate.cc
+++ b/sql/sql_truncate.cc
@@ -216,7 +216,7 @@ static bool recreate_temporary_table(THD *thd, TABLE *table)
rm_temporary_table(table_type, share->path.str);
free_table_share(share);
- my_free(table, MYF(0));
+ my_free(table);
DBUG_RETURN(error);
}
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 127368cef5c..25c1fd6fa1e 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -203,12 +203,13 @@ int mysql_update(THD *thd,
{
bool using_limit= limit != HA_POS_ERROR;
bool safe_update= test(thd->variables.option_bits & OPTION_SAFE_UPDATES);
- bool used_key_is_modified, transactional_table, will_batch;
+ bool used_key_is_modified= FALSE, transactional_table, will_batch;
bool can_compare_record;
int res;
int error, loc_error;
- uint used_index= MAX_KEY, dup_key_found;
+ uint used_index, dup_key_found;
bool need_sort= TRUE;
+ bool reverse= FALSE;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
uint want_privilege;
#endif
@@ -358,11 +359,7 @@ int mysql_update(THD *thd,
my_ok(thd); // No matching records
DBUG_RETURN(0);
}
- if (!select && limit != HA_POS_ERROR)
- {
- if ((used_index= get_index_for_order(table, order, limit)) != MAX_KEY)
- need_sort= FALSE;
- }
+
/* If running in safe sql mode, don't allow updates without keys */
if (table->quick_keys.is_clear_all())
{
@@ -378,24 +375,20 @@ int mysql_update(THD *thd,
table->mark_columns_needed_for_update();
- /* Check if we are modifying a key that we are used to search with */
-
- if (select && select->quick)
- {
- used_index= select->quick->index;
- used_key_is_modified= (!select->quick->unique_key_range() &&
- select->quick->is_keys_used(table->write_set));
+ table->update_const_key_parts(conds);
+ order= simple_remove_const(order, conds);
+
+ used_index= get_index_for_order(order, table, select, limit,
+ &need_sort, &reverse);
+ if (need_sort)
+ { // Assign table scan index to check below for modified key fields:
+ used_index= table->file->key_used_on_scan;
}
- else
- {
- used_key_is_modified= 0;
- if (used_index == MAX_KEY) // no index for sort order
- used_index= table->file->key_used_on_scan;
- if (used_index != MAX_KEY)
- used_key_is_modified= is_key_used(table, used_index, table->write_set);
+ if (used_index != MAX_KEY)
+ { // Check if we are modifying a key that we are used to search with:
+ used_key_is_modified= is_key_used(table, used_index, table->write_set);
}
-
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (used_key_is_modified || order ||
partition_key_modified(table, table->write_set))
@@ -414,7 +407,7 @@ int mysql_update(THD *thd,
table->use_all_columns();
}
- /* note: We avoid sorting avoid if we sort on the used index */
+ /* note: We avoid sorting if we sort on the used index */
if (order && (need_sort || used_key_is_modified))
{
/*
@@ -476,7 +469,7 @@ int mysql_update(THD *thd,
if (used_index == MAX_KEY || (select && select->quick))
init_read_record(&info, thd, table, select, 0, 1, FALSE);
else
- init_read_record_idx(&info, thd, table, 1, used_index);
+ init_read_record_idx(&info, thd, table, 1, used_index, reverse);
thd_proc_info(thd, "Searching rows for update");
ha_rows tmp_limit= limit;
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 7eb9a72273b..53b07371baa 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -875,7 +875,7 @@ static Sys_var_uint Sys_large_page_size(
static Sys_var_mybool Sys_large_pages(
"large_pages", "Enable support for large pages",
- READ_ONLY GLOBAL_VAR(opt_large_files),
+ READ_ONLY GLOBAL_VAR(opt_large_pages),
IF_WIN(NO_CMD_LINE, CMD_LINE(OPT_ARG)), DEFAULT(FALSE));
static Sys_var_charptr Sys_language(
@@ -1630,7 +1630,7 @@ static Sys_var_ulong Sys_thread_stack(
static Sys_var_charptr Sys_tmpdir(
"tmpdir", "Path for temporary files. Several paths may "
"be specified, separated by a "
-#if defined(__WIN__) || defined(__NETWARE__)
+#if defined(__WIN__)
"semicolon (;)"
#else
"colon (:)"
@@ -2379,7 +2379,7 @@ static Sys_var_harows Sys_select_limit(
"sql_select_limit",
"The maximum number of rows to return from SELECT statements",
SESSION_VAR(select_limit), NO_CMD_LINE,
- VALID_RANGE(1, HA_POS_ERROR), DEFAULT(HA_POS_ERROR), BLOCK_SIZE(1));
+ VALID_RANGE(0, HA_POS_ERROR), DEFAULT(HA_POS_ERROR), BLOCK_SIZE(1));
static bool update_timestamp(THD *thd, set_var *var)
{
diff --git a/sql/sys_vars.h b/sql/sys_vars.h
index fbc48573487..18c073b1e90 100644
--- a/sql/sys_vars.h
+++ b/sql/sys_vars.h
@@ -388,7 +388,7 @@ public:
~Sys_var_charptr()
{
if (flags & ALLOCATED)
- my_free(global_var(char*), MYF(MY_ALLOW_ZERO_PTR));
+ my_free(global_var(char*));
flags&= ~ALLOCATED;
}
bool do_check(THD *thd, set_var *var)
@@ -435,7 +435,7 @@ public:
else
new_val= 0;
if (flags & ALLOCATED)
- my_free(global_var(char*), MYF(MY_ALLOW_ZERO_PTR));
+ my_free(global_var(char*));
flags|= ALLOCATED;
global_var(char*)= new_val;
return false;
diff --git a/sql/table.cc b/sql/table.cc
index dbd657bee67..a58623f0036 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -33,6 +33,7 @@
#include "sql_base.h" // release_table_share
#include <m_ctype.h>
#include "my_md5.h"
+#include "sql_select.h"
/* INFORMATION_SCHEMA name */
LEX_STRING INFORMATION_SCHEMA_NAME= {C_STRING_WITH_LEN("information_schema")};
@@ -895,7 +896,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
if (mysql_file_pread(file, buff, n_length, record_offset + share->reclength,
MYF(MY_NABP)))
{
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
share->connect_string.length= uint2korr(buff);
@@ -904,7 +905,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
share->connect_string.
length)))
{
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
next_chunk+= share->connect_string.length + 2;
@@ -925,7 +926,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
plugin_data(tmp_plugin, handlerton *)))
{
/* bad file, legacy_db_type did not match the name */
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
/*
@@ -955,7 +956,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
error= 8;
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
"--skip-partition");
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
plugin_unlock(NULL, share->db_plugin);
@@ -971,7 +972,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
error= 8;
name.str[name.length]=0;
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name.str);
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
/* purecov: end */
}
@@ -988,7 +989,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
memdup_root(&share->mem_root, next_chunk + 4,
partition_info_str_len + 1)))
{
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
}
@@ -996,7 +997,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
if (partition_info_str_len)
{
DBUG_PRINT("info", ("WITH_PARTITION_STORAGE_ENGINE is not defined"));
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
#endif
@@ -1034,7 +1035,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
{
DBUG_PRINT("error",
("fulltext key uses parser that is not defined in .frm"));
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
parser_name.str= (char*) next_chunk;
@@ -1045,7 +1046,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
if (! keyinfo->parser)
{
my_error(ER_PLUGIN_IS_NOT_LOADED, MYF(0), parser_name.str);
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
}
@@ -1057,19 +1058,19 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
{
DBUG_PRINT("error",
("long table comment is not defined in .frm"));
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
share->comment.length = uint2korr(next_chunk);
if (! (share->comment.str= strmake_root(&share->mem_root,
(char*)next_chunk + 2, share->comment.length)))
{
- my_free(buff, MYF(0));
+ my_free(buff);
goto err;
}
next_chunk+= 2 + share->comment.length;
}
- my_free(buff, MYF(0));
+ my_free(buff);
}
share->key_block_size= uint2korr(head+62);
@@ -1585,7 +1586,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
}
else
share->primary_key= MAX_KEY;
- x_free((uchar*) disk_buff);
+ my_free(disk_buff);
disk_buff=0;
if (new_field_pack_flag <= 1)
{
@@ -1657,7 +1658,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
share->error= error;
share->open_errno= my_errno;
share->errarg= errarg;
- x_free((uchar*) disk_buff);
+ my_free(disk_buff);
delete crypted;
delete handler_file;
my_hash_free(&share->name_hash);
@@ -2009,7 +2010,7 @@ partititon_err:
outparam->file= 0; // For easier error checking
outparam->db_stat=0;
free_root(&outparam->mem_root, MYF(0)); // Safe to call on bzero'd root
- my_free((char*) outparam->alias, MYF(MY_ALLOW_ZERO_PTR));
+ my_free((void *) outparam->alias);
DBUG_RETURN (error);
}
@@ -2031,7 +2032,7 @@ int closefrm(register TABLE *table, bool free_share)
if (table->db_stat)
error=table->file->close();
- my_free((char*) table->alias, MYF(MY_ALLOW_ZERO_PTR));
+ my_free((void *) table->alias);
table->alias= 0;
if (table->field)
{
@@ -2126,14 +2127,14 @@ static ulong get_form_pos(File file, uchar *head)
if (mysql_file_read(file, buf, length+names*4, MYF(MY_NABP)))
{
- x_free(buf);
+ my_free(buf);
DBUG_RETURN(0);
}
pos= buf+length;
ret_value= uint4korr(pos);
- my_free(buf, MYF(0));
+ my_free(buf);
DBUG_RETURN(ret_value);
}
@@ -2150,11 +2151,11 @@ int read_string(File file, uchar**to, size_t length)
{
DBUG_ENTER("read_string");
- x_free(*to);
+ my_free(*to);
if (!(*to= (uchar*) my_malloc(length+1,MYF(MY_WME))) ||
mysql_file_read(file, *to, length, MYF(MY_NABP)))
{
- x_free(*to); /* purecov: inspected */
+ my_free(*to); /* purecov: inspected */
*to= 0; /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
@@ -4916,6 +4917,61 @@ void init_mdl_requests(TABLE_LIST *table_list)
}
+/**
+ Update TABLE::const_key_parts for single table UPDATE/DELETE query
+
+ @param conds WHERE clause expression
+
+ @retval TRUE error (OOM)
+ @retval FALSE success
+
+ @note
+ Set const_key_parts bits if key fields are equal to constants in
+ the WHERE expression.
+*/
+
+bool TABLE::update_const_key_parts(COND *conds)
+{
+ bzero((char*) const_key_parts, sizeof(key_part_map) * s->keys);
+
+ if (conds == NULL)
+ return FALSE;
+
+ for (uint index= 0; index < s->keys; index++)
+ {
+ KEY_PART_INFO *keyinfo= key_info[index].key_part;
+ KEY_PART_INFO *keyinfo_end= keyinfo + key_info[index].key_parts;
+
+ for (key_part_map part_map= (key_part_map)1;
+ keyinfo < keyinfo_end;
+ keyinfo++, part_map<<= 1)
+ {
+ if (const_expression_in_where(conds, NULL, keyinfo->field))
+ const_key_parts[index]|= part_map;
+ }
+ }
+ return FALSE;
+}
+
+/**
+ Test if the order list consists of simple field expressions
+
+ @param order Linked list of ORDER BY arguments
+
+ @return TRUE if @a order is empty or consist of simple field expressions
+*/
+
+bool is_simple_order(ORDER *order)
+{
+ for (ORDER *ord= order; ord; ord= ord->next)
+ {
+ if (ord->item[0]->real_item()->type() != Item::FIELD_ITEM)
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
/*****************************************************************************
** Instansiate templates
*****************************************************************************/
diff --git a/sql/table.h b/sql/table.h
index 08b9a6e0a01..2bf390aee4d 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -1104,6 +1104,8 @@ public:
file->extra(HA_EXTRA_NO_KEYREAD);
}
}
+
+ bool update_const_key_parts(COND *conds);
};
@@ -2088,6 +2090,8 @@ inline void mark_as_null_row(TABLE *table)
bfill(table->null_flags,table->s->null_bytes,255);
}
+bool is_simple_order(ORDER *order);
+
#endif /* MYSQL_CLIENT */
#endif /* TABLE_INCLUDED */
diff --git a/sql/transaction.cc b/sql/transaction.cc
index 78551d6fcf7..f6786f20dcf 100644
--- a/sql/transaction.cc
+++ b/sql/transaction.cc
@@ -419,9 +419,13 @@ bool trans_rollback_to_savepoint(THD *thd, LEX_STRING name)
thd->transaction.savepoints= sv;
/*
- Release metadata locks that were acquired during this savepoint unit.
+ Release metadata locks that were acquired during this savepoint unit
+ unless binlogging is on. Releasing locks with binlogging on can break
+ replication as it allows other connections to drop these tables before
+ rollback to savepoint is written to the binlog.
*/
- if (!res)
+ bool binlog_on= mysql_bin_log.is_open() && thd->variables.sql_log_bin;
+ if (!res && !binlog_on)
thd->mdl_context.rollback_to_savepoint(sv->mdl_savepoint);
DBUG_RETURN(test(res));
diff --git a/sql/tztime.cc b/sql/tztime.cc
index 79f3b83553e..af8574c38f1 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -2551,7 +2551,6 @@ scan_tz_dir(char * name_end)
int
main(int argc, char **argv)
{
-#ifndef __NETWARE__
MY_INIT(argv[0]);
if (argc != 2 && argc != 3)
@@ -2610,10 +2609,6 @@ main(int argc, char **argv)
free_root(&tz_storage, MYF(0));
}
-#else
- fprintf(stderr, "This tool has not been ported to NetWare\n");
-#endif /* __NETWARE__ */
-
return 0;
}
diff --git a/sql/uniques.cc b/sql/uniques.cc
index 7b5a6d1ce4f..690b310bde5 100644
--- a/sql/uniques.cc
+++ b/sql/uniques.cc
@@ -566,7 +566,7 @@ bool Unique::walk(tree_walk_action action, void *walk_action_arg)
(BUFFPEK *) file_ptrs.buffer + file_ptrs.elements,
action, walk_action_arg,
tree.compare, tree.custom_arg, &file);
- my_free((char*) merge_buffer, MYF(0));
+ my_free(merge_buffer);
return res;
}
@@ -642,7 +642,7 @@ bool Unique::get(TABLE *table)
goto err;
error=0;
err:
- x_free(sort_buffer);
+ my_free(sort_buffer);
if (flush_io_cache(outfile))
error=1;
diff --git a/sql/unireg.cc b/sql/unireg.cc
index 802e5b7429c..6433b8bc7c2 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -148,7 +148,7 @@ bool mysql_create_frm(THD *thd, const char *file_name,
if (error)
{
- my_free(screen_buff, MYF(0));
+ my_free(screen_buff);
if (! pack_header_error_handler.is_handled)
DBUG_RETURN(1);
@@ -159,7 +159,7 @@ bool mysql_create_frm(THD *thd, const char *file_name,
create_fields,info_length,
screens, create_info->table_options, data_offset, db_file))
{
- my_free(screen_buff, MYF(0));
+ my_free(screen_buff);
DBUG_RETURN(1);
}
}
@@ -228,7 +228,7 @@ bool mysql_create_frm(THD *thd, const char *file_name,
{
my_error(ER_TOO_LONG_TABLE_COMMENT, MYF(0),
real_table_name, (uint) TABLE_COMMENT_MAXLEN);
- my_free(screen_buff,MYF(0));
+ my_free(screen_buff);
DBUG_RETURN(1);
}
char warn_buff[MYSQL_ERRMSG_SIZE];
@@ -259,7 +259,7 @@ bool mysql_create_frm(THD *thd, const char *file_name,
if ((file=create_frm(thd, file_name, db, table, reclength, fileinfo,
create_info, keys, key_info)) < 0)
{
- my_free(screen_buff, MYF(0));
+ my_free(screen_buff);
DBUG_RETURN(1);
}
@@ -374,15 +374,15 @@ bool mysql_create_frm(THD *thd, const char *file_name,
delete crypted;
if (mysql_file_pwrite(file, disk_buff, read_length, filepos+256, MYF_RW))
{
- my_free(disk_buff,MYF(0));
+ my_free(disk_buff);
goto err;
}
- my_free(disk_buff,MYF(0));
+ my_free(disk_buff);
}
#endif
- my_free(screen_buff,MYF(0));
- my_free(keybuff, MYF(0));
+ my_free(screen_buff);
+ my_free(keybuff);
if (opt_sync_frm && !(create_info->options & HA_LEX_CREATE_TMP_TABLE) &&
(mysql_file_sync(file, MYF(MY_WME)) ||
@@ -411,8 +411,8 @@ bool mysql_create_frm(THD *thd, const char *file_name,
DBUG_RETURN(0);
err:
- my_free(screen_buff, MYF(0));
- my_free(keybuff, MYF(0));
+ my_free(screen_buff);
+ my_free(keybuff);
err2:
(void) mysql_file_close(file, MYF(MY_WME));
err3:
@@ -1095,7 +1095,7 @@ static bool make_empty_rec(THD *thd, File file,enum legacy_db_type table_type,
error= mysql_file_write(file, buff, (size_t) reclength, MYF_RW) != 0;
err:
- my_free(buff, MYF(MY_FAE));
+ my_free(buff);
thd->count_cuted_fields= old_count_cuted_fields;
DBUG_RETURN(error);
} /* make_empty_rec */