Commit 4ac20ad4 authored by unknown's avatar unknown

Derived tables bug fix .......


sql/ha_myisam.cc:
  DISABLE KEYS warnings
sql/sql_table.cc:
  DISABLE KEYS warnings
parent 9be78a05
...@@ -1322,10 +1322,10 @@ SELECT t2.id, t1.label FROM t2 INNER JOIN ...@@ -1322,10 +1322,10 @@ SELECT t2.id, t1.label FROM t2 INNER JOIN
(SELECT t1.id_object as id_object FROM t1 WHERE t1.label LIKE '%test%') AS lbl (SELECT t1.id_object as id_object FROM t1 WHERE t1.label LIKE '%test%') AS lbl
ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object); ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
id label id label
3382 Fournisseur Test 3382 Test
102 Fournisseur Test 102 Le Pekin (Test)
1794 Fournisseur Test 1794 Test de resto
1822 Fournisseur Test 1822 Test 3
3524 Fournisseur Test 3524 Societe Test
3525 Fournisseur Test 3525 Fournisseur Test
drop table t1,t2; drop table t1,t2;
...@@ -701,12 +701,20 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize) ...@@ -701,12 +701,20 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
void ha_myisam::deactivate_non_unique_index(ha_rows rows) void ha_myisam::deactivate_non_unique_index(ha_rows rows)
{ {
MYISAM_SHARE* share = file->s; MYISAM_SHARE* share = file->s;
bool do_warning=0;
if (share->state.key_map == ((ulonglong) 1L << share->base.keys)-1) if (share->state.key_map == ((ulonglong) 1L << share->base.keys)-1)
{ {
if (!(specialflag & SPECIAL_SAFE_MODE)) if (!(specialflag & SPECIAL_SAFE_MODE))
{ {
if (rows == HA_POS_ERROR) if (rows == HA_POS_ERROR)
{
uint orig_update= file->update;
file->update ^= HA_STATE_CHANGED;
uint check_update= file->update;
mi_extra(file, HA_EXTRA_NO_KEYS, 0); mi_extra(file, HA_EXTRA_NO_KEYS, 0);
do_warning= (file->update == check_update) && file->state->records;
file->update= orig_update;
}
else else
{ {
/* /*
...@@ -731,6 +739,10 @@ void ha_myisam::deactivate_non_unique_index(ha_rows rows) ...@@ -731,6 +739,10 @@ void ha_myisam::deactivate_non_unique_index(ha_rows rows)
} }
else else
enable_activate_all_index=0; enable_activate_all_index=0;
if (do_warning)
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA,
ER(ER_ILLEGAL_HA), table->table_name);
} }
......
...@@ -789,6 +789,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, ...@@ -789,6 +789,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name,
DBUG_RETURN(0); DBUG_RETURN(0);
} }
table->query_id=thd->query_id; table->query_id=thd->query_id;
table->clear_query_id=1;
thd->tmp_table_used= 1; thd->tmp_table_used= 1;
goto reset; goto reset;
} }
...@@ -2050,8 +2051,9 @@ bool setup_tables(TABLE_LIST *tables) ...@@ -2050,8 +2051,9 @@ bool setup_tables(TABLE_LIST *tables)
table->keys_in_use_for_query &= ~map; table->keys_in_use_for_query &= ~map;
} }
table->used_keys &= table->keys_in_use_for_query; table->used_keys &= table->keys_in_use_for_query;
if (table_list->shared) if (table_list->shared || table->clear_query_id)
{ {
table->clear_query_id= 0;
/* Clear query_id that may have been set by previous select */ /* Clear query_id that may have been set by previous select */
for (Field **ptr=table->field ; *ptr ; ptr++) for (Field **ptr=table->field ; *ptr ; ptr++)
(*ptr)->query_id=0; (*ptr)->query_id=0;
......
...@@ -123,6 +123,16 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, ...@@ -123,6 +123,16 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit,
goto exit; goto exit;
} }
/*
This is done in order to redo all field optimisations when any of the
involved tables is used in the outer query
*/
if (tables)
{
for (TABLE_LIST *cursor= tables; cursor; cursor= cursor->next)
cursor->table->clear_query_id= 1;
}
item_list= select_cursor->item_list; item_list= select_cursor->item_list;
select_cursor->with_wild= 0; select_cursor->with_wild= 0;
if (setup_ref_array(thd, &select_cursor->ref_pointer_array, if (setup_ref_array(thd, &select_cursor->ref_pointer_array,
...@@ -223,8 +233,6 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, ...@@ -223,8 +233,6 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit,
/* Add new temporary table to list of open derived tables */ /* Add new temporary table to list of open derived tables */
table->next= thd->derived_tables; table->next= thd->derived_tables;
thd->derived_tables= table; thd->derived_tables= table;
thd->query_id++;
query_id++;
} }
exit: exit:
......
...@@ -1835,10 +1835,19 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -1835,10 +1835,19 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
/* COND_refresh will be signaled in close_thread_tables() */ /* COND_refresh will be signaled in close_thread_tables() */
break; break;
case DISABLE: case DISABLE:
if (table->db_type == DB_TYPE_MYISAM)
{
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
wait_while_table_is_used(thd, table); wait_while_table_is_used(thd, table);
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
table->file->deactivate_non_unique_index(HA_POS_ERROR); table->file->deactivate_non_unique_index(HA_POS_ERROR);
}
else
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA,
ER(ER_ILLEGAL_HA), table->table_name);
break;
/* COND_refresh will be signaled in close_thread_tables() */ /* COND_refresh will be signaled in close_thread_tables() */
break; break;
} }
......
...@@ -116,6 +116,7 @@ struct st_table { ...@@ -116,6 +116,7 @@ struct st_table {
my_bool crashed; my_bool crashed;
my_bool is_view; my_bool is_view;
my_bool no_keyread; my_bool no_keyread;
my_bool clear_query_id; /* To reset query_id for tables and cols */
Field *next_number_field, /* Set if next_number is activated */ Field *next_number_field, /* Set if next_number is activated */
*found_next_number_field, /* Set on open */ *found_next_number_field, /* Set on open */
*rowid_field; *rowid_field;
......
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