Commit fdde665e authored by unknown's avatar unknown

WL 1682: Bitvector for updated/read fields in handler interface

Fixed clear issues of bitvector and memory allocation issues


sql/bitvector.cc:
  Made bitvector memroot class
sql/bitvector.h:
  Made bitvector memroot class
sql/handler.cc:
  Need to add updated fields to read set to ensure that they are
  updated since the update code doesn't update if records haven't
  changed
  Added DBUG printout's
sql/handler.h:
  Moved clear of bitvector's to reset function
  Introduced ha_reset for this purpose to ensure that it isn't
  necessary to perform this clear in all handlers.
sql/lock.cc:
  Removed clear that has been moved to ha_reset
sql/opt_range.cc:
  Changed reset to ha_reset
  Added delete file
sql/sql_base.cc:
  Removed clear and changed reset to ha_reset
sql/sql_insert.cc:
  Removed clear and changed reset to ha_reset
sql/sql_select.cc:
  Made sure delete file is done if needed
sql/sql_table.cc:
  Added delete file in another place needed
sql/sql_update.cc:
  Bug for multi-update fixed
parent dfb2d19f
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "mysql_priv.h"
#include <bitvector.h> #include <bitvector.h>
void bitvector::create_last_word_mask() void bitvector::create_last_word_mask()
...@@ -68,7 +69,7 @@ int bitvector::init(size_t size) ...@@ -68,7 +69,7 @@ int bitvector::init(size_t size)
DBUG_ASSERT(size < MYSQL_NO_BIT_FOUND); DBUG_ASSERT(size < MYSQL_NO_BIT_FOUND);
DBUG_ASSERT(size > 0); DBUG_ASSERT(size > 0);
m_size= 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));
if (m_data) if (m_data)
{ {
create_last_word_mask(); create_last_word_mask();
......
...@@ -70,7 +70,7 @@ namespace ...@@ -70,7 +70,7 @@ namespace
/* Number returned when no bit found */ /* Number returned when no bit found */
#define MYSQL_NO_BIT_FOUND 1 << 20 #define MYSQL_NO_BIT_FOUND 1 << 20
class bitvector class bitvector :public Sql_alloc
{ {
private: private:
/* Compute the number of bytes required to store 'bits' bits in an array. */ /* Compute the number of bytes required to store 'bits' bits in an array. */
...@@ -100,7 +100,7 @@ class bitvector ...@@ -100,7 +100,7 @@ class bitvector
explicit bitvector(size_t size, bool value= false) explicit bitvector(size_t size, bool value= false)
: m_size(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); DBUG_ASSERT(size < MYSQL_NO_BIT_FOUND);
create_last_word_mask(); create_last_word_mask();
...@@ -115,7 +115,7 @@ class bitvector ...@@ -115,7 +115,7 @@ class bitvector
*/ */
explicit bitvector(byte const* data, size_t size) explicit bitvector(byte const* data, size_t size)
: m_size(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); DBUG_ASSERT(size < MYSQL_NO_BIT_FOUND);
create_last_word_mask(); create_last_word_mask();
...@@ -125,7 +125,7 @@ class bitvector ...@@ -125,7 +125,7 @@ class bitvector
bitvector(bitvector const& other) bitvector(bitvector const& other)
: m_size(other.size()), : 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); DBUG_ASSERT(m_size < MYSQL_NO_BIT_FOUND);
create_last_word_mask(); create_last_word_mask();
...@@ -133,11 +133,7 @@ class bitvector ...@@ -133,11 +133,7 @@ class bitvector
tidy_last_word(); tidy_last_word();
} }
~bitvector() ~bitvector() {}
{
if (m_data)
my_free((char*)m_data, MYF(0));
}
/* /*
Allocate memory to the bitvector and create last word mask Allocate memory to the bitvector and create last word mask
......
...@@ -1443,12 +1443,13 @@ void handler::ha_set_bit_in_rw_set(uint fieldnr, bool write_op) ...@@ -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"); DBUG_ENTER("ha_set_bit_in_rw_set");
if (!write_op) { 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); read_set->set_bit((size_t)fieldnr);
} }
else 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); write_set->set_bit((size_t)fieldnr);
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
...@@ -443,6 +443,8 @@ class handler :public Sql_alloc ...@@ -443,6 +443,8 @@ class handler :public Sql_alloc
virtual int rnd_init(bool scan) =0; virtual int rnd_init(bool scan) =0;
virtual int rnd_end() { return 0; } virtual int rnd_end() { return 0; }
private:
virtual int reset() { return extra(HA_EXTRA_RESET); }
public: public:
byte *ref; /* Pointer to current row */ byte *ref; /* Pointer to current row */
byte *dupp_ref; /* Pointer to dupp row */ byte *dupp_ref; /* Pointer to dupp row */
...@@ -562,6 +564,13 @@ class handler :public Sql_alloc ...@@ -562,6 +564,13 @@ class handler :public Sql_alloc
inited=NONE; inited=NONE;
DBUG_RETURN(rnd_end()); 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 */ /* this is necessary in many places, e.g. in HANDLER command */
int ha_index_or_rnd_end() int ha_index_or_rnd_end()
{ {
...@@ -664,7 +673,6 @@ class handler :public Sql_alloc ...@@ -664,7 +673,6 @@ class handler :public Sql_alloc
{ return 0; } { return 0; }
virtual int extra_opt(enum ha_extra_function operation, ulong cache_size) virtual int extra_opt(enum ha_extra_function operation, ulong cache_size)
{ return extra(operation); } { return extra(operation); }
virtual int reset() { return extra(HA_EXTRA_RESET); }
virtual int external_lock(THD *thd, int lock_type) { return 0; } virtual int external_lock(THD *thd, int lock_type) { return 0; }
virtual void unlock_row() {} virtual void unlock_row() {}
virtual int start_stmt(THD *thd) {return 0;} virtual int start_stmt(THD *thd) {return 0;}
......
...@@ -179,7 +179,6 @@ static int lock_external(THD *thd, TABLE **tables, uint count) ...@@ -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 &&
(*tables)->reginfo.lock_type <= TL_READ_NO_INSERT)) (*tables)->reginfo.lock_type <= TL_READ_NO_INSERT))
lock_type=F_RDLCK; lock_type=F_RDLCK;
(*tables)->file->ha_clear_all_set();
if ((error=(*tables)->file->external_lock(thd,lock_type))) if ((error=(*tables)->file->external_lock(thd,lock_type)))
{ {
print_lock_error(error, (*tables)->file->table_type()); print_lock_error(error, (*tables)->file->table_type());
......
...@@ -778,9 +778,10 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT() ...@@ -778,9 +778,10 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT()
{ {
DBUG_PRINT("info", ("Freeing separate handler %p (free=%d)", file, DBUG_PRINT("info", ("Freeing separate handler %p (free=%d)", file,
free_file)); free_file));
file->reset(); file->ha_reset();
file->external_lock(current_thd, F_UNLCK); file->external_lock(current_thd, F_UNLCK);
file->close(); file->close();
delete file;
} }
} }
delete_dynamic(&ranges); /* ranges are allocated in alloc */ delete_dynamic(&ranges); /* ranges are allocated in alloc */
...@@ -956,6 +957,8 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) ...@@ -956,6 +957,8 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler)
DBUG_RETURN(0); DBUG_RETURN(0);
failure: failure:
if (file)
delete file;
file= save_file; file= save_file;
DBUG_RETURN(1); DBUG_RETURN(1);
} }
......
...@@ -563,7 +563,7 @@ bool close_thread_table(THD *thd, TABLE **table_ptr) ...@@ -563,7 +563,7 @@ bool close_thread_table(THD *thd, TABLE **table_ptr)
else else
{ {
// Free memory and reset for next loop // Free memory and reset for next loop
table->file->reset(); table->file->ha_reset();
} }
table->in_use=0; table->in_use=0;
if (unused_tables) if (unused_tables)
...@@ -1954,7 +1954,6 @@ static bool check_lock_and_start_stmt(THD *thd, TABLE *table, ...@@ -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); my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->alias);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
table->file->ha_clear_all_set();
if ((error=table->file->start_stmt(thd))) if ((error=table->file->start_stmt(thd)))
{ {
table->file->print_error(error,MYF(0)); table->file->print_error(error,MYF(0));
......
...@@ -1959,7 +1959,7 @@ select_insert::~select_insert() ...@@ -1959,7 +1959,7 @@ select_insert::~select_insert()
if (table) if (table)
{ {
table->next_number_field=0; table->next_number_field=0;
table->file->reset(); table->file->ha_reset();
} }
thd->count_cuted_fields= CHECK_FIELD_IGNORE; thd->count_cuted_fields= CHECK_FIELD_IGNORE;
thd->abort_on_warning= 0; thd->abort_on_warning= 0;
......
...@@ -8870,8 +8870,8 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, ...@@ -8870,8 +8870,8 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
(void) new_table.file->close(); (void) new_table.file->close();
err1: err1:
new_table.file->delete_table(new_table.s->table_name); new_table.file->delete_table(new_table.s->table_name);
delete new_table.file;
err2: err2:
delete new_table.file;
thd->proc_info=save_proc_info; thd->proc_info=save_proc_info;
DBUG_RETURN(1); DBUG_RETURN(1);
} }
......
...@@ -1633,6 +1633,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, ...@@ -1633,6 +1633,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
end: end:
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
start_waiting_global_read_lock(thd); start_waiting_global_read_lock(thd);
delete file;
thd->proc_info="After create"; thd->proc_info="After create";
DBUG_RETURN(error); DBUG_RETURN(error);
} }
......
...@@ -652,7 +652,7 @@ bool mysql_multi_update_prepare(THD *thd) ...@@ -652,7 +652,7 @@ bool mysql_multi_update_prepare(THD *thd)
leaves= lex->select_lex.leaf_tables; leaves= lex->select_lex.leaf_tables;
if ((lex->select_lex.no_wrap_view_item= 1, 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, lex->select_lex.no_wrap_view_item= 0,
res)) res))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
...@@ -769,7 +769,7 @@ bool mysql_multi_update_prepare(THD *thd) ...@@ -769,7 +769,7 @@ bool mysql_multi_update_prepare(THD *thd)
if (setup_tables(thd, table_list, &lex->select_lex.where, if (setup_tables(thd, table_list, &lex->select_lex.where,
&lex->select_lex.leaf_tables, FALSE, FALSE) || &lex->select_lex.leaf_tables, FALSE, FALSE) ||
(lex->select_lex.no_wrap_view_item= 1, (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, lex->select_lex.no_wrap_view_item= 0,
res)) res))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment