~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to mysql-test/t/subselect_sj2.test

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
--source include/have_innodb.inc
5
5
--disable_warnings
6
6
drop table if exists t0, t1, t2, t3;
 
7
drop view if exists v1;
7
8
--enable_warnings
8
9
 
9
 
 
10
10
create table t0 (a int);
11
11
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
12
12
 
146
146
 
147
147
#
148
148
# Bug #27348: Assertion abort for a query with two subqueries to be flattened  
149
 
#  
 
149
# Bug #35674: Range optimizer ignores conditions on inner tables in semi-join IN subqueries 
 
150
#
150
151
CREATE TABLE t1 (
151
152
  ID int(11) NOT NULL auto_increment,
152
153
  Name char(35) NOT NULL default '',
546
547
DROP PROCEDURE p2;
547
548
DROP PROCEDURE p3;
548
549
DROP PROCEDURE p4;
 
550
 
 
551
 
 
552
#
 
553
# BUG#35160 "Subquery optimization: table pullout is not reflected in EXPLAIN EXTENDED"
 
554
#
 
555
create table t0 (a int);
 
556
insert into t0 values (0),(1),(2),(3),(4);
 
557
 
 
558
create table t1 (a int, b int, key(a));
 
559
insert into t1 select a,a from t0;
 
560
 
 
561
create table t2 (a int, b int, primary key(a));
 
562
insert into t2 select * from t1;
 
563
 
 
564
# Table t2 should be pulled out because t2.a=t0.a equality
 
565
--echo Table t2, unlike table t1, should be displayed as pulled out
 
566
explain extended select * from t0
 
567
where t0.a in ( select t1.a from t1,t2 where t2.a=t0.a and
 
568
t1.b=t2.b);
 
569
 
 
570
drop table t0, t1, t2;
 
571
 
 
572
#
 
573
# BUG#35767: Processing of uncorrelated subquery with semi-join cause wrong result and crash
 
574
#
 
575
CREATE TABLE t1 (
 
576
  id int(11) NOT NULL,
 
577
  PRIMARY KEY (id));
 
578
 
 
579
CREATE TABLE t2 (
 
580
  id int(11) NOT NULL,
 
581
  fid int(11) NOT NULL,
 
582
  PRIMARY KEY (id));
 
583
 
 
584
insert into t1 values(1);
 
585
insert into t2 values(1,7503),(2,1);
 
586
 
 
587
--error 1054
 
588
explain select count(*) 
 
589
from t1 
 
590
where fid IN (select fid from t2 where (id between 7502 and 8420) order by fid );
 
591
 
 
592
drop table t1, t2;
 
593
 
 
594
#
 
595
# BUG#36137 "virtual longlong Item_in_subselect::val_int(): Assertion `0' failed."
 
596
#
 
597
create table t1 (a int, b int, key (a), key (b));
 
598
insert into t1 values (2,4),(2,4),(2,4);
 
599
select t1.a from t1 
 
600
where 
 
601
  t1.a in (select 1 from t1 where t1.a in (select 1 from t1) group by  t1.a);
 
602
drop table t1;
 
603
 
 
604
#
 
605
# BUG#36128: not in subquery causes crash in cleanup..
 
606
#
 
607
create table t1(a int,b int,key(a),key(b)); 
 
608
insert into t1 values (1,1),(2,2),(3,3);
 
609
select 1 from t1 
 
610
where t1.a not in (select 1 from t1 
 
611
                  where t1.a in (select 1 from t1) 
 
612
                  group by  t1.b);
 
613
drop table t1;
 
614
 
 
615
#
 
616
# BUG#33743 "nested subqueries, unique index, wrong result"
 
617
#
 
618
CREATE TABLE t1
 
619
 (EMPNUM   CHAR(3) NOT NULL,
 
620
  EMPNAME  CHAR(20),
 
621
  GRADE    DECIMAL(4),
 
622
  CITY     CHAR(15));
 
623
 
 
624
CREATE TABLE t2
 
625
 (PNUM     CHAR(3) NOT NULL,
 
626
  PNAME    CHAR(20),
 
627
  PTYPE    CHAR(6),
 
628
  BUDGET   DECIMAL(9),
 
629
  CITY     CHAR(15));
 
630
 
 
631
CREATE TABLE t3
 
632
 (EMPNUM   CHAR(3) NOT NULL,
 
633
  PNUM     CHAR(3) NOT NULL,
 
634
  HOURS    DECIMAL(5));
 
635
 
 
636
INSERT INTO t1 VALUES ('E1','Alice',12,'Deale');
 
637
INSERT INTO t1 VALUES ('E2','Betty',10,'Vienna');
 
638
INSERT INTO t1 VALUES ('E3','Carmen',13,'Vienna');
 
639
INSERT INTO t1 VALUES ('E4','Don',12,'Deale');
 
640
INSERT INTO t1 VALUES ('E5','Ed',13,'Akron');
 
641
 
 
642
INSERT INTO t2 VALUES ('P1','MXSS','Design',10000,'Deale');
 
643
INSERT INTO t2 VALUES ('P2','CALM','Code',30000,'Vienna');
 
644
INSERT INTO t2 VALUES ('P3','SDP','Test',30000,'Tampa');
 
645
INSERT INTO t2 VALUES ('P4','SDP','Design',20000,'Deale');
 
646
INSERT INTO t2 VALUES ('P5','IRM','Test',10000,'Vienna');
 
647
INSERT INTO t2 VALUES ('P6','PAYR','Design',50000,'Deale');
 
648
 
 
649
INSERT INTO t3 VALUES  ('E1','P1',40);
 
650
INSERT INTO t3 VALUES  ('E1','P2',20);
 
651
INSERT INTO t3 VALUES  ('E1','P3',80);
 
652
INSERT INTO t3 VALUES  ('E1','P4',20);
 
653
INSERT INTO t3 VALUES  ('E1','P5',12);
 
654
INSERT INTO t3 VALUES  ('E1','P6',12);
 
655
INSERT INTO t3 VALUES  ('E2','P1',40);
 
656
INSERT INTO t3 VALUES  ('E2','P2',80);
 
657
INSERT INTO t3 VALUES  ('E3','P2',20);
 
658
INSERT INTO t3 VALUES  ('E4','P2',20);
 
659
INSERT INTO t3 VALUES  ('E4','P4',40);
 
660
INSERT INTO t3 VALUES  ('E4','P5',80);
 
661
 
 
662
 
 
663
SELECT * FROM t1;
 
664
CREATE UNIQUE INDEX t1_IDX ON t1(EMPNUM);
 
665
--sorted_result
 
666
SELECT EMPNAME
 
667
FROM t1
 
668
WHERE EMPNUM IN
 
669
   (SELECT EMPNUM
 
670
    FROM t3
 
671
    WHERE PNUM IN
 
672
       (SELECT PNUM
 
673
        FROM t2
 
674
        WHERE PTYPE = 'Design'));
 
675
 
 
676
DROP INDEX t1_IDX ON t1;
 
677
CREATE INDEX t1_IDX ON t1(EMPNUM);
 
678
--sorted_result
 
679
SELECT EMPNAME
 
680
FROM t1
 
681
WHERE EMPNUM IN
 
682
   (SELECT EMPNUM
 
683
    FROM t3
 
684
    WHERE PNUM IN
 
685
       (SELECT PNUM
 
686
        FROM t2
 
687
        WHERE PTYPE = 'Design'));
 
688
 
 
689
DROP INDEX t1_IDX ON t1;
 
690
--sorted_result
 
691
SELECT EMPNAME
 
692
FROM t1
 
693
WHERE EMPNUM IN
 
694
   (SELECT EMPNUM
 
695
    FROM t3
 
696
    WHERE PNUM IN
 
697
       (SELECT PNUM
 
698
        FROM t2
 
699
        WHERE PTYPE = 'Design'));
 
700
 
 
701
DROP TABLE t1, t2, t3;
 
702
 
 
703
#
 
704
# BUG#33245 "Crash on VIEW referencing FROM table in an IN clause"
 
705
 
706
CREATE TABLE t1 (f1 INT NOT NULL);
 
707
CREATE VIEW v1 (a) AS SELECT f1 IN (SELECT f1 FROM t1) FROM t1;
 
708
SELECT * FROM v1;
 
709
drop view v1;
 
710
drop table t1;
 
711
 
 
712
 
 
713
#
 
714
# BUG#35550 "Semi-join subquery in ON clause and no WHERE crashes the server"
 
715
#
 
716
create table t0 (a int);
 
717
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 
718
 
 
719
create table t1(a int, b int);
 
720
insert into t1 values (0,0),(1,1),(2,2);
 
721
create table t2 as select * from t1;
 
722
 
 
723
create table t3 (pk int, a int, primary key(pk));
 
724
insert into t3 select a,a from t0;
 
725
 
 
726
explain 
 
727
select * from t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t3));
 
