Bug #17206 Update through VIEW is not working

parent 44f2bd57
DROP TABLE IF EXISTS t1,t2,t3;
DROP VIEW IF EXISTS v1,v2,v3;
create table t1 (a int, b int, c int, d int) engine=ndb;
insert into t1 values (1,2,3,4),(5,6,7,8);
create view v1 as select t1.c as a, t1.a as b, t1.d as c, t1.a+t1.b+t1.c as d from t1;
select * from v1 order by a,b,c;
a b c d
3 1 4 6
7 5 8 18
update v1 set a=a+100 where b=1;
select * from v1 order by a,b,c;
a b c d
7 5 8 18
103 1 4 106
drop view v1;
create view v1 as select t1.c as a from t1;
insert into v1 values (200);
select * from t1 order by a,b,c,d;
a b c d
NULL NULL 200 NULL
1 2 103 4
5 6 7 8
drop view v1;
drop table t1;
-- source include/have_ndb.inc
-- source include/not_embedded.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3;
DROP VIEW IF EXISTS v1,v2,v3;
--enable_warnings
#
# simple operations via view
#
create table t1 (a int, b int, c int, d int) engine=ndb;
insert into t1 values (1,2,3,4),(5,6,7,8);
create view v1 as select t1.c as a, t1.a as b, t1.d as c, t1.a+t1.b+t1.c as d from t1;
select * from v1 order by a,b,c;
update v1 set a=a+100 where b=1;
select * from v1 order by a,b,c;
drop view v1;
create view v1 as select t1.c as a from t1;
insert into v1 values (200);
select * from t1 order by a,b,c,d;
drop view v1;
drop table t1;
......@@ -3858,13 +3858,31 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
register_tree_change, actual_table);
}
if (fld)
{
#ifndef NO_EMBEDDED_ACCESS_CHECKS
/* Check if there are sufficient access rights to the found field. */
if (fld && check_privileges &&
check_column_grant_in_table_ref(thd, *actual_table, name, length))
fld= WRONG_GRANT;
/* Check if there are sufficient access rights to the found field. */
if (check_privileges &&
check_column_grant_in_table_ref(thd, *actual_table, name, length))
fld= WRONG_GRANT;
else
#endif
if (thd->set_query_id)
{
Field *field_to_set= NULL;
if (fld == view_ref_found)
{
Item *it= (*ref)->real_item();
if (it->type() == Item::FIELD_ITEM)
field_to_set= ((Item_field*)it)->field;
}
else
field_to_set= fld;
if (field_to_set)
field_to_set->table->file->ha_set_bit_in_rw_set(field_to_set->fieldnr,
(bool)(thd->set_query_id-1));
}
}
DBUG_RETURN(fld);
}
......@@ -5044,6 +5062,7 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
DBUG_ENTER("setup_fields");
thd->set_query_id=set_query_id;
DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
if (allow_sum_func)
thd->lex->allow_sum_func|= 1 << thd->lex->current_select->nest_level;
thd->where= THD::DEFAULT_WHERE;
......@@ -5070,6 +5089,7 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
{
thd->lex->allow_sum_func= save_allow_sum_func;
thd->set_query_id= save_set_query_id;
DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
DBUG_RETURN(TRUE); /* purecov: inspected */
}
if (ref)
......@@ -5081,6 +5101,7 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
}
thd->lex->allow_sum_func= save_allow_sum_func;
thd->set_query_id= save_set_query_id;
DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
DBUG_RETURN(test(thd->net.report_error));
}
......@@ -5527,6 +5548,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
arena= 0; // For easier test
thd->set_query_id=1;
DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
select_lex->cond_count= 0;
for (table= tables; table; table= table->next_local)
......
......@@ -1984,6 +1984,7 @@ bool fix_partition_func(THD *thd, const char* name, TABLE *table,
DBUG_RETURN(FALSE);
}
thd->set_query_id= 0;
DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
/*
Set-up the TABLE_LIST object to be a list with a single table
Set the object to zero to create NULL pointers and set alias
......@@ -2120,6 +2121,7 @@ bool fix_partition_func(THD *thd, const char* name, TABLE *table,
result= FALSE;
end:
thd->set_query_id= save_set_query_id;
DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
DBUG_RETURN(result);
}
......
......@@ -1338,6 +1338,7 @@ bool check_key_in_view(THD *thd, TABLE_LIST *view)
*/
bool save_set_query_id= thd->set_query_id;
thd->set_query_id= 0;
DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
for (Field_translator *fld= trans; fld < end_of_trans; fld++)
{
if (!fld->item->fixed && fld->item->fix_fields(thd, &fld->item))
......@@ -1347,6 +1348,7 @@ bool check_key_in_view(THD *thd, TABLE_LIST *view)
}
}
thd->set_query_id= save_set_query_id;
DBUG_PRINT("info", ("thd->set_query_id: %d", thd->set_query_id));
}
/* Loop over all keys to see if a unique-not-null key is used */
for (;key_info != key_info_end ; key_info++)
......
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