From 39b792908f3c0da3150ac6700a5c1f8b8e6eec76 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Feb 2006 18:08:18 +0100 Subject: [PATCH] Bug #17206 Update through VIEW is not working mysql-test/r/ndb_view.result: New BitKeeper file ``mysql-test/r/ndb_view.result'' mysql-test/t/ndb_view.test: New BitKeeper file ``mysql-test/t/ndb_view.test'' --- mysql-test/r/ndb_view.result | 24 ++++++++++++++++++++++++ mysql-test/t/ndb_view.test | 29 +++++++++++++++++++++++++++++ sql/sql_base.cc | 32 +++++++++++++++++++++++++++----- sql/sql_partition.cc | 2 ++ sql/sql_view.cc | 2 ++ 5 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 mysql-test/r/ndb_view.result create mode 100644 mysql-test/t/ndb_view.test diff --git a/mysql-test/r/ndb_view.result b/mysql-test/r/ndb_view.result new file mode 100644 index 00000000000..b7d1b6860c8 --- /dev/null +++ b/mysql-test/r/ndb_view.result @@ -0,0 +1,24 @@ +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; diff --git a/mysql-test/t/ndb_view.test b/mysql-test/t/ndb_view.test new file mode 100644 index 00000000000..3b8fc330b40 --- /dev/null +++ b/mysql-test/t/ndb_view.test @@ -0,0 +1,29 @@ +-- 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; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 44b3a22ec52..44aed586928 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -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) diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index c6df76f2674..cc34c6f137a 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -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); } diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 78497a2cf8b..c4cb9770e14 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -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++)