Commit 3c484480 authored by monty@tik.mysql.fi's avatar monty@tik.mysql.fi
Browse files

Split setup_fields to setup_tables and setup_fields

Fixed problem with UPDATE TABLE when keys wheren't always used.
parent 6f9a73a1
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -18704,7 +18704,13 @@ deleted and the new one is renamed. This is done in such a way that
all updates are automatically redirected to the new table without
any failed updates. While @code{ALTER TABLE} is executing, the original
table is readable by other clients. Updates and writes to the table
are stalled until the new table is ready:
are stalled until the new table is ready.
Note that if you use any other option to @code{ALTER TABLE} than
@code{RENAME}, @strong{MySQL} will always create a temporary table, even
if the data wouldn't strictly need to be copied (like when you change the
name of a column). We plan to fix this in the future, but as one doesn't
normally do @code{ALTER TABLE} that often this isn't that high on our TODO.
@itemize @bullet
@item
+4 −1
Original line number Diff line number Diff line
@@ -79,9 +79,12 @@ then
  basedir=@prefix@
  bindir=@bindir@
  execdir=@libexecdir@ 
else
elif test -d "$basedir/libexec"
  bindir="$basedir/bin"
  execdir="$basedir/libexec"
else
  bindir="$basedir/bin"
  execdir="$basedir/bin"
fi

mdata=$ldata/mysql
+1 −1
Original line number Diff line number Diff line
@@ -2231,7 +2231,7 @@ ha_innobase::create(

  	/* Create the table definition in Innobase */

  	if (error = create_table_def(trx, form, norm_name)) {
  	if ((error = create_table_def(trx, form, norm_name))) {

		trx_commit_for_mysql(trx);

+1 −0
Original line number Diff line number Diff line
@@ -402,6 +402,7 @@ TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find);
SQL_SELECT *make_select(TABLE *head, table_map const_tables,
			table_map read_tables, COND *conds, int *error);
Item ** find_item_in_list(Item *item,List<Item> &items);
bool setup_tables(TABLE_LIST *tables);
int setup_fields(THD *thd,TABLE_LIST *tables,List<Item> &item,
		 bool set_query_id,List<Item> *sum_func_list);
int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds);
+38 −29
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ static bool insert_fields(THD *thd,TABLE_LIST *tables, const char *table_name,
			  List_iterator<Item> *it);
static void free_cache_entry(TABLE *entry);
static void mysql_rm_tmp_tables(void);
static key_map get_key_map_from_key_list(THD *thd, TABLE *table,
static key_map get_key_map_from_key_list(TABLE *table,
					 List<String> *index_list);


@@ -1711,11 +1711,8 @@ find_item_in_list(Item *find,List<Item> &items)
  return found;
}


/****************************************************************************
** Check that all given fields exists and fill struct with current data
** Check also that the 'used keys' and 'ignored keys' exists and set up the
** table structure accordingly
****************************************************************************/

int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields,
@@ -1729,7 +1726,36 @@ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields,
  thd->allow_sum_func= test(sum_func_list);
  thd->where="field list";

  /* Remap table numbers if INSERT ... SELECT */
  while ((item=it++))
  {
    if (item->type() == Item::FIELD_ITEM &&
	((Item_field*) item)->field_name[0] == '*')
    {
      if (insert_fields(thd,tables,((Item_field*) item)->table_name,&it))
	DBUG_RETURN(-1); /* purecov: inspected */
    }
    else
    {
      if (item->fix_fields(thd,tables))
	DBUG_RETURN(-1); /* purecov: inspected */
      if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM)
	item->split_sum_func(*sum_func_list);
      thd->used_tables|=item->used_tables();
    }
  }
  DBUG_RETURN(test(thd->fatal_error));
}


/*
  Remap table numbers if INSERT ... SELECT
  Check also that the 'used keys' and 'ignored keys' exists and set up the
  table structure accordingly
*/

bool setup_tables(TABLE_LIST *tables)
{
  DBUG_ENTER("setup_tables");
  uint tablenr=0;
  for (TABLE_LIST *table=tables ; table ; table=table->next,tablenr++)
  {
@@ -1739,48 +1765,31 @@ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields,
      table->table->maybe_null=1;		// LEFT OUTER JOIN ...
    if (table->use_index)
    {
      key_map map= get_key_map_from_key_list(thd,table->table,
      key_map map= get_key_map_from_key_list(table->table,
					     table->use_index);
      if (map == ~(key_map) 0)
	DBUG_RETURN(-1);
	DBUG_RETURN(1);
      table->table->keys_in_use_for_query=map;
    }
    if (table->ignore_index)
    {
      key_map map= get_key_map_from_key_list(thd,table->table,
      key_map map= get_key_map_from_key_list(table->table,
					     table->ignore_index);
      if (map == ~(key_map) 0)
	DBUG_RETURN(-1);
	DBUG_RETURN(1);
      table->table->keys_in_use_for_query &= ~map;
    }
  }
  if (tablenr > MAX_TABLES)
  {
    my_error(ER_TOO_MANY_TABLES,MYF(0),MAX_TABLES);
    DBUG_RETURN(-1);
  }
  while ((item=it++))
  {
    if (item->type() == Item::FIELD_ITEM &&
	((Item_field*) item)->field_name[0] == '*')
    {
      if (insert_fields(thd,tables,((Item_field*) item)->table_name,&it))
	DBUG_RETURN(-1); /* purecov: inspected */
    }
    else
    {
      if (item->fix_fields(thd,tables))
	DBUG_RETURN(-1); /* purecov: inspected */
      if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM)
	item->split_sum_func(*sum_func_list);
      thd->used_tables|=item->used_tables();
    }
    DBUG_RETURN(1);
  }
  DBUG_RETURN(test(thd->fatal_error));
  DBUG_RETURN(0);
}


static key_map get_key_map_from_key_list(THD *thd, TABLE *table,
static key_map get_key_map_from_key_list(TABLE *table, 
					 List<String> *index_list)
{
  key_map map=0;
Loading