subselect3.result

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· RESULT 代码 · 共 763 行 · 第 1/2 页

RESULT
763
字号
drop table if exists t0, t1, t2, t3, t4;create table t1 (oref int, grp int, ie int) ;insert into t1 (oref, grp, ie) values(1, 1, 1),(1, 1, 1),(1, 2, NULL),(2, 1, 3),(3, 1, 4),(3, 2, NULL);create table t2 (oref int, a int);insert into t2 values (1, 1),(2, 2),(3, 3),(4, NULL),(2, NULL);select a, oref, a in (select max(ie) from t1 where oref=t2.oref group by grp) Z from t2;a	oref	Z1	1	12	2	03	3	NULLNULL	4	0NULL	2	NULLexplain extendedselect a, oref, a in (select max(ie) from t1 where oref=t2.oref group by grp) Z from t2;id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	5	2	DEPENDENT SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	6	Using where; Using temporary; Using filesortWarnings:Note	1276	Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) AS `max(ie)` from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `Z` from `test`.`t2`explain extendedselect a, oref from t2 where a in (select max(ie) from t1 where oref=t2.oref group by grp);id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where2	DEPENDENT SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	6	Using where; Using temporary; Using filesortWarnings:Note	1276	Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select max(`test`.`t1`.`ie`) AS `max(ie)` from `test`.`t1` where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) group by `test`.`t1`.`grp` having (<cache>(`test`.`t2`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))select a, oref, a in (select max(ie) from t1 where oref=t2.oref group by grp unionselect max(ie) from t1 where oref=t2.oref group by grp) Z from t2;a	oref	Z1	1	12	2	03	3	NULLNULL	4	0NULL	2	NULLcreate table t3 (a int);insert into t3 values (NULL), (NULL);flush status;select a in (select max(ie) from t1 where oref=4 group by grp) from t3;a in (select max(ie) from t1 where oref=4 group by grp)00show status like 'Handler_read_rnd_next';Variable_name	ValueHandler_read_rnd_next	11select ' ^ This must show 11' Z;Z ^ This must show 11explain extended select a in (select max(ie) from t1 where oref=4 group by grp) from t3;id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	2	2	DEPENDENT SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	6	Using where; Using temporary; Using filesortWarnings:Note	1003	select <in_optimizer>(`test`.`t3`.`a`,<exists>(select max(`test`.`t1`.`ie`) AS `max(ie)` from `test`.`t1` where (`test`.`t1`.`oref` = 4) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t3`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `a in (select max(ie) from t1 where oref=4 group by grp)` from `test`.`t3`drop table t1, t2, t3;create table t1 (a int, oref int, key(a));insert into t1 values (1, 1),(1, NULL),(2, 3),(2, NULL),(3, NULL);create table t2 (a int, oref int);insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4);select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;oref	a	Z1	1	12	2	03	NULL	NULL4	NULL	0explain extended select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	4	2	DEPENDENT SUBQUERY	t1	index_subquery	a	a	5	func	2	Using where; Full scan on NULL keyWarnings:Note	1276	Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1Note	1003	select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where (`test`.`t1`.`oref` = `test`.`t2`.`oref`) having trigcond(<is_not_null_test>(`test`.`t1`.`a`))))) AS `Z` from `test`.`t2`flush status;select oref, a from t2 where a in (select a from t1 where oref=t2.oref);oref	a1	1show status like '%Handler_read_rnd_next';Variable_name	ValueHandler_read_rnd_next	5delete from t2;insert into t2 values (NULL, 0),(NULL, 0), (NULL, 0), (NULL, 0);flush status;select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;oref	a	Z0	NULL	00	NULL	00	NULL	00	NULL	0show status like '%Handler_read%';Variable_name	ValueHandler_read_first	0Handler_read_key	0Handler_read_next	0Handler_read_prev	0Handler_read_rnd	0Handler_read_rnd_next	29select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z;ZNo key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.drop table t1, t2;create table t1 (a int, b int, primary key (a));insert into t1 values (1,1), (3,1),(100,1);create table t2 (a int, b int);insert into t2 values (1,1),(2,1),(NULL,1),(NULL,0);select a,b, a in (select a from t1 where t1.b = t2.b) Z from t2 ;a	b	Z1	1	12	1	0NULL	1	NULLNULL	0	0drop table t1, t2;create table t1 (a int, b int, key(a));insert into t1 values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);create table t2 like t1;insert into t2 select * from t1;update t2 set b=1;create table t3 (a int, oref int);insert into t3 values (1, 1), (NULL,1), (NULL,0);select a, oref, t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z from t3;a	oref	Z1	1	1NULL	1	NULLNULL	0	0explain extendedselect a, oref, t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z from t3;id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	2	DEPENDENT SUBQUERY	t1	ref_or_null	a	a	5	func	4	Using where; Full scan on NULL key2	DEPENDENT SUBQUERY	t2	ref	a	a	5	test.t1.b	1	Using whereWarnings:Note	1276	Field or reference 'test.t3.oref' of SELECT #2 was resolved in SELECT #1Note	1003	select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<in_optimizer>(`test`.`t3`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`a` = `test`.`t1`.`b`) and (`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond(((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`)))) having trigcond(<is_not_null_test>(`test`.`t1`.`a`)))) AS `Z` from `test`.`t3`drop table t1, t2, t3;create table t1 (a int NOT NULL, b int NOT NULL, key(a));insert into t1 values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);create table t2 like t1;insert into t2 select * from t1;update t2 set b=1;create table t3 (a int, oref int);insert into t3 values (1, 1), (NULL,1), (NULL,0);select a, oref, t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z from t3;a	oref	Z1	1	1NULL	1	NULLNULL	0	0This must show a trig_cond:explain extendedselect a, oref, t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z from t3;id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	2	DEPENDENT SUBQUERY	t1	ref	a	a	4	func	2	Using where; Full scan on NULL key2	DEPENDENT SUBQUERY	t2	ref	a	a	4	test.t1.b	1	Using whereWarnings:Note	1276	Field or reference 'test.t3.oref' of SELECT #2 was resolved in SELECT #1Note	1003	select `test`.`t3`.`a` AS `a`,`test`.`t3`.`oref` AS `oref`,<in_optimizer>(`test`.`t3`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`a` = `test`.`t1`.`b`) and (`test`.`t2`.`b` = `test`.`t3`.`oref`) and trigcond((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`))))) AS `Z` from `test`.`t3`drop table t1,t2,t3;create table t1 (oref int, grp int);insert into t1 (oref, grp) values(1, 1),(1, 1);create table t2 (oref int, a int);insert into t2 values (1, NULL),(2, NULL);select a, oref, a in (select count(*) from t1 group by grp having grp=t2.oref) Z from t2;a	oref	ZNULL	1	NULLNULL	2	0This must show a trig_cond:explain extendedselect a, oref, a in (select count(*) from t1 group by grp having grp=t2.oref) Z from t2;id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	2	DEPENDENT SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	2	Using temporary; Using filesortWarnings:Note	1276	Field or reference 't2.oref' of SELECT #2 was resolved in SELECT #1Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>(`test`.`t2`.`a`,<exists>(select count(0) AS `count(*)` from `test`.`t1` group by `test`.`t1`.`grp` having ((`test`.`t1`.`grp` = `test`.`t2`.`oref`) and trigcond((<cache>(`test`.`t2`.`a`) = <ref_null_helper>(count(0))))))) AS `Z` from `test`.`t2`drop table t1, t2;create table t1 (a int, b int, primary key (a));insert into t1 values (1,1), (3,1),(100,1);create table t2 (a int, b int);insert into t2 values (1,1),(2,1),(NULL,1),(NULL,0);select a,b, a in (select a from t1 where t1.b = t2.b union select a fromt1 where t1.b = t2.b) Z from t2 ;a	b	Z1	1	12	1	0NULL	1	NULLNULL	0	0select a,b, a in (select a from t1 where t1.b = t2.b) Z from t2 ;a	b	Z1	1	12	1	0NULL	1	NULLNULL	0	0drop table t1, t2;create table t3 (a int);insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);create table t2 (a int, b int, oref int);insert into t2 values (NULL,1, 100), (NULL,2, 100);create table t1 (a int, b int, c int, key(a,b));insert into t1 select 2*A, 2*A, 100 from t3;explain extended select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2;id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	2	DEPENDENT SUBQUERY	t1	index_subquery	a	a	5	func	2	Using where; Full scan on NULL keyWarnings:Note	1276	Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2`select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2;a	b	oref	ZNULL	1	100	0NULL	2	100	NULLcreate table t4 (x int);insert into t4 select A.a + 10*B.a from t1 A, t1 B;explain extended select a,b, oref, (a,b) in (select a,b from t1,t4 where c=t2.oref) Z from t2;id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	2	DEPENDENT SUBQUERY	t1	ref_or_null	a	a	5	func	2	Using where; Full scan on NULL key2	DEPENDENT SUBQUERY	t4	ALL	NULL	NULL	NULL	NULL	100	Using whereWarnings:Note	1276	Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`))))) AS `Z` from `test`.`t2`select a,b, oref, (a,b) in (select a,b from t1,t4 where c=t2.oref) Z from t2;a	b	oref	ZNULL	1	100	0NULL	2	100	NULLdrop table t1,t2,t3,t4;create table t1 (oref char(4), grp int, ie1 int, ie2 int);insert into t1 (oref, grp, ie1, ie2) values('aa', 10, 2, 1),('aa', 10, 1, 1),('aa', 20, 2, 1),('bb', 10, 3, 1),('cc', 10, 4, 2),('cc', 20, 3, 2),('ee', 10, 2, 1),('ee', 10, 1, 2),('ff', 20, 2, 2),('ff', 20, 1, 2);create table t2 (oref char(4), a int, b int);insert into t2 values ('ee', NULL, 1),('bb', 2, 1),('ff', 2, 2),('cc', 3, NULL),('bb', NULL, NULL),('aa', 1, 1),('dd', 1, NULL);alter table t1 add index idx(ie1,ie2);select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2 where a=3 and b is null ;oref	a	b	Zcc	3	NULL	NULLinsert into t2 values ('new1', 10,10);insert into t1 values ('new1', 1234, 10, NULL);select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2 where a=10 and b=10;oref	a	b	Znew1	10	10	NULLexplain extendedselect oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2 where a=10 and b=10;id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	8	Using where2	DEPENDENT SUBQUERY	t1	index_subquery	idx	idx	5	func	4	Using where; Full scan on NULL keyWarnings:Note	1276	Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1Note	1003	select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`)))))) AS `Z` from `test`.`t2` where ((`test`.`t2`.`b` = 10) and (`test`.`t2`.`a` = 10))drop table t1, t2;create table t1 (oref char(4), grp int, ie int);insert into t1 (oref, grp, ie) values('aa', 10, 2),('aa', 10, 1),('aa', 20, NULL),('bb', 10, 3),('cc', 10, 4),('cc', 20, NULL),('ee', 10, NULL),('ee', 10, NULL),('ff', 20, 2),('ff', 20, 1);create table t2 (oref char(4), a int);insert into t2 values ('ee', NULL),('bb', 2),('ff', 2),('cc', 3),('aa', 1),('dd', NULL),('bb', NULL);select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;oref	a	Zee	NULL	NULLbb	2	0ff	2	1cc	3	NULLaa	1	1dd	NULL	0bb	NULL	NULLselect oref, a from t2 where a in (select ie from t1 where oref=t2.oref);oref	aff	2aa	1select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);oref	abb	2dd	NULLselect oref, a, a in (select min(ie) from t1 where oref=t2.oref group by grp) Z from t2;oref	a	Zee	NULL	NULLbb	2	0ff	2	0cc	3	NULLaa	1	1dd	NULL	0bb	NULL	NULLselect oref, a from t2 where a in (select min(ie) from t1 where oref=t2.oref group by grp);oref	aaa	1select oref, a from t2 where a not in (select min(ie) from t1 where oref=t2.oref group by grp);oref	abb	2ff	2dd	NULLupdate t1 set ie=3 where oref='ff' and ie=1;select oref, a, a in (select min(ie) from t1 where oref=t2.oref group bygrp) Z from t2;oref	a	Zee	NULL	NULLbb	2	0ff	2	1cc	3	NULLaa	1	1dd	NULL	0bb	NULL	NULLselect oref, a from t2 where a in (select min(ie) from t1 whereoref=t2.oref group by grp);oref	aff	2aa	1select oref, a from t2 where a not in (select min(ie) from t1 whereoref=t2.oref group by grp);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?