728
 
 
729
drop table t0, t1, t2, t3;
 
730
 
 
731
#
 
732
# BUG#34799: crash or/and memory overrun with dependant subquery and some joins
 
733
#
 
734
create table t1 (a int);
 
735
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 
736
 
 
737
create table t2 (a char(200), b char(200), c char(200), primary key (a,b,c)) engine=innodb;
 
738
insert into t2 select concat(a, repeat('X',198)),repeat('B',200),repeat('B',200) from t1;
 
739
insert into t2 select concat(a, repeat('Y',198)),repeat('B',200),repeat('B',200) from t1;
 
740
alter table t2 add filler1 int;
 
741
 
 
742
insert into t1 select A.a + 10*(B.a + 10*C.a) from t1 A, t1 B, t1 C;
 
743
 
 
744
set @save_join_buffer_size=@@join_buffer_size; 
 
745
--disable_warnings
 
746
set join_buffer_size=1;
 
747
--enable_warnings
 
748
 
 
749
select * from t2 where filler1 in ( select a from t1);
 
750
set join_buffer_size=default;
 
751
 
 
752
drop table t1, t2; 
 
753
#
 
754
# BUG#33509: Server crashes with number of recursive subqueries=61
 
755
#  (the query may or may not fail with an error so we're using it with SP 
 
