mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
BitKeeper/etc/logging_ok: auto-union sql/item.cc: Auto merged sql/item.h: Auto merged sql/mysql_priv.h: Auto merged sql/sql_acl.cc: Auto merged sql/sql_base.cc: Manual merge
This commit is contained in:
@ -1793,33 +1793,42 @@ bool rm_temporary_table(enum db_type base, char *path)
|
||||
#define WRONG_GRANT (Field*) -1
|
||||
|
||||
Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length,
|
||||
bool check_grants, bool allow_rowid)
|
||||
bool check_grants, bool allow_rowid,
|
||||
uint *cached_field_index_ptr)
|
||||
{
|
||||
Field *field;
|
||||
if (table->name_hash.records)
|
||||
Field **field_ptr, *field;
|
||||
uint cached_field_index= *cached_field_index_ptr;
|
||||
|
||||
/* We assume here that table->field < NO_CACHED_FIELD_INDEX = UINT_MAX */
|
||||
if (cached_field_index < table->fields &&
|
||||
!my_strcasecmp(system_charset_info,
|
||||
table->field[cached_field_index]->field_name, name))
|
||||
field_ptr= table->field + cached_field_index;
|
||||
else if (table->name_hash.records)
|
||||
field_ptr= (Field**)hash_search(&table->name_hash,(byte*) name,
|
||||
length);
|
||||
else
|
||||
{
|
||||
if ((field=(Field*) hash_search(&table->name_hash,(byte*) name,
|
||||
length)))
|
||||
goto found;
|
||||
if (!(field_ptr= table->field))
|
||||
return (Field *)0;
|
||||
for (; *field_ptr; ++field_ptr)
|
||||
if (!my_strcasecmp(system_charset_info, (*field_ptr)->field_name, name))
|
||||
break;
|
||||
}
|
||||
|
||||
if (field_ptr && *field_ptr)
|
||||
{
|
||||
*cached_field_index_ptr= field_ptr - table->field;
|
||||
field= *field_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
Field **ptr;
|
||||
if (!(ptr=table->field))
|
||||
return (Field *)0;
|
||||
while ((field = *ptr++))
|
||||
{
|
||||
if (!my_strcasecmp(system_charset_info, field->field_name, name))
|
||||
goto found;
|
||||
}
|
||||
if (!allow_rowid ||
|
||||
my_strcasecmp(system_charset_info, name, "_rowid") ||
|
||||
!(field=table->rowid_field))
|
||||
return (Field*) 0;
|
||||
}
|
||||
if (allow_rowid &&
|
||||
!my_strcasecmp(system_charset_info, name, "_rowid") &&
|
||||
(field=table->rowid_field))
|
||||
goto found;
|
||||
return (Field*) 0;
|
||||
|
||||
found:
|
||||
if (thd->set_query_id)
|
||||
{
|
||||
if (field->query_id != thd->query_id)
|
||||
@ -1874,6 +1883,31 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
|
||||
uint length=(uint) strlen(name);
|
||||
char name_buff[NAME_LEN+1];
|
||||
|
||||
|
||||
if (item->cached_table)
|
||||
{
|
||||
/*
|
||||
This shortcut is used by prepared statements. We assuming that
|
||||
TABLE_LIST *tables is not changed during query execution (which
|
||||
is true for all queries except RENAME but luckily RENAME doesn't
|
||||
use fields...) so we can rely on reusing pointer to its member.
|
||||
With this optimisation we also miss case when addition of one more
|
||||
field makes some prepared query ambiguous and so erronous, but we
|
||||
accept this trade off.
|
||||
*/
|
||||
found= find_field_in_table(thd,tables->table,name,length,
|
||||
test(tables->table->grant.want_privilege),
|
||||
1, &(item->cached_field_index));
|
||||
|
||||
if (found)
|
||||
{
|
||||
(*where)= tables;
|
||||
if (found == WRONG_GRANT)
|
||||
return (Field*) 0;
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
if (db && lower_case_table_names)
|
||||
{
|
||||
/*
|
||||
@ -1898,10 +1932,10 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
|
||||
Field *find=find_field_in_table(thd,tables->table,name,length,
|
||||
test(tables->table->grant.
|
||||
want_privilege),
|
||||
1);
|
||||
1, &(item->cached_field_index));
|
||||
if (find)
|
||||
{
|
||||
(*where)= tables;
|
||||
(*where)= item->cached_table= tables;
|
||||
if (find == WRONG_GRANT)
|
||||
return (Field*) 0;
|
||||
if (db || !thd->where)
|
||||
@ -1955,12 +1989,12 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
|
||||
|
||||
Field *field=find_field_in_table(thd,tables->table,name,length,
|
||||
test(tables->table->grant.want_privilege),
|
||||
allow_rowid);
|
||||
allow_rowid, &(item->cached_field_index));
|
||||
if (field)
|
||||
{
|
||||
if (field == WRONG_GRANT)
|
||||
return (Field*) 0;
|
||||
(*where)= tables;
|
||||
(*where)= item->cached_table= tables;
|
||||
if (found)
|
||||
{
|
||||
if (!thd->where) // Returns first found
|
||||
@ -2308,7 +2342,7 @@ insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name,
|
||||
!find_field_in_table(thd, natural_join_table, field->field_name,
|
||||
strlen(field->field_name), 0, 0))
|
||||
{
|
||||
Item_field *item= new Item_field(field);
|
||||
Item_field *item= new Item_field(thd, field);
|
||||
if (!found++)
|
||||
(void) it->replace(item); // Replace '*'
|
||||
else
|
||||
|
Reference in New Issue
Block a user