summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorunknown <monty@narttu.mysql.fi>2003-06-05 00:12:45 +0300
committerunknown <monty@narttu.mysql.fi>2003-06-05 00:12:45 +0300
commitad5e39bf12b7aeefbc313e464a1349541a7b15c5 (patch)
tree824e127f68404d3fbe881d6619e34ad389d21202 /sql/item.cc
parent020baadcfebbd0f2248d9a3fa15f29d6e9d954b4 (diff)
parentc6c60f6ee819a238ab62e3f9608502c9a8f25b36 (diff)
downloadmariadb-git-ad5e39bf12b7aeefbc313e464a1349541a7b15c5.tar.gz
merge with public tree
BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union client/mysql.cc: Auto merged configure.in: Auto merged include/config-win.h: Auto merged include/mysql.h: Auto merged include/mysql_version.h.in: Auto merged libmysqld/lib_sql.cc: Auto merged mysql-test/r/alter_table.result: Auto merged mysql-test/r/create.result: Auto merged mysql-test/r/ctype_collate.result: Auto merged mysql-test/r/innodb.result: Auto merged mysql-test/r/show_check.result: Auto merged mysql-test/r/subselect.result: Auto merged mysql-test/r/type_blob.result: Auto merged mysql-test/t/subselect.test: Auto merged mysys/default.c: Auto merged sql/Makefile.am: Auto merged sql/field.cc: Auto merged sql/item.cc: Auto merged sql/item.h: Auto merged sql/item_cmpfunc.cc: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged sql/protocol.cc: Auto merged sql/set_var.cc: Auto merged sql/set_var.h: Auto merged sql/slave.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_string.cc: Auto merged sql/sql_string.h: Auto merged sql/sql_table.cc: Auto merged sql/sql_yacc.yy: Auto merged
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc34
1 files changed, 31 insertions, 3 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 42a949287e5..cdd78572a0a 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -117,7 +117,9 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
/*
- This function is only called when comparing items in the WHERE clause
+ This function is called when:
+ - Comparing items in the WHERE clause (when doing where optimization)
+ - When trying to find an ORDER BY/GROUP BY item in the SELECT part
*/
bool Item::eq(const Item *item, bool binary_cmp) const
@@ -243,6 +245,7 @@ void Item_field::set_field(Field *field_par)
decimals= field->decimals();
table_name=field_par->table_name;
field_name=field_par->field_name;
+ db_name=field_par->table->table_cache_key;
unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
set_charset(field_par->charset(), COER_IMPLICIT);
}
@@ -344,9 +347,34 @@ longlong Item_field::val_int_result()
return result_field->val_int();
}
+
bool Item_field::eq(const Item *item, bool binary_cmp) const
{
- return item->type() == FIELD_ITEM && ((Item_field*) item)->field == field;
+ if (item->type() != FIELD_ITEM)
+ return 0;
+
+ Item_field *item_field= (Item_field*) item;
+ if (item_field->field)
+ return item_field->field == field;
+ /*
+ We may come here when we are trying to find a function in a GROUP BY
+ clause from the select list.
+ In this case the '100 % correct' way to do this would be to first
+ run fix_fields() on the GROUP BY item and then retry this function, but
+ I think it's better to relax the checking a bit as we will in
+ most cases do the correct thing by just checking the field name.
+ (In cases where we would choose wrong we would have to generate a
+ ER_NON_UNIQ_ERROR).
+ */
+ return (!my_strcasecmp(system_charset_info, item_field->name,
+ field_name) &&
+ (!item_field->table_name ||
+ (!my_strcasecmp(table_alias_charset, item_field->table_name,
+ table_name) &&
+ (!item_field->db_name ||
+ (item_field->db_name && !my_strcasecmp(table_alias_charset,
+ item_field->db_name,
+ db_name))))));
}
table_map Item_field::used_tables() const
@@ -837,7 +865,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
return rf->fix_fields(thd, tables, ref) || rf->check_cols(1);
}
}
- }
+ }
else if (!tmp)
return -1;