Commit e5f48e13 authored by monty@mysql.com's avatar monty@mysql.com

Reverting patch for BUG #14009 (use of abs() on null value causes problems with filesort

Fix for bug #14536: SELECT @A,@A:=... fails with prepared statements
parent f3502cd9
......@@ -180,8 +180,8 @@ Field Type Null Key Default Extra
f1 date NO 0000-00-00
f2 datetime YES NULL
f3 time YES NULL
f4 time NO 00:00:00
f5 time NO 00:00:00
f4 time YES NULL
f5 time YES NULL
f6 time NO 00:00:00
f7 datetime YES NULL
f8 date YES NULL
......
......@@ -176,7 +176,7 @@ Table Create Table
t1 CREATE TABLE `t1` (
`round(15.4,-1)` decimal(3,0) unsigned NOT NULL default '0',
`truncate(-5678.123451,-3)` decimal(4,0) NOT NULL default '0',
`abs(-1.1)` decimal(2,1) default NULL,
`abs(-1.1)` decimal(2,1) NOT NULL default '0.0',
`-(-1.1)` decimal(2,1) NOT NULL default '0.0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
......
......@@ -123,6 +123,17 @@ select @a+0, @a:=@a+0+count(*), count(*), @a+0 from t1 group by i;
0 1 1 0
1 3 2 0
3 6 3 0
set @a=0;
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
@a @a:="hello" @a @a:=3 @a @a:="hello again"
0 hello 0 3 0 hello again
0 hello 0 3 0 hello again
0 hello 0 3 0 hello again
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
@a @a:="hello" @a @a:=3 @a @a:="hello again"
hello again hello hello again 3 hello again hello again
hello again hello hello again 3 hello again hello again
hello again hello hello again 3 hello again hello again
drop table t1;
set @a=_latin2'test';
select charset(@a),collation(@a),coercibility(@a);
......
......@@ -16,4 +16,3 @@ rpl_until : Unstable test case, bug#12429
rpl_deadlock : Unstable test case, bug#12429
kill : Unstable test case, bug#9712
archive_gis : The test fails on 32bit Linux
user_var : Ramil should fix this soon
......@@ -70,6 +70,10 @@ create table t1 (i int not null);
insert t1 values (1),(2),(2),(3),(3),(3);
select @a:=0; select @a, @a:=@a+count(*), count(*), @a from t1 group by i;
select @a:=0; select @a+0, @a:=@a+0+count(*), count(*), @a+0 from t1 group by i;
set @a=0;
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
drop table t1;
#
......
......@@ -5082,14 +5082,16 @@ bool Item_insert_value::fix_fields(THD *thd, Item **items)
{
DBUG_ASSERT(fixed == 0);
/* We should only check that arg is in first table */
if (!arg->fixed)
{
bool res;
st_table_list *orig_next_table= context->last_name_resolution_table;
context->last_name_resolution_table= context->first_name_resolution_table;
if (!arg->fixed && arg->fix_fields(thd, &arg))
{
res= arg->fix_fields(thd, &arg);
context->last_name_resolution_table= orig_next_table;
if (res)
return TRUE;
}
context->last_name_resolution_table= orig_next_table;
if (arg->type() == REF_ITEM)
{
......
......@@ -636,7 +636,6 @@ void Item_func_num1::fix_num_length_and_dec()
{
decimals= args[0]->decimals;
max_length= args[0]->max_length;
maybe_null= 1;
}
......
......@@ -845,6 +845,7 @@ class Item_func_timediff :public Item_str_func
{
decimals=0;
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null= 1;
}
Field *tmp_table_field(TABLE *t_arg)
{
......
......@@ -37,7 +37,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
TABLE_LIST *table_list, MEM_ROOT *mem_root);
static void free_cache_entry(TABLE *entry);
static void mysql_rm_tmp_tables(void);
static my_bool open_new_frm(const char *path, const char *alias,
static bool open_new_frm(THD *thd, const char *path, const char *alias,
const char *db, const char *table_name,
uint db_stat, uint prgflag,
uint ha_open_flags, TABLE *outparam,
......@@ -1755,7 +1755,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
thd->open_options, entry)) &&
(error != 5 ||
(fn_format(path, path, 0, reg_ext, MY_UNPACK_FILENAME),
open_new_frm(path, alias, db, name,
open_new_frm(thd, path, alias, db, name,
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
HA_GET_INDEX | HA_TRY_READ_ONLY),
READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
......@@ -5260,6 +5260,7 @@ int init_ftfuncs(THD *thd, SELECT_LEX *select_lex, bool no_order)
SYNOPSIS
open_new_frm()
THD thread handler
path path to .frm
alias alias for table
db database
......@@ -5273,8 +5274,8 @@ int init_ftfuncs(THD *thd, SELECT_LEX *select_lex, bool no_order)
mem_root temporary MEM_ROOT for parsing
*/
static my_bool
open_new_frm(const char *path, const char *alias,
static bool
open_new_frm(THD *thd, const char *path, const char *alias,
const char *db, const char *table_name,
uint db_stat, uint prgflag,
uint ha_open_flags, TABLE *outparam, TABLE_LIST *table_desc,
......@@ -5296,7 +5297,7 @@ open_new_frm(const char *path, const char *alias,
my_error(ER_WRONG_OBJECT, MYF(0), db, table_name, "BASE TABLE");
goto err;
}
if (mysql_make_view(parser, table_desc))
if (mysql_make_view(thd, parser, table_desc))
goto err;
}
else
......
......@@ -361,7 +361,7 @@ class st_select_lex_node {
friend class st_select_lex_unit;
friend bool mysql_new_select(struct st_lex *lex, bool move_down);
friend my_bool mysql_make_view (File_parser *parser,
friend bool mysql_make_view(THD *thd, File_parser *parser,
TABLE_LIST *table);
private:
void fast_exclude();
......
......@@ -1237,7 +1237,8 @@ JOIN::exec()
if (zero_result_cause)
{
(void) return_zero_rows(this, result, select_lex->leaf_tables, *columns_list,
(void) return_zero_rows(this, result, select_lex->leaf_tables,
*columns_list,
send_row_on_empty_set(),
select_options,
zero_result_cause,
......@@ -1671,7 +1672,8 @@ JOIN::exec()
{
thd->proc_info="Sending data";
DBUG_PRINT("info", ("%s", thd->proc_info));
result->send_fields(*columns_list,
result->send_fields((procedure ? curr_join->procedure_fields_list :
*curr_fields_list),
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
error= do_select(curr_join, curr_fields_list, NULL, procedure);
thd->limit_found_rows= curr_join->send_records;
......@@ -9023,7 +9025,6 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
int rc= 0;
enum_nested_loop_state error= NESTED_LOOP_OK;
JOIN_TAB *join_tab;
List<Item> *columns_list= procedure? &join->procedure_fields_list : fields;
DBUG_ENTER("do_select");
join->procedure=procedure;
......@@ -9057,8 +9058,12 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
error= (*end_select)(join,join_tab,1);
}
else if (join->send_row_on_empty_set())
{
List<Item> *columns_list= (procedure ? &join->procedure_fields_list :
fields);
rc= join->result->send_data(*columns_list);
}
}
else
{
error= sub_select(join,join_tab,0);
......
......@@ -728,20 +728,24 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
SYNOPSIS
mysql_make_view()
parser - parser object;
table - TABLE_LIST structure for filling
thd Thread handler
parser parser object
table TABLE_LIST structure for filling
RETURN
0 ok
1 error
*/
my_bool
mysql_make_view(File_parser *parser, TABLE_LIST *table)
bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table)
{
THD *thd= current_thd;
SELECT_LEX *end, *view_select;
LEX *old_lex, *lex;
Query_arena *arena, backup;
int res;
bool result;
DBUG_ENTER("mysql_make_view");
DBUG_PRINT("info", ("table=%p (%s)", table, table->table_name));
DBUG_PRINT("info", ("table: 0x%lx (%s)", (ulong) table, table->table_name));
if (table->view)
{
......@@ -765,16 +769,12 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
DBUG_RETURN(0);
}
SELECT_LEX *end;
LEX *old_lex= thd->lex, *lex;
SELECT_LEX *view_select;
int res= 0;
/*
For now we assume that tables will not be changed during PS life (it
will be TRUE as far as we make new table cache).
*/
Query_arena *arena= thd->stmt_arena, backup;
old_lex= thd->lex;
arena= thd->stmt_arena;
if (arena->is_conventional())
arena= 0;
else
......@@ -1133,23 +1133,21 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
(st_select_lex_node**)&old_lex->all_selects_list;
ok2:
if (arena)
thd->restore_active_arena(arena, &backup);
if (!old_lex->time_zone_tables_used && thd->lex->time_zone_tables_used)
old_lex->time_zone_tables_used= thd->lex->time_zone_tables_used;
thd->lex= old_lex;
if (!table->prelocking_placeholder && table->prepare_security(thd))
DBUG_RETURN(1);
DBUG_RETURN(0);
result= !table->prelocking_placeholder && table->prepare_security(thd);
err:
end:
if (arena)
thd->restore_active_arena(arena, &backup);
thd->lex= old_lex;
DBUG_RETURN(result);
err:
delete table->view;
table->view= 0; // now it is not VIEW placeholder
thd->lex= old_lex;
DBUG_RETURN(1);
result= 1;
goto end;
}
......
......@@ -19,7 +19,7 @@
bool mysql_create_view(THD *thd,
enum_view_create_mode mode);
my_bool mysql_make_view(File_parser *parser, TABLE_LIST *table);
bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table);
bool mysql_drop_view(THD *thd, TABLE_LIST *view, enum_drop_mode drop_mode);
......
......@@ -2654,7 +2654,7 @@ Natural_join_column::check_grants(THD *thd, const char *name, uint length)
GRANT_INFO *grant;
const char *db_name;
const char *table_name;
Security_context *save_security_ctx= 0;
Security_context *save_security_ctx;
Security_context *new_sctx= table_ref->security_ctx;
bool res;
......@@ -2673,13 +2673,10 @@ Natural_join_column::check_grants(THD *thd, const char *name, uint length)
table_name= table_ref->table->s->table_name;
}
if (new_sctx)
{
save_security_ctx= thd->security_ctx;
if (new_sctx)
thd->security_ctx= new_sctx;
}
res= check_grant_column(thd, grant, db_name, table_name, name, length);
if (save_security_ctx)
thd->security_ctx= save_security_ctx;
return res;
}
......
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