diff --git a/sql/bitvector.cc b/sql/bitvector.cc index 861cff2c9bb..0fcae84abc2 100644 --- a/sql/bitvector.cc +++ b/sql/bitvector.cc @@ -16,6 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "mysql_priv.h" #include void bitvector::create_last_word_mask() @@ -68,7 +69,7 @@ int bitvector::init(size_t size) DBUG_ASSERT(size < MYSQL_NO_BIT_FOUND); DBUG_ASSERT(size > 0); m_size= size; - m_data= (uchar*)my_malloc(byte_size_word_aligned(size), MYF(0)); + m_data= (uchar*)sql_alloc(byte_size_word_aligned(size)); if (m_data) { create_last_word_mask(); diff --git a/sql/bitvector.h b/sql/bitvector.h index 2a33e1858f1..f08f782879f 100644 --- a/sql/bitvector.h +++ b/sql/bitvector.h @@ -70,7 +70,7 @@ namespace /* Number returned when no bit found */ #define MYSQL_NO_BIT_FOUND 1 << 20 -class bitvector +class bitvector :public Sql_alloc { private: /* Compute the number of bytes required to store 'bits' bits in an array. */ @@ -100,7 +100,7 @@ public: explicit bitvector(size_t size, bool value= false) : m_size(size), - m_data((uchar*)my_malloc(byte_size_word_aligned(size), MYF(0))) + m_data((uchar*)sql_alloc(byte_size_word_aligned(size))) { DBUG_ASSERT(size < MYSQL_NO_BIT_FOUND); create_last_word_mask(); @@ -115,7 +115,7 @@ public: */ explicit bitvector(byte const* data, size_t size) : m_size(size), - m_data((uchar*)my_malloc(byte_size_word_aligned(size), MYF(0))) + m_data((uchar*)sql_alloc(byte_size_word_aligned(size))) { DBUG_ASSERT(size < MYSQL_NO_BIT_FOUND); create_last_word_mask(); @@ -125,7 +125,7 @@ public: bitvector(bitvector const& other) : m_size(other.size()), - m_data((uchar*)my_malloc(other.bytes(), MYF(0))) + m_data((uchar*)sql_alloc(other.bytes())) { DBUG_ASSERT(m_size < MYSQL_NO_BIT_FOUND); create_last_word_mask(); @@ -133,11 +133,7 @@ public: tidy_last_word(); } - ~bitvector() - { - if (m_data) - my_free((char*)m_data, MYF(0)); - } + ~bitvector() {} /* Allocate memory to the bitvector and create last word mask diff --git a/sql/handler.cc b/sql/handler.cc index 229fe4ccc18..97e2a790a2d 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1443,12 +1443,13 @@ void handler::ha_set_bit_in_rw_set(uint fieldnr, bool write_op) { DBUG_ENTER("ha_set_bit_in_rw_set"); if (!write_op) { - DBUG_PRINT("info", ("Set bit in read set")); + DBUG_PRINT("info", ("Set bit %u in read set", fieldnr)); read_set->set_bit((size_t)fieldnr); } else { - DBUG_PRINT("info", ("Set bit in write set")); + DBUG_PRINT("info", ("Set bit %u in read and write set", fieldnr)); + read_set->set_bit((size_t)fieldnr); write_set->set_bit((size_t)fieldnr); } DBUG_VOID_RETURN; diff --git a/sql/handler.h b/sql/handler.h index 31bd5978e1c..b463e423e86 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -443,6 +443,8 @@ class handler :public Sql_alloc virtual int rnd_init(bool scan) =0; virtual int rnd_end() { return 0; } +private: + virtual int reset() { return extra(HA_EXTRA_RESET); } public: byte *ref; /* Pointer to current row */ byte *dupp_ref; /* Pointer to dupp row */ @@ -562,6 +564,13 @@ public: inited=NONE; DBUG_RETURN(rnd_end()); } + int ha_reset() + { + DBUG_ENTER("ha_reset"); + ha_clear_all_set(); + DBUG_RETURN(reset()); + } + /* this is necessary in many places, e.g. in HANDLER command */ int ha_index_or_rnd_end() { @@ -664,7 +673,6 @@ public: { return 0; } virtual int extra_opt(enum ha_extra_function operation, ulong cache_size) { return extra(operation); } - virtual int reset() { return extra(HA_EXTRA_RESET); } virtual int external_lock(THD *thd, int lock_type) { return 0; } virtual void unlock_row() {} virtual int start_stmt(THD *thd) {return 0;} diff --git a/sql/lock.cc b/sql/lock.cc index bb7d1f7163b..ac527ca84f8 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -179,7 +179,6 @@ static int lock_external(THD *thd, TABLE **tables, uint count) ((*tables)->reginfo.lock_type >= TL_READ && (*tables)->reginfo.lock_type <= TL_READ_NO_INSERT)) lock_type=F_RDLCK; - (*tables)->file->ha_clear_all_set(); if ((error=(*tables)->file->external_lock(thd,lock_type))) { print_lock_error(error, (*tables)->file->table_type()); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index b83e4f369af..fbb7ac80c28 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -778,9 +778,10 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT() { DBUG_PRINT("info", ("Freeing separate handler %p (free=%d)", file, free_file)); - file->reset(); + file->ha_reset(); file->external_lock(current_thd, F_UNLCK); file->close(); + delete file; } } delete_dynamic(&ranges); /* ranges are allocated in alloc */ @@ -956,6 +957,8 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) DBUG_RETURN(0); failure: + if (file) + delete file; file= save_file; DBUG_RETURN(1); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 63fcf2b70b3..7c94b6004be 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -563,7 +563,7 @@ bool close_thread_table(THD *thd, TABLE **table_ptr) else { // Free memory and reset for next loop - table->file->reset(); + table->file->ha_reset(); } table->in_use=0; if (unused_tables) @@ -1954,7 +1954,6 @@ static bool check_lock_and_start_stmt(THD *thd, TABLE *table, my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->alias); DBUG_RETURN(1); } - table->file->ha_clear_all_set(); if ((error=table->file->start_stmt(thd))) { table->file->print_error(error,MYF(0)); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 512fdb90ef9..a3062582367 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1959,7 +1959,7 @@ select_insert::~select_insert() if (table) { table->next_number_field=0; - table->file->reset(); + table->file->ha_reset(); } thd->count_cuted_fields= CHECK_FIELD_IGNORE; thd->abort_on_warning= 0; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 0d5efb99ce6..a9916fbfcf7 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8870,8 +8870,8 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, (void) new_table.file->close(); err1: new_table.file->delete_table(new_table.s->table_name); - delete new_table.file; err2: + delete new_table.file; thd->proc_info=save_proc_info; DBUG_RETURN(1); } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index cb98bba5e4d..37814782018 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1633,6 +1633,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, end: VOID(pthread_mutex_unlock(&LOCK_open)); start_waiting_global_read_lock(thd); + delete file; thd->proc_info="After create"; DBUG_RETURN(error); } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 8cb2cbef684..bd9e230514b 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -652,7 +652,7 @@ bool mysql_multi_update_prepare(THD *thd) leaves= lex->select_lex.leaf_tables; if ((lex->select_lex.no_wrap_view_item= 1, - res= setup_fields(thd, 0, table_list, *fields, 1, 0, 0), + res= setup_fields(thd, 0, table_list, *fields, 2, 0, 0), lex->select_lex.no_wrap_view_item= 0, res)) DBUG_RETURN(TRUE); @@ -769,7 +769,7 @@ bool mysql_multi_update_prepare(THD *thd) if (setup_tables(thd, table_list, &lex->select_lex.where, &lex->select_lex.leaf_tables, FALSE, FALSE) || (lex->select_lex.no_wrap_view_item= 1, - res= setup_fields(thd, 0, table_list, *fields, 1, 0, 0), + res= setup_fields(thd, 0, table_list, *fields, 2, 0, 0), lex->select_lex.no_wrap_view_item= 0, res)) DBUG_RETURN(TRUE);