diff options
author | Sergey Glukhov <Sergey.Glukhov@sun.com> | 2010-03-12 10:33:16 +0400 |
---|---|---|
committer | Sergey Glukhov <Sergey.Glukhov@sun.com> | 2010-03-12 10:33:16 +0400 |
commit | b8132a8d946bde553834c37785bbe53008f1e925 (patch) | |
tree | 8c5e7ceda5785c052e709a71c6a64f50b2e93eae | |
parent | b182c9bd2030c3b3c548157d1bc4c01c306b2c5c (diff) | |
download | mariadb-git-b8132a8d946bde553834c37785bbe53008f1e925.tar.gz |
Bug#41788 mysql_fetch_field returns org_table == table by a view
The problem is that Item_direct_view_ref which is inherited
from Item_ident updates orig_table_name and table_name with
the same values. The fix is introduction of new constructor
into Item_ident and up which updates orig_table_name and
table_name separately.
mysql-test/r/metadata.result:
test case
mysql-test/t/metadata.test:
test case
sql/item.cc:
new constructor which updates
orig_table_name and table_name
separately.
sql/item.h:
new constructor which updates
orig_table_name and table_name
separately.
sql/table.cc:
used new constructor
-rw-r--r-- | mysql-test/r/metadata.result | 11 | ||||
-rw-r--r-- | mysql-test/t/metadata.test | 13 | ||||
-rw-r--r-- | sql/item.cc | 26 | ||||
-rw-r--r-- | sql/item.h | 13 | ||||
-rw-r--r-- | sql/table.cc | 4 |
5 files changed, 64 insertions, 3 deletions
diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index 6b498e55d85..2f9fb6b67f5 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -198,4 +198,15 @@ def IF(i, d, d) IF(i, d, d) 10 10 10 Y 128 0 63 def IFNULL(d, d) IFNULL(d, d) 10 10 10 Y 128 0 63 def LEAST(d, d) LEAST(d, d) 10 10 10 Y 128 0 63 DROP TABLE t1; +# +# Bug#41788 mysql_fetch_field returns org_table == table by a view +# +CREATE TABLE t1 (f1 INT); +CREATE VIEW v1 AS SELECT f1 FROM t1; +SELECT f1 FROM v1 va; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test v1 va f1 f1 3 11 0 Y 32768 0 63 +f1 +DROP VIEW v1; +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/metadata.test b/mysql-test/t/metadata.test index a10767579fb..9bfb47c53be 100644 --- a/mysql-test/t/metadata.test +++ b/mysql-test/t/metadata.test @@ -129,4 +129,17 @@ SELECT COALESCE(d, d), IFNULL(d, d), IF(i, d, d), DROP TABLE t1; +--echo # +--echo # Bug#41788 mysql_fetch_field returns org_table == table by a view +--echo # + +CREATE TABLE t1 (f1 INT); +CREATE VIEW v1 AS SELECT f1 FROM t1; +--enable_metadata +SELECT f1 FROM v1 va; +--disable_metadata + +DROP VIEW v1; +DROP TABLE t1; + --echo End of 5.0 tests diff --git a/sql/item.cc b/sql/item.cc index ec4c2e6e662..e34905a2e7f 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -556,6 +556,18 @@ Item_ident::Item_ident(Name_resolution_context *context_arg, } +Item_ident::Item_ident(TABLE_LIST *view_arg, const char *field_name_arg) + :orig_db_name(NullS), orig_table_name(view_arg->table_name), + orig_field_name(field_name_arg), context(&view_arg->view->select_lex.context), + db_name(NullS), table_name(view_arg->alias), + field_name(field_name_arg), + alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX), + cached_table(NULL), depended_from(NULL) +{ + name = (char*) field_name_arg; +} + + /** Constructor used by Item_field & Item_*_ref (see Item comment) */ @@ -5721,6 +5733,20 @@ Item_ref::Item_ref(Name_resolution_context *context_arg, } +Item_ref::Item_ref(TABLE_LIST *view_arg, Item **item, + const char *field_name_arg, bool alias_name_used_arg) + :Item_ident(view_arg, field_name_arg), + result_field(NULL), ref(item) +{ + alias_name_used= alias_name_used_arg; + /* + This constructor is used to create some internal references over fixed items + */ + if (ref && *ref && (*ref)->fixed) + set_properties(); +} + + /** Resolve the name of a reference to a column reference. diff --git a/sql/item.h b/sql/item.h index d2e8382023b..77b6e28e98b 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1402,6 +1402,7 @@ public: const char *db_name_arg, const char *table_name_arg, const char *field_name_arg); Item_ident(THD *thd, Item_ident *item); + Item_ident(TABLE_LIST *view_arg, const char *field_name_arg); const char *full_name() const; void cleanup(); bool remove_dependence_processor(uchar * arg); @@ -2222,6 +2223,8 @@ public: Item_ref(Name_resolution_context *context_arg, Item **item, const char *table_name_arg, const char *field_name_arg, bool alias_name_used_arg= FALSE); + Item_ref(TABLE_LIST *view_arg, Item **item, + const char *field_name_arg, bool alias_name_used_arg= FALSE); /* Constructor need to process subselect with temporary tables (see Item) */ Item_ref(THD *thd, Item_ref *item) @@ -2337,6 +2340,12 @@ public: {} /* Constructor need to process subselect with temporary tables (see Item) */ Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {} + Item_direct_ref(TABLE_LIST *view_arg, Item **item, + const char *field_name_arg, + bool alias_name_used_arg= FALSE) + :Item_ref(view_arg, item, field_name_arg, + alias_name_used_arg) + {} double val_real(); longlong val_int(); @@ -2362,6 +2371,10 @@ public: /* Constructor need to process subselect with temporary tables (see Item) */ Item_direct_view_ref(THD *thd, Item_direct_ref *item) :Item_direct_ref(thd, item) {} + Item_direct_view_ref(TABLE_LIST *view_arg, Item **item, + const char *field_name_arg) + :Item_direct_ref(view_arg, item, field_name_arg) + {} bool fix_fields(THD *, Item **); bool eq(const Item *item, bool binary_cmp) const; diff --git a/sql/table.cc b/sql/table.cc index 8758596d408..a4e2c59fb87 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4023,9 +4023,7 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref, { DBUG_RETURN(field); } - Item *item= new Item_direct_view_ref(&view->view->select_lex.context, - field_ref, view->alias, - name); + Item *item= new Item_direct_view_ref(view, field_ref, name); DBUG_RETURN(item); } |