mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 21:12:26 +01:00
034b44cb9f
BitKeeper/etc/logging_ok: auto-union scripts/make_win_src_distribution.old: Merge rename: scripts/make_win_src_distribution.sh -> scripts/make_win_src_distribution.old BUILD/compile-pentium-debug-max: Auto merged BitKeeper/deleted/.del-sel000001.result~383913ae4505ec86: Auto merged BitKeeper/deleted/.del-sel000001.test~9567c1646058cc: Auto merged Build-tools/Bootstrap: Auto merged Build-tools/Do-compile: Auto merged Docs/Makefile.am: Auto merged client/get_password.c: Auto merged client/mysql.cc: Auto merged client/mysqltest.c: Auto merged extra/perror.c: Auto merged include/config-win.h: Auto merged include/my_sys.h: Auto merged innobase/btr/btr0cur.c: Auto merged innobase/btr/btr0pcur.c: Auto merged innobase/buf/buf0buf.c: Auto merged innobase/buf/buf0flu.c: Auto merged innobase/dict/dict0dict.c: Auto merged innobase/dict/dict0load.c: Auto merged innobase/include/buf0buf.h: Auto merged innobase/include/log0recv.h: Auto merged innobase/include/row0sel.h: Auto merged innobase/include/srv0srv.h: Auto merged innobase/include/ut0mem.h: Auto merged innobase/lock/lock0lock.c: Auto merged innobase/log/log0log.c: Auto merged innobase/mem/mem0pool.c: Auto merged innobase/os/os0file.c: Auto merged innobase/row/row0mysql.c: Auto merged innobase/row/row0sel.c: Auto merged innobase/srv/srv0srv.c: Auto merged innobase/srv/srv0start.c: Auto merged innobase/trx/trx0sys.c: Auto merged innobase/trx/trx0trx.c: Auto merged innobase/ut/ut0mem.c: Auto merged innobase/ut/ut0ut.c: Auto merged myisam/ft_boolean_search.c: Auto merged myisam/mi_check.c: Auto merged myisam/mi_extra.c: Auto merged myisam/mi_key.c: Auto merged myisam/myisamdef.h: Auto merged myisammrg/myrg_queue.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/ctype_latin1_de.result: Auto merged mysql-test/r/flush.result: Auto merged mysql-test/r/func_time.result: Auto merged mysql-test/r/grant_cache.result: Auto merged mysql-test/r/join.result: Auto merged mysql-test/r/join_outer.result: Auto merged mysql-test/r/range.result: Auto merged mysql-test/r/rpl000018.result: Auto merged mysql-test/r/rpl_insert_id.result: Auto merged mysql-test/r/rpl_master_pos_wait.result: Auto merged mysql-test/r/rpl_relayspace.result: Auto merged mysql-test/r/select_safe.result: Auto merged mysql-test/r/symlink.result: Auto merged mysql-test/r/type_date.result: Auto merged mysql-test/r/type_datetime.result: Auto merged mysql-test/t/alias.test: Auto merged mysql-test/t/ctype_latin1_de.test: Auto merged mysql-test/t/fulltext_left_join.test: Auto merged mysql-test/t/func_time.test: Auto merged mysql-test/t/handler.test: Auto merged mysql-test/t/heap.test: Auto merged mysql-test/t/join.test: Auto merged mysql-test/t/join_outer.test: Auto merged mysql-test/t/order_by.test: Auto merged mysql-test/t/range.test: Auto merged mysql-test/t/rpl000001.test: Auto merged mysql-test/t/rpl000018.test: Auto merged mysql-test/t/rpl_insert_id.test: Auto merged mysql-test/t/sel000100.test: Auto merged mysql-test/t/select_safe.test: Auto merged mysql-test/t/type_date.test: Auto merged mysql-test/t/type_datetime.test: Auto merged mysql-test/t/user_var.test: Auto merged mysys/default.c: Auto merged mysys/mf_format.c: Auto merged mysys/my_getopt.c: Auto merged mysys/thr_lock.c: Auto merged mysys/tree.c: Auto merged scripts/Makefile.am: Auto merged scripts/mysql_install_db.sh: Auto merged scripts/mysqld_safe.sh: Auto merged sql/Makefile.am: Auto merged sql/field_conv.cc: Auto merged sql/ha_innodb.h: Auto merged sql/ha_myisam.cc: Auto merged sql/ha_myisammrg.h: Auto merged sql/handler.cc: Auto merged sql/handler.h: Auto merged sql/item.h: Auto merged sql/item_func.cc: Auto merged sql/item_timefunc.cc: Auto merged sql/net_serv.cc: Auto merged sql/nt_servc.cc: Auto merged sql/opt_range.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_cache.h: Auto merged sql/sql_db.cc: Auto merged sql/sql_delete.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_list.h: Auto merged sql/sql_load.cc: Auto merged sql/sql_rename.cc: Auto merged sql/sql_repl.h: Auto merged sql/sql_update.cc: Auto merged sql/table.cc: Auto merged sql/table.h: Auto merged sql/uniques.cc: Auto merged support-files/mysql.spec.sh: Auto merged vio/viosocket.c: Auto merged BitKeeper/deleted/.del-ctype-latin1_de.c~c5d8f9208bceb98e: merge BitKeeper/deleted/.del-mini_client.cc~8677895ec8169183: merge acinclude.m4: Merge with 4.0 (openssl patch) client/mysqlbinlog.cc: Merge with 4.0 in which we had added code from 4.1 (We are basicly only using the 4.1 code here) configure.in: Keep 4.1 file heap/hp_open.c: merge with 4.0 include/my_base.h: merge with 4.0 include/my_global.h: merge with 4.0 include/mysqld_error.h: merge with 4.0 innobase/ha/ha0ha.c: merge with 4.0 (Code should be same but we use indentaion from 4.0) innobase/log/log0recv.c: merge with 4.0 libmysql/libmysql.c: Remove with 4.0 code that was ported from 4.1 libmysqld/lib_sql.cc: merge with 4.0 myisam/mi_open.c: Remove 4.0 specific code myisam/myisamchk.c: merge with 4.0 myisammrg/myrg_rkey.c: merge with 4.0 mysql-test/r/alter_table.result: May need to be fixed after merge mysql-test/r/create.result: May need to be fixed after merge mysql-test/r/distinct.result: May need to be fixed after merge mysql-test/r/drop.result: May need to be fixed after merge mysql-test/r/fulltext.result: May need to be fixed after merge mysql-test/r/func_set.result: May need to be fixed after merge mysql-test/r/func_str.result: May need to be fixed after merge mysql-test/r/func_test.result: May need to be fixed after merge mysql-test/r/grant.result: May need to be fixed after merge mysql-test/r/group_by.result: May need to be fixed after merge mysql-test/r/handler.result: May need to be fixed after merge mysql-test/r/heap.result: May need to be fixed after merge mysql-test/r/innodb.result: May need to be fixed after merge mysql-test/r/insert.result: May need to be fixed after merge mysql-test/r/insert_select.result: May need to be fixed after merge mysql-test/r/key_diff.result: May need to be fixed after merge mysql-test/r/merge.result: May need to be fixed after merge mysql-test/r/myisam.result: May need to be fixed after merge mysql-test/r/order_by.result: May need to be fixed after merge mysql-test/r/query_cache.result: May need to be fixed after merge mysql-test/r/rpl_flush_log_loop.result: May need to be fixed after merge mysql-test/r/rpl_loaddata.result: May need to be fixed after merge mysql-test/r/rpl_log.result: May need to be fixed after merge mysql-test/r/rpl_log_pos.result: May need to be fixed after merge mysql-test/r/rpl_rotate_logs.result: May need to be fixed after merge mysql-test/r/select.result: May need to be fixed after merge mysql-test/r/union.result: May need to be fixed after merge mysql-test/r/user_var.result: May need to be fixed after merge mysql-test/t/alter_table.test: merge with 4.0 mysql-test/t/create.test: merge with 4.0 mysql-test/t/distinct.test: merge with 4.0 mysql-test/t/drop.test: merge with 4.0 mysql-test/t/flush.test: merge with 4.0 mysql-test/t/fulltext.test: merge with 4.0 mysql-test/t/func_set.test: merge with 4.0 mysql-test/t/func_str.test: merge with 4.0 mysql-test/t/func_test.test: merge with 4.0 mysql-test/t/grant.test: merge with 4.0 mysql-test/t/grant_cache.test: merge with 4.0 mysql-test/t/innodb.test: Add back EXPLAIN and SHOW KEYS statements, but make them independent of number of rows returned by InnoDB mysql-test/t/insert.test: merge with 4.0 mysql-test/t/insert_select.test: merge with 4.0 mysql-test/t/merge.test: merge with 4.0 mysql-test/t/query_cache.test: merge with 4.0 mysql-test/t/rpl_flush_log_loop.test: merge with 4.0 mysql-test/t/rpl_loaddata.test: merge with 4.0 mysql-test/t/rpl_rotate_logs.test: merge with 4.0 mysql-test/t/select.test: merge with 4.0 mysql-test/t/symlink.test: merge with 4.0 mysql-test/t/union.test: merge with 4.0 mysys/charset.c: merge with 4.0 scripts/mysql_fix_privilege_tables.sh: merge with 4.0 (Add quoting for some variables) sql/field.h: merge with 4.0 sql/ha_innodb.cc: merge with 4.0 sql/item_cmpfunc.cc: merge with 4.0 sql/item_cmpfunc.h: merge with 4.0 sql/item_func.h: merge with 4.0 sql/item_strfunc.cc: merge with 4.0 Fixed null handling with ELT() sql/item_timefunc.h: merge with 4.0 sql/lex.h: merge with 4.0 sql/log.cc: merge with 4.0 sql/log_event.cc: Merge with 4.0 Cleanups: - Indentation - #endif comments - Replace strmov() with *pos++= for two byte strings - Moved variable declarations to start of functions - Merged identical code (LOAD_EVENT) - Added casts when subtracting pointers Did a full diff between this and 4.0 to ensure that the file is correct after merge. sql/log_event.h: merge with 4.0 sql/mysql_priv.h: merge with 4.0 sql/mysqld.cc: merge with 4.0 sql/repl_failsafe.cc: merge with 4.0 sql/set_var.cc: merge with 4.0 sql/set_var.h: merge with 4.0 sql/share/czech/errmsg.txt: merge with 4.0 sql/share/danish/errmsg.txt: merge with 4.0 sql/share/dutch/errmsg.txt: merge with 4.0 sql/share/english/errmsg.txt: merge with 4.0 sql/share/estonian/errmsg.txt: merge with 4.0 sql/share/french/errmsg.txt: merge with 4.0 sql/share/german/errmsg.txt: merge with 4.0 sql/share/greek/errmsg.txt: merge with 4.0 sql/share/hungarian/errmsg.txt: merge with 4.0 sql/share/italian/errmsg.txt: merge with 4.0 sql/share/japanese/errmsg.txt: merge with 4.0 sql/share/korean/errmsg.txt: merge with 4.0 sql/share/norwegian-ny/errmsg.txt: merge with 4.0 sql/share/norwegian/errmsg.txt: merge with 4.0 sql/share/polish/errmsg.txt: merge with 4.0 sql/share/portuguese/errmsg.txt: merge with 4.0 sql/share/romanian/errmsg.txt: merge with 4.0 sql/share/russian/errmsg.txt: merge with 4.0 sql/share/slovak/errmsg.txt: merge with 4.0 sql/share/spanish/errmsg.txt: merge with 4.0 sql/share/swedish/errmsg.txt: merge with 4.0 sql/share/ukrainian/errmsg.txt: merge with 4.0 sql/slave.cc: Merge + some indentation fixes sql/slave.h: merge with 4.0 sql/sql_acl.cc: merge with 4.0 Some end space removal to make it easier to do future merges sql/sql_acl.h: merge with 4.0 sql/sql_cache.cc: merge with 4.0 sql/sql_class.h: merge with 4.0 sql/sql_handler.cc: merge with 4.0 sql/sql_lex.cc: merge with 4.0 sql/sql_lex.h: merge with 4.0 sql/sql_parse.cc: merge with 4.0 sql/sql_repl.cc: merge with 4.0 sql/sql_select.cc: merge with 4.0 sql/sql_table.cc: merge with 4.0 sql/sql_union.cc: Merge with 4.0 Note that I couldn't find out how to merge OPTION_FOUND_ROWS handling so this has to be fixed later sql/sql_yacc.yy: merge with 4.0 Removed end space to make merge easier vio/Makefile.am: merge with 4.0
238 lines
9.8 KiB
Text
238 lines
9.8 KiB
Text
#
|
|
# Test of unions
|
|
#
|
|
|
|
--disable_warnings
|
|
drop table if exists t1,t2,t3,t4,t5,t6;
|
|
--enable_warnings
|
|
|
|
CREATE TABLE t1 (a int not null, b char (10) not null);
|
|
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c');
|
|
CREATE TABLE t2 (a int not null, b char (10) not null);
|
|
insert into t2 values (3,'c'),(4,'d'),(5,'f'),(6,'e');
|
|
|
|
select a,b from t1 union select a,b from t2;
|
|
select a,b from t1 union all select a,b from t2;
|
|
select a,b from t1 union all select a,b from t2 order by b;
|
|
select a,b from t1 union all select a,b from t2 union select 7,'g';
|
|
select 0,'#' union select a,b from t1 union all select a,b from t2 union select 7,'gg';
|
|
select a,b from t1 union select a,b from t1;
|
|
select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 group by b;
|
|
|
|
# Test alternate syntax for unions
|
|
(select a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 4;
|
|
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1);
|
|
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc;
|
|
--error 1248
|
|
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b;
|
|
explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc;
|
|
(select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2;
|
|
select found_rows();
|
|
select sql_calc_found_rows a,b from t1 union all select a,b from t2 limit 2;
|
|
select found_rows();
|
|
|
|
#
|
|
# Test some error conditions with UNION
|
|
#
|
|
|
|
explain select a,b from t1 union all select a,b from t2;
|
|
|
|
--error 1054
|
|
explain select xx from t1 union select 1;
|
|
explain select a,b from t1 union select 1;
|
|
explain select 1 union select a,b from t1 union select 1;
|
|
explain select a,b from t1 union select 1 limit 0;
|
|
|
|
--error 1221
|
|
select a,b from t1 into outfile 'skr' union select a,b from t2;
|
|
|
|
--error 1221
|
|
select a,b from t1 order by a union select a,b from t2;
|
|
|
|
--error 1221
|
|
insert into t3 select a from t1 order by a union select a from t2;
|
|
|
|
--error 1222
|
|
create table t3 select a,b from t1 union select a from t2;
|
|
|
|
--error 1222
|
|
select a,b from t1 union select a from t2;
|
|
|
|
--error 1222
|
|
select * from t1 union select a from t2;
|
|
|
|
--error 1222
|
|
select a from t1 union select * from t2;
|
|
|
|
--error 1234
|
|
select * from t1 union select SQL_BUFFER_RESULT * from t2;
|
|
|
|
# Test CREATE, INSERT and REPLACE
|
|
create table t3 select a,b from t1 union all select a,b from t2;
|
|
insert into t3 select a,b from t1 union all select a,b from t2;
|
|
replace into t3 select a,b as c from t1 union all select a,b from t2;
|
|
|
|
drop table t1,t2,t3;
|
|
|
|
#
|
|
# Test some unions without tables
|
|
#
|
|
--error 1096
|
|
select * union select 1;
|
|
select 1 as a,(select a union select a);
|
|
--error 1054
|
|
(select 1) union (select 2) order by 0;
|
|
SELECT @a:=1 UNION SELECT @a:=@a+1;
|
|
--error 1054
|
|
(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a);
|
|
(SELECT 1,3) UNION (SELECT 2,1) ORDER BY (SELECT 2);
|
|
|
|
#
|
|
# Test bug reported by joc@presence-pc.com
|
|
#
|
|
|
|
CREATE TABLE t1 (
|
|
`pseudo` char(35) NOT NULL default '',
|
|
`pseudo1` char(35) NOT NULL default '',
|
|
`same` tinyint(1) unsigned NOT NULL default '1',
|
|
PRIMARY KEY (`pseudo1`),
|
|
KEY `pseudo` (`pseudo`)
|
|
) TYPE=MyISAM;
|
|
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 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,pseudo1 desc;
|
|
SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION SELECT pseudo FROM t1 WHERE pseudo1='joce';
|
|
SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION ALL SELECT pseudo FROM t1 WHERE pseudo1='joce';
|
|
SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION SELECT 1;
|
|
drop table t1;
|
|
|
|
create table t1 (a int);
|
|
create table t2 (a int);
|
|
insert into t1 values (1),(2),(3),(4),(5);
|
|
insert into t2 values (11),(12),(13),(14),(15);
|
|
(select * from t1 limit 2) union (select * from t2 limit 3) limit 4;
|
|
(select * from t1 limit 2) union (select * from t2 limit 3);
|
|
(select * from t1 limit 2) union (select * from t2 limit 20,3);
|
|
set SQL_SELECT_LIMIT=2;
|
|
(select * from t1 limit 1) union (select * from t2 limit 3);
|
|
set SQL_SELECT_LIMIT=DEFAULT;
|
|
drop table t1,t2;
|
|
|
|
#
|
|
# Test error with left join
|
|
#
|
|
|
|
CREATE TABLE t1 (
|
|
cid smallint(5) unsigned NOT NULL default '0',
|
|
cv varchar(250) NOT NULL default '',
|
|
PRIMARY KEY (cid),
|
|
UNIQUE KEY cv (cv)
|
|
) ;
|
|
INSERT INTO t1 VALUES (8,'dummy');
|
|
CREATE TABLE t2 (
|
|
cid bigint(20) unsigned NOT NULL auto_increment,
|
|
cap varchar(255) NOT NULL default '',
|
|
PRIMARY KEY (cid),
|
|
KEY cap (cap)
|
|
) ;
|
|
CREATE TABLE t3 (
|
|
gid bigint(20) unsigned NOT NULL auto_increment,
|
|
gn varchar(255) NOT NULL default '',
|
|
must tinyint(4) default NULL,
|
|
PRIMARY KEY (gid),
|
|
KEY gn (gn)
|
|
) ;
|
|
INSERT INTO t3 VALUES (1,'V1',NULL);
|
|
CREATE TABLE t4 (
|
|
uid bigint(20) unsigned NOT NULL default '0',
|
|
gid bigint(20) unsigned default NULL,
|
|
rid bigint(20) unsigned default NULL,
|
|
cid bigint(20) unsigned default NULL,
|
|
UNIQUE KEY m (uid,gid,rid,cid),
|
|
KEY uid (uid),
|
|
KEY rid (rid),
|
|
KEY cid (cid),
|
|
KEY container (gid,rid,cid)
|
|
) ;
|
|
INSERT INTO t4 VALUES (1,1,NULL,NULL);
|
|
CREATE TABLE t5 (
|
|
rid bigint(20) unsigned NOT NULL auto_increment,
|
|
rl varchar(255) NOT NULL default '',
|
|
PRIMARY KEY (rid),
|
|
KEY rl (rl)
|
|
) ;
|
|
CREATE TABLE t6 (
|
|
uid bigint(20) unsigned NOT NULL auto_increment,
|
|
un varchar(250) NOT NULL default '',
|
|
uc smallint(5) unsigned NOT NULL default '0',
|
|
PRIMARY KEY (uid),
|
|
UNIQUE KEY nc (un,uc),
|
|
KEY un (un)
|
|
) ;
|
|
INSERT INTO t6 VALUES (1,'test',8);
|
|
|
|
SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test";
|
|
SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t3.must IS NOT NULL AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test";
|
|
(SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t3.must IS NOT NULL AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test") UNION (SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t6.uc = t1.cid AND t1.cv = "dummy" AND t6.un = "test");
|
|
drop table t1,t2,t3,t4,t5,t6;
|
|
|
|
#
|
|
# Test insert ... SELECT with UNION
|
|
#
|
|
|
|
CREATE TABLE t1 (a int not null, b char (10) not null);
|
|
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c');
|
|
CREATE TABLE t2 (a int not null, b char (10) not null);
|
|
insert into t2 values (3,'c'),(4,'d'),(5,'f'),(6,'e');
|
|
create table t3 select a,b from t1 union select a,b from t2;
|
|
create table t4 (select a,b from t1) union (select a,b from t2) limit 2;
|
|
insert into t4 select a,b from t1 union select a,b from t2;
|
|
insert into t3 (select a,b from t1) union (select a,b from t2) limit 2;
|
|
select * from t3;
|
|
select * from t4;
|
|
drop table t1,t2,t3,t4;
|
|
|
|
#
|
|
# Test for another bug with UNION and LEFT JOIN
|
|
#
|
|
CREATE TABLE t1 ( id int(3) unsigned default '0') TYPE=MyISAM;
|
|
INSERT INTO t1 (id) VALUES("1");
|
|
CREATE TABLE t2 ( id int(3) unsigned default '0', id_master int(5) default '0', text1 varchar(5) default NULL, text2 varchar(5) default NULL) TYPE=MyISAM;
|
|
INSERT INTO t2 (id, id_master, text1, text2) VALUES("1", "1",
|
|
"foo1", "bar1");
|
|
INSERT INTO t2 (id, id_master, text1, text2) VALUES("2", "1",
|
|
"foo2", "bar2");
|
|
INSERT INTO t2 (id, id_master, text1, text2) VALUES("3", "1", NULL,
|
|
"bar3");
|
|
INSERT INTO t2 (id, id_master, text1, text2) VALUES("4", "1",
|
|
"foo4", "bar4");
|
|
SELECT 1 AS id_master, 1 AS id, NULL AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master;
|
|
SELECT 1 AS id_master, 1 AS id, 'ABCDE' AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master;
|
|
drop table if exists t1,t2;
|
|
|
|
#
|
|
# Test of bug when using the same table multiple times
|
|
#
|
|
create table t1 (a int not null primary key auto_increment, b int, key(b));
|
|
create table t2 (a int not null primary key auto_increment, b int);
|
|
insert into t1 (b) values (1),(2),(2),(3);
|
|
insert into t2 (b) values (10),(11),(12),(13);
|
|
|
|
explain (select * from t1 where a=1) union (select * from t2 where a=1);
|
|
(select * from t1 where a=5) union (select * from t2 where a=1);
|
|
(select * from t1 where a=5 and a=6) union (select * from t2 where a=1);
|
|
(select t1.a,t1.b from t1,t2 where t1.a=5) union (select * from t2 where a=1);
|
|
(select * from t1 where a=1) union (select t1.a,t2.a from t1,t2 where t1.a=t2.a);
|
|
explain (select * from t1 where a=1 and b=10) union (select t1.a,t2.a from t1,t2 where t1.a=t2.a);
|
|
explain (select * from t1 where a=1) union (select * from t1 where b=1);
|
|
drop table t1,t2;
|
|
create table t1 ( id int not null auto_increment, primary key (id) ,user_name text );
|
|
create table t2 ( id int not null auto_increment, primary key (id) ,group_name text );
|
|
create table t3 ( id int not null auto_increment, primary key (id) ,user_id int ,index user_idx (user_id) ,foreign key (user_id) references users(id) ,group_id int ,index group_idx (group_id) ,foreign key (group_id) references groups(id) );
|
|
insert into t1 (user_name) values ('Tester');
|
|
insert into t2 (group_name) values ('Group A');
|
|
insert into t2 (group_name) values ('Group B');
|
|
insert into t3 (user_id, group_id) values (1,1);
|
|
select 1 'is_in_group', a.user_name, c.group_name, b.id from t1 a, t3 b, t2 c where a.id = b.user_id and b.group_id = c.id UNION select 0 'is_in_group', a.user_name, c.group_name, null from t1 a, t2 c;
|
|
drop table t1, t2, t3;
|