Commit 8c3e381b authored by Sergey Glukhov's avatar Sergey Glukhov

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
parent d1d177b8
......@@ -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
......@@ -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
......@@ -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.
......
......@@ -1402,6 +1402,7 @@ class Item_ident :public Item
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 @@ class Item_ref :public Item_ident
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 @@ class Item_direct_ref :public Item_ref
{}
/* 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 @@ class Item_direct_view_ref :public Item_direct_ref
/* 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;
......
......@@ -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);
}
......
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