756
#  
 
757
create table t1 (a int not null);
 
758
 
 
759
--disable_warnings
 
760
drop procedure if exists p1;
 
761
--enable_warnings
 
762
 
 
763
delimiter |;
 
764
 
 
765
CREATE PROCEDURE p1()
 
766
BEGIN
 
767
  DECLARE EXIT HANDLER FOR SQLEXCEPTION select a from t1;
 
768
  prepare s1 from '
 
769
  select a from t1 where a in ( 
 
770
  select a from t1 where a in ( 
 
771
  select a from t1 where a in ( 
 
772
  select a from t1 where a in ( 
 
773
  select a from t1 where a in ( 
 
774
  select a from t1 where a in ( 
 
775
  select a from t1 where a in ( 
 
776
  select a from t1 where a in ( 
 
777
  select a from t1 where a in ( 
 
778
  select a from t1 where a in ( 
 
779
  select a from t1 where a in ( 
 
780
  select a from t1 where a in ( 
 
781
  select a from t1 where a in ( 
 
782
  select a from t1 where a in ( 
 
783
  select a from t1 where a in ( 
 
784
  select a from t1 where a in ( 
 
785
  select a from t1 where a in ( 
 
786
  select a from t1 where a in ( 
 
787
  select a from t1 where a in ( 
 
788
  select a from t1 where a in ( 
 
789
  select a from t1 where a in ( 
 
790
  select a from t1 where a in ( 
 
791
  select a from t1 where a in ( 
 
792
  select a from t1 where a in ( 
 
793
  select a from t1 where a in ( 
 
794
  select a from t1 where a in ( 
 
795
  select a from t1 where a in ( 
 
796
  select a from t1 where a in ( 
 
797
  select a from t1 where a in ( 
 
798
  select a from t1 where a in ( 
 
799
  select a from t1 where a in ( 
 
800
  select a from t1 where a in ( 
 
801
  select a from t1 where a in ( 
 
802
  select a from t1 where a in ( 
 
803
  select a from t1 where a in ( 
 
804
  select a from t1 where a in ( 
 
805
  select a from t1 where a in ( 
 
806
  select a from t1 where a in ( 
 
807
  select a from t1 where a in ( 
 
808
  select a from t1 where a in ( 
 
809
  select a from t1 where a in ( 
 
810
  select a from t1 where a in ( 
 
811
  select a from t1 where a in ( 
 
812
  select a from t1 where a in ( 
 
813
  select a from t1 where a in ( 
 
814
  select a from t1 where a in ( 
 
815
  select a from t1 where a in ( 
 
816
  select a from t1 where a in ( 
 
817
  select a from t1 where a in ( 
 
818
  select a from t1 where a in ( 
 
819
  select a from t1 where a in ( 
 
820
  select a from t1 where a in ( 
 
821
  select a from t1 where a in ( 
 
822
  select a from t1 where a in ( 
 
823
  select a from t1 where a in ( 
 
824
  select a from t1 where a in ( 
 
825
  select a from t1 where a in ( 
 
826
  select a from t1 where a in ( 
 
827
  select a from t1 where a in ( 
 
828
  select a from t1 where a in ( 
 
829
  select a from t1 where a in ( 
 
830
  select a from t1 where a in ( select a from t1) 
 
831
  )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))';
 
832
  execute s1;
 
833
END;
 
834
|
 
835
delimiter ;|
 
836
 
 
837
call p1();
 
838
drop procedure p1;
 
839
drop table t1;