Commit 4b56b0ee authored by unknown's avatar unknown

Split setup_fields to setup_tables and setup_fields

Fixed problem with UPDATE TABLE when keys wheren't always used.


Docs/manual.texi:
  Added comment to ALTER TABLE
scripts/mysql_install_db.sh:
  Added test for mysqld in libexec
sql/ha_innobase.cc:
  Removed compiler warning
sql/mysql_priv.h:
  Split setup_fields to setup_tables and setup_fields
sql/sql_base.cc:
  Split setup_fields to setup_tables and setup_fields
sql/sql_insert.cc:
  Split setup_fields to setup_tables and setup_fields
sql/sql_load.cc:
  Split setup_fields to setup_tables and setup_fields
sql/sql_parse.cc:
  Fixed missing 'mysql_info" with now clients.
sql/sql_select.cc:
  Split setup_fields to setup_tables and setup_fields
sql/sql_update.cc:
  Fixed problem with UPDATE TABLE when keys wheren't always used.
sql/sql_yacc.yy:
  Small isolation change
parent 6257ee76
...@@ -18704,7 +18704,13 @@ deleted and the new one is renamed. This is done in such a way that ...@@ -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 all updates are automatically redirected to the new table without
any failed updates. While @code{ALTER TABLE} is executing, the original any failed updates. While @code{ALTER TABLE} is executing, the original
table is readable by other clients. Updates and writes to the table 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 @itemize @bullet
@item @item
...@@ -79,9 +79,12 @@ then ...@@ -79,9 +79,12 @@ then
basedir=@prefix@ basedir=@prefix@
bindir=@bindir@ bindir=@bindir@
execdir=@libexecdir@ execdir=@libexecdir@
else elif test -d "$basedir/libexec"
bindir="$basedir/bin" bindir="$basedir/bin"
execdir="$basedir/libexec" execdir="$basedir/libexec"
else
bindir="$basedir/bin"
execdir="$basedir/bin"
fi fi
mdata=$ldata/mysql mdata=$ldata/mysql
......
...@@ -2231,7 +2231,7 @@ ha_innobase::create( ...@@ -2231,7 +2231,7 @@ ha_innobase::create(
/* Create the table definition in Innobase */ /* 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); trx_commit_for_mysql(trx);
......
...@@ -402,6 +402,7 @@ TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find); ...@@ -402,6 +402,7 @@ TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find);
SQL_SELECT *make_select(TABLE *head, table_map const_tables, SQL_SELECT *make_select(TABLE *head, table_map const_tables,
table_map read_tables, COND *conds, int *error); table_map read_tables, COND *conds, int *error);
Item ** find_item_in_list(Item *item,List<Item> &items); 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, int setup_fields(THD *thd,TABLE_LIST *tables,List<Item> &item,
bool set_query_id,List<Item> *sum_func_list); bool set_query_id,List<Item> *sum_func_list);
int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds); int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds);
......
...@@ -39,7 +39,7 @@ static bool insert_fields(THD *thd,TABLE_LIST *tables, const char *table_name, ...@@ -39,7 +39,7 @@ static bool insert_fields(THD *thd,TABLE_LIST *tables, const char *table_name,
List_iterator<Item> *it); List_iterator<Item> *it);
static void free_cache_entry(TABLE *entry); static void free_cache_entry(TABLE *entry);
static void mysql_rm_tmp_tables(void); 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); List<String> *index_list);
...@@ -1711,11 +1711,8 @@ find_item_in_list(Item *find,List<Item> &items) ...@@ -1711,11 +1711,8 @@ find_item_in_list(Item *find,List<Item> &items)
return found; return found;
} }
/**************************************************************************** /****************************************************************************
** Check that all given fields exists and fill struct with current data ** 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, 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, ...@@ -1729,7 +1726,36 @@ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields,
thd->allow_sum_func= test(sum_func_list); thd->allow_sum_func= test(sum_func_list);
thd->where="field 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; uint tablenr=0;
for (TABLE_LIST *table=tables ; table ; table=table->next,tablenr++) 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, ...@@ -1739,48 +1765,31 @@ int setup_fields(THD *thd, TABLE_LIST *tables, List<Item> &fields,
table->table->maybe_null=1; // LEFT OUTER JOIN ... table->table->maybe_null=1; // LEFT OUTER JOIN ...
if (table->use_index) 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); table->use_index);
if (map == ~(key_map) 0) if (map == ~(key_map) 0)
DBUG_RETURN(-1); DBUG_RETURN(1);
table->table->keys_in_use_for_query=map; table->table->keys_in_use_for_query=map;
} }
if (table->ignore_index) 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); table->ignore_index);
if (map == ~(key_map) 0) if (map == ~(key_map) 0)
DBUG_RETURN(-1); DBUG_RETURN(1);
table->table->keys_in_use_for_query &= ~map; table->table->keys_in_use_for_query &= ~map;
} }
} }
if (tablenr > MAX_TABLES) if (tablenr > MAX_TABLES)
{ {
my_error(ER_TOO_MANY_TABLES,MYF(0),MAX_TABLES); my_error(ER_TOO_MANY_TABLES,MYF(0),MAX_TABLES);
DBUG_RETURN(-1); DBUG_RETURN(1);
} }
while ((item=it++)) DBUG_RETURN(0);
{
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));
} }
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) List<String> *index_list)
{ {
key_map map=0; key_map map=0;
......
...@@ -78,7 +78,7 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields, ...@@ -78,7 +78,7 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields,
table_list.grant=table->grant; table_list.grant=table->grant;
thd->dupp_field=0; thd->dupp_field=0;
if (setup_fields(thd,&table_list,fields,1,0)) if (setup_tables(&table_list) || setup_fields(thd,&table_list,fields,1,0))
return -1; return -1;
if (thd->dupp_field) if (thd->dupp_field)
{ {
...@@ -151,7 +151,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields, ...@@ -151,7 +151,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields,
save_time_stamp=table->time_stamp; save_time_stamp=table->time_stamp;
values= its++; values= its++;
if (check_insert_fields(thd,table,fields,*values,1) || if (check_insert_fields(thd,table,fields,*values,1) ||
setup_fields(thd,table_list,*values,0,0)) setup_tables(table_list) || setup_fields(thd,table_list,*values,0,0))
{ {
table->time_stamp=save_time_stamp; table->time_stamp=save_time_stamp;
goto abort; goto abort;
...@@ -168,7 +168,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields, ...@@ -168,7 +168,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, List<Item> &fields,
table->time_stamp=save_time_stamp; table->time_stamp=save_time_stamp;
goto abort; goto abort;
} }
if (setup_fields(thd,table_list,*values,0,0)) if (setup_tables(table_list) || setup_fields(thd,table_list,*values,0,0))
{ {
table->time_stamp=save_time_stamp; table->time_stamp=save_time_stamp;
goto abort; goto abort;
......
...@@ -91,7 +91,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, ...@@ -91,7 +91,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
else else
{ // Part field list { // Part field list
thd->dupp_field=0; thd->dupp_field=0;
if (setup_fields(thd,table_list,fields,1,0) < 0) if (setup_tables(table_list) || setup_fields(thd,table_list,fields,1,0))
DBUG_RETURN(-1); DBUG_RETURN(-1);
if (thd->dupp_field) if (thd->dupp_field)
{ {
......
...@@ -455,7 +455,8 @@ check_connections(THD *thd) ...@@ -455,7 +455,8 @@ check_connections(THD *thd)
db=strend(passwd)+1; db=strend(passwd)+1;
if (thd->client_capabilities & CLIENT_INTERACTIVE) if (thd->client_capabilities & CLIENT_INTERACTIVE)
thd->inactive_timeout=net_interactive_timeout; thd->inactive_timeout=net_interactive_timeout;
if (thd->client_capabilities & CLIENT_TRANSACTIONS) if ((thd->client_capabilities & CLIENT_TRANSACTIONS) &&
opt_using_transactions)
thd->net.return_status= &thd->server_status; thd->net.return_status= &thd->server_status;
net->timeout=net_read_timeout; net->timeout=net_read_timeout;
if (check_user(thd,COM_CONNECT, user, passwd, db, 1)) if (check_user(thd,COM_CONNECT, user, passwd, db, 1))
......
...@@ -174,7 +174,8 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds, ...@@ -174,7 +174,8 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
thd->proc_info="init"; thd->proc_info="init";
thd->used_tables=0; // Updated by setup_fields thd->used_tables=0; // Updated by setup_fields
if (setup_fields(thd,tables,fields,1,&all_fields) || if (setup_tables(tables) ||
setup_fields(thd,tables,fields,1,&all_fields) ||
setup_conds(thd,tables,&conds) || setup_conds(thd,tables,&conds) ||
setup_order(thd,tables,fields,all_fields,order) || setup_order(thd,tables,fields,all_fields,order) ||
setup_group(thd,tables,fields,all_fields,group,&hidden_group_fields) || setup_group(thd,tables,fields,all_fields,group,&hidden_group_fields) ||
......
...@@ -70,7 +70,7 @@ int mysql_update(THD *thd,TABLE_LIST *table_list,List<Item> &fields, ...@@ -70,7 +70,7 @@ int mysql_update(THD *thd,TABLE_LIST *table_list,List<Item> &fields,
table->quick_keys=0; table->quick_keys=0;
want_privilege=table->grant.want_privilege; want_privilege=table->grant.want_privilege;
table->grant.want_privilege=(SELECT_ACL & ~table->grant.privilege); table->grant.want_privilege=(SELECT_ACL & ~table->grant.privilege);
if (setup_conds(thd,table_list,&conds)) if (setup_tables(table_list) || setup_conds(thd,table_list,&conds))
DBUG_RETURN(-1); /* purecov: inspected */ DBUG_RETURN(-1); /* purecov: inspected */
old_used_keys=table->used_keys; // Keys used in WHERE old_used_keys=table->used_keys; // Keys used in WHERE
......
...@@ -2785,7 +2785,7 @@ set_isolation: ...@@ -2785,7 +2785,7 @@ set_isolation:
default_tx_isolation= $2; default_tx_isolation= $2;
} }
| SESSION_SYM tx_isolation | SESSION_SYM tx_isolation
{ current_thd->session_tx_isolation= $2; } { current_thd->session_tx_isolation= Lex->tx_isolation= $2; }
| tx_isolation | tx_isolation
{ Lex->tx_isolation= $1; } { Lex->tx_isolation= $1; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment