Commit 05821367 authored by unknown's avatar unknown

Fixed bug in UNION when doing UNION with the same tables


myisam/mi_extra.c:
  More debugging information
mysql-test/r/union.result:
  Added test for UNION bug
mysql-test/t/union.test:
  Added test for UNION bug
sql/sql_base.cc:
  Clear field->query_id when using UNION
sql/sql_parse.cc:
  Fix for UNION bug
sql/sql_union.cc:
  Cleanup
sql/table.h:
  Fix for UNION bug
tools/Makefile.am:
  Fix for compiling with MIT-threads
parent 28097f40
...@@ -34,6 +34,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function) ...@@ -34,6 +34,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function)
int error=0; int error=0;
MYISAM_SHARE *share=info->s; MYISAM_SHARE *share=info->s;
DBUG_ENTER("mi_extra"); DBUG_ENTER("mi_extra");
DBUG_PRINT("enter",("function: %d",(int) function));
switch (function) { switch (function) {
case HA_EXTRA_RESET: case HA_EXTRA_RESET:
......
...@@ -62,7 +62,11 @@ t2 ALL NULL NULL NULL NULL 4 ...@@ -62,7 +62,11 @@ t2 ALL NULL NULL NULL NULL 4
pseudo pseudo
dekad dekad
joce joce
pseudo1
joce
testtt
tsestset
pseudo pseudo1 same pseudo pseudo1 same
dekad joce 1
joce testtt 1
joce tsestset 1 joce tsestset 1
joce testtt 1
dekad joce 1
...@@ -60,5 +60,6 @@ CREATE TABLE t1 ( ...@@ -60,5 +60,6 @@ CREATE TABLE t1 (
) TYPE=MyISAM; ) TYPE=MyISAM;
INSERT INTO t1 (pseudo,pseudo1,same) VALUES ('joce', 'testtt', 1),('joce', 'tsestset', 1),('dekad', 'joce', 1); INSERT INTO t1 (pseudo,pseudo1,same) VALUES ('joce', 'testtt', 1),('joce', 'tsestset', 1),('dekad', 'joce', 1);
SELECT pseudo FROM t1 WHERE pseudo1='joce' UNION SELECT pseudo FROM t1 WHERE pseudo='joce'; SELECT pseudo FROM t1 WHERE pseudo1='joce' UNION SELECT pseudo FROM t1 WHERE pseudo='joce';
SELECT * FROM t1 WHERE pseudo1='joce' UNION SELECT * FROM t1 WHERE pseudo='joce'; SELECT pseudo1 FROM t1 WHERE pseudo1='joce' UNION SELECT pseudo1 FROM t1 WHERE pseudo='joce';
SELECT * FROM t1 WHERE pseudo1='joce' UNION SELECT * FROM t1 WHERE pseudo='joce' order by pseudo desc;
drop table t1; drop table t1;
...@@ -1590,7 +1590,8 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length, ...@@ -1590,7 +1590,8 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length,
else else
thd->dupp_field=field; thd->dupp_field=field;
} }
if (check_grants && !thd->master_access && check_grant_column(thd,table,name,length)) if (check_grants && !thd->master_access &&
check_grant_column(thd,table,name,length))
return WRONG_GRANT; return WRONG_GRANT;
return field; return field;
} }
...@@ -1808,6 +1809,12 @@ bool setup_tables(TABLE_LIST *tables) ...@@ -1808,6 +1809,12 @@ bool setup_tables(TABLE_LIST *tables)
DBUG_RETURN(1); DBUG_RETURN(1);
table->keys_in_use_for_query &= ~map; table->keys_in_use_for_query &= ~map;
} }
if (table_list->shared)
{
/* Clear query_id that may have been set by previous select */
for (Field **ptr=table->field ; *ptr ; ptr++)
(*ptr)->query_id=0;
}
} }
if (tablenr > MAX_TABLES) if (tablenr > MAX_TABLES)
{ {
......
...@@ -2921,8 +2921,10 @@ static bool create_total_list(THD *thd, LEX *lex, TABLE_LIST **result) ...@@ -2921,8 +2921,10 @@ static bool create_total_list(THD *thd, LEX *lex, TABLE_LIST **result)
} }
*new_table_list= cursor; *new_table_list= cursor;
new_table_list= &cursor->next; new_table_list= &cursor->next;
*new_table_list=0; // end result list *new_table_list=0; // end result list
} }
else
aux->shared=1; // Mark that it's used twice
aux->table=(TABLE *) cursor; aux->table=(TABLE *) cursor;
} }
} }
......
...@@ -37,7 +37,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result) ...@@ -37,7 +37,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
int res; int res;
DBUG_ENTER("mysql_union"); DBUG_ENTER("mysql_union");
/* Fix tables--to-be-unioned-from list to point at opened tables */ /* Fix tables 'to-be-unioned-from' list to point at opened tables */
for (sl=&lex->select_lex; sl; sl=sl->next) for (sl=&lex->select_lex; sl; sl=sl->next)
{ {
for (TABLE_LIST *cursor= (TABLE_LIST *)sl->table_list.first; for (TABLE_LIST *cursor= (TABLE_LIST *)sl->table_list.first;
......
...@@ -145,6 +145,7 @@ typedef struct st_table_list { ...@@ -145,6 +145,7 @@ typedef struct st_table_list {
uint outer_join; /* Which join type */ uint outer_join; /* Which join type */
bool straight; /* optimize with prev table */ bool straight; /* optimize with prev table */
bool updating; /* for replicate-do/ignore table */ bool updating; /* for replicate-do/ignore table */
bool shared; /* Used twice in union */
} TABLE_LIST; } TABLE_LIST;
typedef struct st_open_table_list typedef struct st_open_table_list
......
INCLUDES = @MT_INCLUDES@ -I$(srcdir)/../include \ INCLUDES = @MT_INCLUDES@ -I$(srcdir)/../include \
$(openssl_includes) -I../include $(openssl_includes) -I../include
LIBS= @openssl_libs@ LDADD= @CLIENT_EXTRA_LDFLAGS@ ../libmysql_r/libmysqlclient_r.la @openssl_libs@
LDADD= @CLIENT_EXTRA_LDFLAGS@ ../libmysql_r/libmysqlclient_r.la
bin_PROGRAMS= mysqlmanager bin_PROGRAMS= mysqlmanager
mysqlmanager_SOURCES= mysqlmanager.c mysqlmanager_SOURCES= mysqlmanager.c
mysqlmanager_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) mysqlmanager_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
......
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