summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authortimour@mysql.com <>2005-11-11 11:40:35 +0200
committertimour@mysql.com <>2005-11-11 11:40:35 +0200
commit225e94fb75737f9f8a50d8101ba66ab17f138a71 (patch)
tree5a4096f282af46eb0f4d8d92a8fbf8bf087a9743 /sql/item.cc
parent4015635bcd974eb0587f8f9bf80a4f6a5d59dec2 (diff)
downloadmariadb-git-225e94fb75737f9f8a50d8101ba66ab17f138a71.tar.gz
Fix for BUG#14662: view column in ORDER BY considered ambiguous if SELECT contains
the same column as an aliased and as a non-aliased column. The problem was that Item_direct_view_ref::eq() was first comparing view columns by name, and in this case the name of one of them is different since it is aliased.
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc31
1 files changed, 20 insertions, 11 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 1850b7d05c3..1767f9d97c1 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -4938,8 +4938,7 @@ bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
}
/*
- Compare view field's name with item's name before call to referenced
- item's eq()
+ Compare two view column references for equality.
SYNOPSIS
Item_direct_view_ref::eq()
@@ -4947,12 +4946,13 @@ bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
binary_cmp make binary comparison
DESCRIPTION
- Consider queries:
- create view v1 as select t1.f1 as f2, t1.f2 as f1 from t1;
- select * from v1 order by f1;
- In order to choose right field for sorting we need to compare
- given item's name (f1) to view field's name prior to calling
- referenced item's eq().
+ A view column reference is considered equal to another column
+ reference if the second one is a view column and if both column
+ references point to the same field. For views 'same field' means
+ the same Item_field object in the view translation table, where
+ the view translation table contains all result columns of the
+ view. This definition ensures that view columns are resolved
+ in the same manner as table columns.
RETURN
TRUE Referenced item is equal to given item
@@ -4962,9 +4962,18 @@ bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
bool Item_direct_view_ref::eq(const Item *item, bool binary_cmp) const
{
- Item *it= ((Item *) item)->real_item();
- return (!it->name || !my_strcasecmp(system_charset_info, it->name,
- field_name)) && ref && (*ref)->real_item()->eq(it, binary_cmp);
+ if (item->type() == REF_ITEM)
+ {
+ Item_ref *item_ref= (Item_ref*) item;
+ if (item_ref->ref_type() == VIEW_REF)
+ {
+ Item *item_ref_ref= *(item_ref->ref);
+ DBUG_ASSERT((*ref)->type() == FIELD_ITEM &&
+ (item_ref_ref->type() == FIELD_ITEM));
+ return (*ref == item_ref_ref);
+ }
+ }
+ return FALSE;
}
void Item_null_helper::print(String *str)