summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <gshchepa/uchum@gleb.loc>2007-06-20 13:06:24 +0500
committerunknown <gshchepa/uchum@gleb.loc>2007-06-20 13:06:24 +0500
commite2aa6ee13e7e42ed6406934d45f70ee1c07b520d (patch)
tree0b25f7316a296a2868256f5ab80929d7653bf0c8
parentfcacd0b2718ce86dc782304e82df5ce93b71c41d (diff)
parente855bf33b36586c4abca0b905608682f21752b75 (diff)
downloadmariadb-git-e2aa6ee13e7e42ed6406934d45f70ee1c07b520d.tar.gz
Merge gleb.loc:/home/uchum/work/bk/5.0-opt-28898
into gleb.loc:/home/uchum/work/bk/5.0-opt sql/sql_select.cc: Auto merged
-rw-r--r--mysql-test/r/metadata.result41
-rw-r--r--mysql-test/t/metadata.test21
-rw-r--r--sql/item.cc15
-rw-r--r--sql/item.h6
-rw-r--r--sql/sql_select.cc7
5 files changed, 85 insertions, 5 deletions
diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result
index d33fb038b79..283dc8a02ae 100644
--- a/mysql-test/r/metadata.result
+++ b/mysql-test/r/metadata.result
@@ -140,4 +140,45 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is
def a v_small v_small 3 9 9 N 32769 0 63
v_small
214748364
+CREATE TABLE t1 (c1 CHAR(1));
+CREATE TABLE t2 (c2 CHAR(1));
+CREATE VIEW v1 AS SELECT t1.c1 FROM t1;
+CREATE VIEW v2 AS SELECT t2.c2 FROM t2;
+INSERT INTO t1 VALUES ('1'), ('2'), ('3');
+INSERT INTO t2 VALUES ('1'), ('2'), ('3'), ('2');
+SELECT v1.c1 FROM v1 JOIN t2 ON c1=c2 ORDER BY 1;
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def test t1 v1 c1 c1 254 1 1 Y 0 0 8
+c1
+1
+2
+2
+3
+SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2;
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def test t1 v1 c1 c1 254 1 1 Y 0 0 8
+def test t2 v2 c2 c2 254 1 1 Y 0 0 8
+c1 c2
+1 1
+2 2
+3 3
+2 2
+SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1;
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def test t1 v1 c1 c1 254 1 1 Y 32768 0 8
+def test t2 v2 c2 c2 254 1 1 Y 0 0 8
+c1 c2
+1 1
+2 2
+3 3
+SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1 ORDER BY v2.c2;
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def test t1 v1 c1 c1 254 1 1 Y 32768 0 8
+def test t2 v2 c2 c2 254 1 1 Y 0 0 8
+c1 c2
+1 1
+2 2
+3 3
+DROP VIEW v1;
+DROP TABLE t1,t2;
End of 5.0 tests
diff --git a/mysql-test/t/metadata.test b/mysql-test/t/metadata.test
index df4acec2021..ed510bc2c89 100644
--- a/mysql-test/t/metadata.test
+++ b/mysql-test/t/metadata.test
@@ -90,5 +90,26 @@ select a.* from (select 2147483648 as v_large) a;
select a.* from (select 214748364 as v_small) a;
--disable_metadata
+#
+# Bug #28898: table alias and database name of VIEW columns is empty in the
+# metadata of # SELECT statement where join is executed via temporary table.
+#
+
+CREATE TABLE t1 (c1 CHAR(1));
+CREATE TABLE t2 (c2 CHAR(1));
+CREATE VIEW v1 AS SELECT t1.c1 FROM t1;
+CREATE VIEW v2 AS SELECT t2.c2 FROM t2;
+INSERT INTO t1 VALUES ('1'), ('2'), ('3');
+INSERT INTO t2 VALUES ('1'), ('2'), ('3'), ('2');
+
+--enable_metadata
+SELECT v1.c1 FROM v1 JOIN t2 ON c1=c2 ORDER BY 1;
+SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2;
+SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1;
+SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1 ORDER BY v2.c2;
+--disable_metadata
+
+DROP VIEW v1;
+DROP TABLE t1,t2;
--echo End of 5.0 tests
diff --git a/sql/item.cc b/sql/item.cc
index 32c43eaa865..b1b85ba8b41 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -5501,6 +5501,21 @@ void Item_ref::make_field(Send_field *field)
}
+Item *Item_ref::get_tmp_table_item(THD *thd)
+{
+ if (!result_field)
+ return (*ref)->get_tmp_table_item(thd);
+
+ Item_field *item= new Item_field(result_field);
+ if (item)
+ {
+ item->table_name= table_name;
+ item->db_name= db_name;
+ }
+ return item;
+}
+
+
void Item_ref_null_helper::print(String *str)
{
str->append(STRING_WITH_LEN("<ref_null_helper>("));
diff --git a/sql/item.h b/sql/item.h
index 9268afaba0c..3478095351a 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1904,11 +1904,7 @@ public:
enum_field_types field_type() const { return (*ref)->field_type(); }
Field *get_tmp_table_field()
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
- Item *get_tmp_table_item(THD *thd)
- {
- return (result_field ? new Item_field(result_field) :
- (*ref)->get_tmp_table_item(thd));
- }
+ Item *get_tmp_table_item(THD *thd);
table_map used_tables() const
{
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 36c0988021f..f4450bf393f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -14245,6 +14245,13 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
if (!item_field)
DBUG_RETURN(TRUE); // Fatal error
item_field->name= item->name;
+ if (item->type() == Item::REF_ITEM)
+ {
+ Item_field *ifield= (Item_field *) item_field;
+ Item_ref *iref= (Item_ref *) item;
+ ifield->table_name= iref->table_name;
+ ifield->db_name= iref->db_name;
+ }
#ifndef DBUG_OFF
if (_db_on_ && !item_field->name)
{