mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
fixed updateability VIEW detection (Bug#5146)
fixed other Item_ref methods where result_field involved mysql-test/r/view.result: statements added to distinct in temporary table with a VIEW test test of agggregate over aggregate with view mysql-test/t/view.test: statements added to distinct in temporary table with a VIEW test test of agggregate over aggregate with view sql/item.cc: fixed other Item_ref methods where result_field involved sql/item.h: fixed other Item_ref methods where result_field involved sql/sql_lex.cc: fixed updateability VIEW detection
This commit is contained in:
@@ -1132,5 +1132,22 @@ select distinct a from t1 limit 2;
|
||||
a
|
||||
1
|
||||
2
|
||||
prepare stmt1 from "select distinct a from v1 limit 2";
|
||||
execute stmt1;
|
||||
a
|
||||
1
|
||||
2
|
||||
execute stmt1;
|
||||
a
|
||||
1
|
||||
2
|
||||
deallocate prepare stmt1;
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
create table t1 (tg_column bigint);
|
||||
create view v1 as select count(tg_column) as vg_column from t1;
|
||||
select avg(vg_column) from v1;
|
||||
avg(vg_column)
|
||||
0.0000
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
||||
@@ -1076,5 +1076,18 @@ create view v1 as select a from t1;
|
||||
select distinct a from v1;
|
||||
select distinct a from v1 limit 2;
|
||||
select distinct a from t1 limit 2;
|
||||
prepare stmt1 from "select distinct a from v1 limit 2";
|
||||
execute stmt1;
|
||||
execute stmt1;
|
||||
deallocate prepare stmt1;
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# aggregate function of aggregate function
|
||||
#
|
||||
create table t1 (tg_column bigint);
|
||||
create view v1 as select count(tg_column) as vg_column from t1;
|
||||
select avg(vg_column) from v1;
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
||||
38
sql/item.cc
38
sql/item.cc
@@ -2141,6 +2141,7 @@ void Item_ref::cleanup()
|
||||
{
|
||||
DBUG_ENTER("Item_ref::cleanup");
|
||||
Item_ident::cleanup();
|
||||
result_field= 0;
|
||||
if (hook_ptr)
|
||||
*hook_ptr= orig_item;
|
||||
DBUG_VOID_RETURN;
|
||||
@@ -2164,6 +2165,43 @@ bool Item_ref::send(Protocol *prot, String *tmp)
|
||||
}
|
||||
|
||||
|
||||
double Item_ref::val_result()
|
||||
{
|
||||
if (result_field)
|
||||
{
|
||||
if ((null_value= result_field->is_null()))
|
||||
return 0.0;
|
||||
return result_field->val_real();
|
||||
}
|
||||
return val();
|
||||
}
|
||||
|
||||
|
||||
longlong Item_ref::val_int_result()
|
||||
{
|
||||
if (result_field)
|
||||
{
|
||||
if ((null_value= result_field->is_null()))
|
||||
return 0.0;
|
||||
return result_field->val_int();
|
||||
}
|
||||
return val_int();
|
||||
}
|
||||
|
||||
|
||||
String *Item_ref::str_result(String* str)
|
||||
{
|
||||
if (result_field)
|
||||
{
|
||||
if ((null_value= result_field->is_null()))
|
||||
return 0;
|
||||
str->set_charset(str_value.charset());
|
||||
return result_field->val_str(str, &str_value);
|
||||
}
|
||||
return val_str(str);
|
||||
}
|
||||
|
||||
|
||||
void Item_ref_null_helper::print(String *str)
|
||||
{
|
||||
str->append("<ref_null_helper>(", 18);
|
||||
|
||||
@@ -964,6 +964,9 @@ public:
|
||||
{
|
||||
return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
|
||||
}
|
||||
double val_result();
|
||||
longlong val_int_result();
|
||||
String *str_result(String* tmp);
|
||||
bool send(Protocol *prot, String *tmp);
|
||||
void make_field(Send_field *field) { (*ref)->make_field(field); }
|
||||
bool fix_fields(THD *, struct st_table_list *, Item **);
|
||||
|
||||
@@ -1540,6 +1540,7 @@ bool st_lex::can_be_merged()
|
||||
select_lex.order_list.elements == 0 &&
|
||||
select_lex.group_list.elements == 0 &&
|
||||
select_lex.having == 0 &&
|
||||
select_lex.with_sum_func == 0 &&
|
||||
select_lex.table_list.elements == 1 &&
|
||||
!(select_lex.options & SELECT_DISTINCT) &&
|
||||
select_lex.select_limit == HA_POS_ERROR);
|
||||
|
||||
Reference in New Issue
Block a user