summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@mishka.local>2004-09-17 03:08:23 +0300
committerunknown <monty@mishka.local>2004-09-17 03:08:23 +0300
commite74b00bbc98c1082086422dc9c8578dade9d4a11 (patch)
treea8b336253346895e427b74008617db6d076f5fa3 /sql
parent6c3e66510c29abb4a935483a711b55f3ff8607ab (diff)
downloadmariadb-git-e74b00bbc98c1082086422dc9c8578dade9d4a11.tar.gz
Removed wrong warnings in test suite (This was because select_insert / select_create results was not freed.
Added thd to openfrm() for initialization of TABLE->in_use. This fixed a bug in BDB handling where table->in_use was used early mysql-test/r/key.result: Added new tests that shows a bug in warnings hat mysql-test/t/key.test: Added new tests that shows a bug in warnings hat sql/handler.cc: Added thd to openfrm() for initialization of TABLE->in_use sql/item.cc: New function to avoid warnings when giving field a value sql/item.h: New function to avoid warnings when giving field a value sql/mysql_priv.h: Added thd to openfrm() for initialization of TABLE->in_use sql/opt_range.cc: Don't give warnings in optimizer when internally storing a field value in a field. (Should be ok as we ar checking the feild in the WHERE clause later) sql/sql_base.cc: Give memroot explicitely to open_unireg_entry() and open_table() (Makes code simpler) Ensure that table->in_use is set early New arguments for openfrm() sql/sql_insert.cc: More debugging & comments sql/sql_parse.cc: Delete results for select_insert and select_create. This fixed a bug that generated warnings in test suite sql/sql_select.h: Don't give warnings in optimizer when internally storing a field value in a field. (Should be ok as we ar checking the feild in the WHERE clause later) sql/sql_table.cc: New arguments to open_table() and openfrm() sql/table.cc: Added thd to openfrm() for initialization of TABLE->in_use This fixes some bugs in BDB where table->in_use was used
Diffstat (limited to 'sql')
-rw-r--r--sql/handler.cc2
-rw-r--r--sql/item.cc12
-rw-r--r--sql/item.h1
-rw-r--r--sql/mysql_priv.h4
-rw-r--r--sql/opt_range.cc2
-rw-r--r--sql/sql_base.cc23
-rw-r--r--sql/sql_insert.cc5
-rw-r--r--sql/sql_parse.cc4
-rw-r--r--sql/sql_select.h2
-rw-r--r--sql/sql_table.cc6
-rw-r--r--sql/table.cc7
11 files changed, 43 insertions, 25 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index c3513ad819f..5f1e36d636a 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1362,7 +1362,7 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info,
char name_buff[FN_REFLEN];
DBUG_ENTER("ha_create_table");
- if (openfrm(name,"",0,(uint) READ_ALL, 0, &table))
+ if (openfrm(current_thd, name,"",0,(uint) READ_ALL, 0, &table))
DBUG_RETURN(1);
if (update_create_info)
{
diff --git a/sql/item.cc b/sql/item.cc
index cbb760156b3..3953aecaa08 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -282,6 +282,18 @@ CHARSET_INFO *Item::default_charset()
}
+int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
+{
+ int res;
+ THD *thd= field->table->in_use;
+ enum_check_fields tmp= thd->count_cuted_fields;
+ thd->count_cuted_fields= CHECK_FIELD_IGNORE;
+ res= save_in_field(field, no_conversions);
+ thd->count_cuted_fields= tmp;
+ return res;
+}
+
+
Item *
Item_splocal::this_item()
{
diff --git a/sql/item.h b/sql/item.h
index a237e7ce6f5..8608f2916a9 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -152,6 +152,7 @@ public:
*/
inline void quick_fix_field() { fixed= 1; }
/* Function returns 1 on overflow and -1 on fatal errors */
+ int save_in_field_no_warnings(Field *field, bool no_conversions);
virtual int save_in_field(Field *field, bool no_conversions);
virtual void save_org_in_field(Field *field)
{ (void) save_in_field(field, 1); }
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index e7a0778d5cb..6ba76cf52b6 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -1069,8 +1069,8 @@ int rea_create_table(THD *thd, my_string file_name,HA_CREATE_INFO *create_info,
uint key_count,KEY *key_info);
int format_number(uint inputflag,uint max_length,my_string pos,uint length,
my_string *errpos);
-int openfrm(const char *name,const char *alias,uint filestat,uint prgflag,
- uint ha_open_flags, TABLE *outparam);
+int openfrm(THD *thd, const char *name,const char *alias,uint filestat,
+ uint prgflag, uint ha_open_flags, TABLE *outparam);
int readfrm(const char *name, const void** data, uint* length);
int writefrm(const char* name, const void* data, uint len);
int create_table_from_handler(const char *db, const char *name,
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index e3a130f55f0..a47b4bcfbca 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -3481,7 +3481,7 @@ get_mm_leaf(PARAM *param, COND *conf_func, Field *field, KEY_PART *key_part,
field->cmp_type() != value->result_type())
DBUG_RETURN(0);
- if (value->save_in_field(field, 1) < 0)
+ if (value->save_in_field_no_warnings(field, 1) < 0)
{
/* This happens when we try to insert a NULL field in a not null column */
DBUG_RETURN(&null_element); // cmp with NULL is never TRUE
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 80090ba288e..8587942e30e 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -813,7 +813,8 @@ TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
pthread_mutex_lock(&LOCK_open);
- if (open_unireg_entry(thd, table, db, table_name, table_name, 0, 0) ||
+ if (open_unireg_entry(thd, table, db, table_name, table_name, 0,
+ &thd->mem_root) ||
!(table->table_cache_key =memdup_root(&table->mem_root,(char*) key,
key_length)))
{
@@ -956,7 +957,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
}
table->prev->next=table->next; /* Remove from unused list */
table->next->prev=table->prev;
-
+ table->in_use= thd;
}
else
{
@@ -994,7 +995,6 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
VOID(my_hash_insert(&open_cache,(byte*) table));
}
- table->in_use=thd;
check_unused(); // Debugging call
VOID(pthread_mutex_unlock(&LOCK_open));
@@ -1073,8 +1073,8 @@ bool reopen_table(TABLE *table,bool locked)
VOID(pthread_mutex_lock(&LOCK_open));
safe_mutex_assert_owner(&LOCK_open);
- if (open_unireg_entry(current_thd, &tmp, db, table_name,
- table->table_name, 0, 0))
+ if (open_unireg_entry(table->in_use, &tmp, db, table_name,
+ table->table_name, 0, &table->in_use->mem_root))
goto end;
free_io_cache(table);
@@ -1413,7 +1413,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
DBUG_ENTER("open_unireg_entry");
strxmov(path, mysql_data_home, "/", db, "/", name, NullS);
- while ((error= openfrm(path, alias,
+ while ((error= openfrm(thd, path, alias,
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
HA_GET_INDEX | HA_TRY_READ_ONLY |
NO_ERR_ON_NEW_FRM),
@@ -1468,7 +1468,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
pthread_mutex_unlock(&LOCK_open);
thd->clear_error(); // Clear error message
error= 0;
- if (openfrm(path,alias,
+ if (openfrm(thd, path, alias,
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX |
HA_TRY_READ_ONLY),
READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
@@ -1713,7 +1713,8 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type)
thd->current_tablenr= 0;
/* open_ltable can be used only for BASIC TABLEs */
table_list->required_type= FRMTYPE_TABLE;
- while (!(table= open_table(thd, table_list, 0, &refresh)) && refresh)
+ while (!(table= open_table(thd, table_list, &thd->mem_root, &refresh)) &&
+ refresh)
;
if (table)
@@ -1901,7 +1902,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
MYF(MY_WME))))
DBUG_RETURN(0); /* purecov: inspected */
- if (openfrm(path, table_name,
+ if (openfrm(thd, path, table_name,
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX),
READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
ha_open_options,
@@ -1912,7 +1913,6 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
}
tmp_table->reginfo.lock_type=TL_WRITE; // Simulate locked
- tmp_table->in_use= thd;
tmp_table->tmp_table = (tmp_table->file->has_transactions() ?
TRANSACTIONAL_TMP_TABLE : TMP_TABLE);
tmp_table->table_cache_key=(char*) (tmp_table+1);
@@ -3397,9 +3397,6 @@ open_new_frm(const char *path, const char *alias,
pathstr.str= (char*) path;
pathstr.length= strlen(path);
- if (!mem_root)
- mem_root= &current_thd->mem_root;
-
if ((parser= sql_parse_prepare(&pathstr, mem_root, 1)))
{
if (!strncmp("VIEW", parser->type()->str, parser->type()->length))
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index c30fdcd805f..5828f0be2f9 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1652,12 +1652,14 @@ void select_insert::cleanup()
select_insert::~select_insert()
{
+ DBUG_ENTER("~select_insert");
if (table)
{
table->next_number_field=0;
table->file->reset();
}
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
+ DBUG_VOID_RETURN;
}
@@ -1815,7 +1817,8 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
table->next_number_field=table->found_next_number_field;
restore_record(table,default_values); // Get empty record
- thd->count_cuted_fields= CHECK_FIELD_WARN; // count warnings
+ /* Count warnings. This is reset in ~select_insert() */
+ thd->count_cuted_fields= CHECK_FIELD_WARN;
thd->cuted_fields=0;
if (info.handle_duplicates == DUP_IGNORE ||
info.handle_duplicates == DUP_REPLACE)
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 156897682b3..8c63b6d1b9f 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2461,6 +2461,7 @@ mysql_execute_command(THD *thd)
select_lex->resolve_mode= SELECT_LEX::SELECT_MODE;
res=handle_select(thd, lex, result);
select_lex->resolve_mode= SELECT_LEX::NOMATTER_MODE;
+ delete result;
}
/* reset for PS */
lex->create_list.empty();
@@ -2818,6 +2819,7 @@ unsent_create_error:
break;
if ((result= new select_insert(first_table, first_table->table,
&lex->field_list, lex->duplicates)))
+ {
/* Skip first table, which is the table we are inserting in */
lex->select_lex.table_list.first= (byte*) first_table->next_local;
/*
@@ -2829,6 +2831,8 @@ unsent_create_error:
/* revert changes for SP */
lex->select_lex.table_list.first= (byte*) first_table;
lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
+ delete result;
+ }
if (thd->net.report_error)
res= -1;
}
diff --git a/sql/sql_select.h b/sql/sql_select.h
index a1487693b79..eb80f3ee608 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -471,7 +471,7 @@ public:
{}
bool copy()
{
- return item->save_in_field(to_field, 1) || err != 0;
+ return item->save_in_field_no_warnings(to_field, 1) || err != 0;
}
const char *name() const { return "func"; }
};
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 65be24ae537..fb4ad28202a 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1387,7 +1387,7 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
don't want to delete from it) 2) it would be written before the CREATE
TABLE, which is a wrong order. So we keep binary logging disabled.
*/
- if (!(table= open_table(thd, create_table, 0, (bool*) 0)))
+ if (!(table= open_table(thd, create_table, &thd->mem_root, (bool*) 0)))
{
quick_rm_table(create_info->db_type, create_table->db,
table_case_name(create_info, create_table->real_name));
@@ -1629,7 +1629,7 @@ static int prepare_for_repair(THD* thd, TABLE_LIST *table_list,
char name[FN_REFLEN];
strxmov(name, mysql_data_home, "/", table_list->db, "/",
table_list->real_name, NullS);
- if (openfrm(name, "", 0, 0, 0, &tmp_table))
+ if (openfrm(thd, name, "", 0, 0, 0, &tmp_table))
DBUG_RETURN(0); // Can't open frm file
table= &tmp_table;
}
@@ -3026,7 +3026,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
bzero((void*) &tbl, sizeof(tbl));
tbl.db= new_db;
tbl.real_name= tbl.alias= tmp_name;
- new_table= open_table(thd, &tbl, 0, 0);
+ new_table= open_table(thd, &tbl, &thd->mem_root, 0);
}
else
{
diff --git a/sql/table.cc b/sql/table.cc
index 1c216c44f66..946dbc0766a 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -61,8 +61,8 @@ static byte* get_field_name(Field **buff,uint *length,
5 It is new format of .frm file
*/
-int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
- uint ha_open_flags, TABLE *outparam)
+int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
+ uint prgflag, uint ha_open_flags, TABLE *outparam)
{
reg1 uint i;
reg2 uchar *strpos;
@@ -119,6 +119,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
}
bzero((char*) outparam,sizeof(*outparam));
+ outparam->in_use= thd;
outparam->blob_ptr_size=sizeof(char*);
outparam->db_stat = db_stat;
init_sql_alloc(&outparam->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
@@ -733,7 +734,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
outparam->db_low_byte_first=outparam->file->low_byte_first();
my_pthread_setspecific_ptr(THR_MALLOC,old_root);
- current_thd->status_var.opened_tables++;
+ thd->status_var.opened_tables++;
#ifndef DBUG_OFF
if (use_hash)
(void) hash_check(&outparam->name_hash);