Skip to content

Commit

Permalink
cleanup: find_field_in_table()
Browse files Browse the repository at this point in the history
don't duplicate functionality, use TABLE::find_field_by_name()

also, set cached_field_index_ptr for _rowid field
  • Loading branch information
vuvova committed Feb 12, 2018
1 parent f894f90 commit 34857b9
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5628,7 +5628,7 @@ Field *
find_field_in_table(THD *thd, TABLE *table, const char *name, size_t length,
bool allow_rowid, uint *cached_field_index_ptr)
{
Field **field_ptr, *field;
Field *field;
uint cached_field_index= *cached_field_index_ptr;
DBUG_ENTER("find_field_in_table");
DBUG_PRINT("enter", ("table: '%s', field name: '%s'", table->alias.c_ptr(),
Expand All @@ -5638,38 +5638,18 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, size_t length,
if (cached_field_index < table->s->fields &&
!my_strcasecmp(system_charset_info,
table->field[cached_field_index]->field_name.str, name))
field_ptr= table->field + cached_field_index;
else if (table->s->name_hash.records)
{
field_ptr= (Field**) my_hash_search(&table->s->name_hash, (uchar*) name,
length);
if (field_ptr)
{
/*
field_ptr points to field in TABLE_SHARE. Convert it to the matching
field in table
*/
field_ptr= (table->field + (field_ptr - table->s->field));
}
}
field= table->field[cached_field_index];
else
{
if (!(field_ptr= table->field))
DBUG_RETURN((Field *)0);
for (; *field_ptr; ++field_ptr)
if (!my_strcasecmp(system_charset_info, (*field_ptr)->field_name.str,
name))
break;
LEX_CSTRING fname= {name, length};
field= table->find_field_by_name(&fname);
}

if (field_ptr && *field_ptr)
if (field)
{
if ((*field_ptr)->invisible == INVISIBLE_FULL &&
if (field->invisible == INVISIBLE_FULL &&
DBUG_EVALUATE_IF("test_completely_invisible", 0, 1))
DBUG_RETURN((Field*)0);

*cached_field_index_ptr= (uint)(field_ptr - table->field);
field= *field_ptr;
}
else
{
Expand All @@ -5679,6 +5659,7 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, size_t length,
DBUG_RETURN((Field*) 0);
field= table->field[table->s->rowid_field_offset-1];
}
*cached_field_index_ptr= field->field_index;

update_field_dependencies(thd, field, table);

Expand Down

0 comments on commit 34857b9

Please sign in to comment.