Commit e74b00bb authored by unknown's avatar unknown

Removed wrong warnings in test suite (This was because select_insert /...

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
parent 6c3e6651
......@@ -110,7 +110,11 @@ name_id name
SELECT * FROM t2 WHERE name='[T,U]_axpby';
name_id name
2 [T,U]_axpby
drop table t1,t2;
CREATE TABLE t3 SELECT * FROM t2 WHERE name='[T,U]_axpby';
SELECT * FROM t2 WHERE name='[T,U]_axpby';
name_id name
2 [T,U]_axpby
drop table t1,t2,t3;
create table t1
(
SEQNO numeric(12 ) not null,
......
......@@ -129,7 +129,11 @@ create table t2
INSERT t2 select * from t1;
SELECT * FROM t2 WHERE name='[T,U]_axpy';
SELECT * FROM t2 WHERE name='[T,U]_axpby';
drop table t1,t2;
# Test possible problems with warnings in CREATE ... SELECT
CREATE TABLE t3 SELECT * FROM t2 WHERE name='[T,U]_axpby';
SELECT * FROM t2 WHERE name='[T,U]_axpby';
drop table t1,t2,t3;
#
# Test bug with long primary key
......
......@@ -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)
{
......
......@@ -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()
{
......
......@@ -152,6 +152,7 @@ class Item {
*/
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); }
......
......@@ -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,
......
......@@ -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
......
......@@ -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))
......
......@@ -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)
......
......@@ -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 @@ mysql_execute_command(THD *thd)
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 @@ mysql_execute_command(THD *thd)
/* 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;
}
......
......@@ -471,7 +471,7 @@ class store_key_item :public store_key
{}
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"; }
};
......
......@@ -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
{
......
......@@ -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);
......
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