diff options
author | unknown <timour@mysql.com> | 2005-10-01 09:35:30 +0300 |
---|---|---|
committer | unknown <timour@mysql.com> | 2005-10-01 09:35:30 +0300 |
commit | 58263844c7e916d271dc1e14661ea1b6e66d5e04 (patch) | |
tree | f5ee23694bda45817fb2d312a039f559d122820f | |
parent | 3a806cd674deca9288f7555c03172afa4ada01ac (diff) | |
download | mariadb-git-58263844c7e916d271dc1e14661ea1b6e66d5e04.tar.gz |
Fix for BUG#13410 - qualified reference to a view column in the HAVING clause cannot be resolved.
The problem was then when a column reference was resolved to a view column, the new Item
created for this column contained the name of the view, and not the view alias.
mysql-test/r/view.result:
Additional test for BUG#13410.
mysql-test/t/view.test:
Additional test for BUG#13410.
sql/item.cc:
Correctly cast 'cur_field' to Item_ident because if the original item is
an Item_field, the cur_field is either an Item_field or an Item_ref.
Thus we have to cast cur_field to a common super-class of both.
sql/item.h:
- real_item() may be called before Item_ref::ref is set
(i.e. the Item_ref object was resolved).
- To avoid a crash and to return some meaningful value
in such cases we return 'this'.
sql/sql_base.cc:
- 'item' may be an Item_ref, so we test for the type of the actual
referenced item.
- Correctly cast 'cur_field' to Item_ident because if the original
item is an Item_field, the cur_field is either an Item_field or an
Item_ref. Thus we have to cast cur_field to a common super-class
of both.
sql/table.cc:
- When creating a new Item for a reference to a view column, use the view alias,
and not the real view name.
- Removed old code
-rw-r--r-- | mysql-test/r/view.result | 10 | ||||
-rw-r--r-- | mysql-test/t/view.test | 2 | ||||
-rw-r--r-- | sql/item.cc | 4 | ||||
-rw-r--r-- | sql/item.h | 2 | ||||
-rw-r--r-- | sql/sql_base.cc | 4 | ||||
-rw-r--r-- | sql/table.cc | 18 |
6 files changed, 18 insertions, 22 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 9742c029706..e52ec950c8c 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2286,5 +2286,15 @@ SELECT v1.a FROM v1 GROUP BY v1.a HAVING v1.a > 1; a 2 3 +SELECT t_1.a FROM t1 AS t_1 GROUP BY t_1.a HAVING t_1.a IN (1,2,3); +a +1 +2 +3 +SELECT v_1.a FROM v1 AS v_1 GROUP BY v_1.a HAVING v_1.a IN (1,2,3); +a +1 +2 +3 DROP VIEW v1; DROP TABLE t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 8d3593162c7..15c8cccf69c 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2162,6 +2162,8 @@ INSERT INTO t1 VALUES (1,1),(2,2),(3,3); CREATE VIEW v1 AS SELECT a,b FROM t1; SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > 1; SELECT v1.a FROM v1 GROUP BY v1.a HAVING v1.a > 1; +SELECT t_1.a FROM t1 AS t_1 GROUP BY t_1.a HAVING t_1.a IN (1,2,3); +SELECT v_1.a FROM v1 AS v_1 GROUP BY v_1.a HAVING v_1.a IN (1,2,3); DROP VIEW v1; DROP TABLE t1; diff --git a/sql/item.cc b/sql/item.cc index f826fc1d874..966dbbaec53 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2973,7 +2973,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) const char *field_name; ORDER *found_group= NULL; int found_match_degree= 0; - Item_field *cur_field; + Item_ident *cur_field; int cur_match_degree= 0; if (find_item->type() == Item::FIELD_ITEM || @@ -2992,7 +2992,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) { if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM) { - cur_field= (Item_field*) *cur_group->item; + cur_field= (Item_ident*) *cur_group->item; cur_match_degree= 0; DBUG_ASSERT(cur_field->field_name != 0); diff --git a/sql/item.h b/sql/item.h index 10c1eec2db9..755eaf2136f 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1619,7 +1619,7 @@ public: } Item *real_item() { - return (*ref)->real_item(); + return (ref && *ref) ? (*ref)->real_item() : this; } bool walk(Item_processor processor, byte *arg) { return (*ref)->walk(processor, arg); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 715d38925aa..1ea51ae1067 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3357,9 +3357,9 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter, for (uint i= 0; (item=li++); i++) { - if (field_name && item->type() == Item::FIELD_ITEM) + if (field_name && item->real_item()->type() == Item::FIELD_ITEM) { - Item_field *item_field= (Item_field*) item; + Item_ident *item_field= (Item_ident*) item; /* In case of group_concat() with ORDER BY condition in the QUERY diff --git a/sql/table.cc b/sql/table.cc index 982d5e7ddc9..4be48bafae4 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2424,22 +2424,6 @@ Field *Natural_join_column::field() const char *Natural_join_column::table_name() { return table_ref->alias; - /* - TODO: - I think that it is sufficient to return just - table->alias, which is correctly set to either - the view name, the table name, or the alias to - the table reference (view or stored table). - */ -#ifdef NOT_YET - if (view_field) - return table_ref->view_name.str; - - DBUG_ASSERT(!strcmp(table_ref->table_name, - table_ref->table->s->table_name)); - return table_ref->table_name; -} -#endif } @@ -2575,7 +2559,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->view_name.str, + field_ref, view->alias, name); DBUG_RETURN(item); } |