Commit f6a552b1 authored by unknown's avatar unknown

sql_base.cc, item.cc:

  Fixed bug #13411.
  Fixed name resolution for non-qualified reference to a view column
  in the HAVING clause.
view.result, view.test:
  Added a test case for bug #13411.


mysql-test/t/view.test:
  Added a test case for bug #13411.
mysql-test/r/view.result:
  Added a test case for bug #13411.
sql/item.cc:
  Fixed bug #13411.
  Fixed name resolution for non-qualified reference to a view column
  in the HAVING clause.
sql/sql_base.cc:
  Fixed bug #13411.
  Fixed name resolution for non-qualified reference to a view column
  in the HAVING clause.
parent 4aa9a107
...@@ -2262,3 +2262,16 @@ WEEKDAY(date) ...@@ -2262,3 +2262,16 @@ WEEKDAY(date)
1 1
DROP TABLE t1; DROP TABLE t1;
DROP VIEW v1, v2, v3; DROP VIEW v1, v2, v3;
CREATE TABLE t1 ( a int, b int );
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 a > 1;
a
2
3
SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1;
a
2
3
DROP VIEW v1;
DROP TABLE t1;
...@@ -2139,3 +2139,18 @@ SELECT * FROM v3; ...@@ -2139,3 +2139,18 @@ SELECT * FROM v3;
DROP TABLE t1; DROP TABLE t1;
DROP VIEW v1, v2, v3; DROP VIEW v1, v2, v3;
#
# Bug #13411: crash when using non-qualified view column in HAVING clause
#
CREATE TABLE t1 ( a int, b int );
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 a > 1;
SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1;
DROP VIEW v1;
DROP TABLE t1;
...@@ -1687,7 +1687,7 @@ bool Item_field::eq(const Item *item, bool binary_cmp) const ...@@ -1687,7 +1687,7 @@ bool Item_field::eq(const Item *item, bool binary_cmp) const
return 0; return 0;
Item_field *item_field= (Item_field*) item; Item_field *item_field= (Item_field*) item;
if (item_field->field) if (item_field->field && field)
return item_field->field == field; return item_field->field == field;
/* /*
We may come here when we are trying to find a function in a GROUP BY We may come here when we are trying to find a function in a GROUP BY
...@@ -1701,10 +1701,10 @@ bool Item_field::eq(const Item *item, bool binary_cmp) const ...@@ -1701,10 +1701,10 @@ bool Item_field::eq(const Item *item, bool binary_cmp) const
*/ */
return (!my_strcasecmp(system_charset_info, item_field->name, return (!my_strcasecmp(system_charset_info, item_field->name,
field_name) && field_name) &&
(!item_field->table_name || (!item_field->table_name || !table_name ||
(!my_strcasecmp(table_alias_charset, item_field->table_name, (!my_strcasecmp(table_alias_charset, item_field->table_name,
table_name) && table_name) &&
(!item_field->db_name || (!item_field->db_name || !db_name ||
(item_field->db_name && !strcmp(item_field->db_name, (item_field->db_name && !strcmp(item_field->db_name,
db_name)))))); db_name))))));
} }
......
...@@ -3459,7 +3459,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter, ...@@ -3459,7 +3459,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
} }
} }
} }
else if (!table_name && (item->eq(find,0) || else if (!table_name && (find->eq(item,0) ||
find->name && item->name && find->name && item->name &&
!my_strcasecmp(system_charset_info, !my_strcasecmp(system_charset_info,
item->name,find->name))) item->name,find->name)))
......
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