mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / analyse.test
blobc77967a0cc931c3fa5ed029c0b282ecd82b16b42
2 # Test of procedure analyse
4 -- source include/have_innodb.inc
6 --disable_warnings
7 drop table if exists t1,t2;
8 --enable_warnings
9 create table t1 (i int, j int, empty_string char(10), bool char(1), d date);
10 insert into t1 values (1,2,"","Y","2002-03-03"), (3,4,"","N","2002-03-04"), (5,6,"","Y","2002-03-04"), (7,8,"","N","2002-03-05");
11 select count(*) from t1 procedure analyse();
12 select * from t1 procedure analyse();
13 select * from t1 procedure analyse(2);
14 --error ER_WRONG_USAGE
15 create table t2 select * from t1 procedure analyse();
16 drop table t1;
18 --error ER_WRONG_USAGE
19 EXPLAIN SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE();
22 # Bug#2813 - analyse does not quote string values in enums from string
25 create table t1 (v varchar(128));
26 insert into t1 values ('abc'),('abc\'def\\hij\"klm\0opq'),('\''),('\"'),('\\'),('a\0'),('b\''),('c\"'),('d\\'),('\'b'),('\"c'),('\\d'),('a\0\0\0b'),('a\'\'\'\'b'),('a\"\"\"\"b'),('a\\\\\\\\b'),('\'\0\\\"'),('\'\''),('\"\"'),('\\\\'),('The\ZEnd');
27 select * from t1 procedure analyse();
28 drop table t1;
30 #decimal-related test
32 create table t1 (df decimal(5,1));
33 insert into t1 values(1.1);
34 insert into t1 values(2.2);
35 select * from t1 procedure analyse();
36 drop table t1;
39 # Bug#10716 - Procedure Analyse results in wrong values for optimal field type
42 create table t1 (d double);
43 insert into t1 values (100000);
44 select * from t1 procedure analyse (1,1);
45 drop table t1;
48 # Bug #14138 ROLLUP and PROCEDURE ANALYSE() hang server
50 create table t1 (product varchar(32), country_id int not null, year int,
51                  profit int);
52 insert into t1  values ( 'Computer', 2,2000, 1200),
53     ( 'TV', 1, 1999, 150),
54     ( 'Calculator', 1, 1999,50),
55     ( 'Computer', 1, 1999,1500),
56     ( 'Computer', 1, 2000,1500),
57     ( 'TV', 1, 2000, 150),
58     ( 'TV', 2, 2000, 100),
59     ( 'TV', 2, 2000, 100),
60     ( 'Calculator', 1, 2000,75),
61     ( 'Calculator', 2, 2000,75),
62     ( 'TV', 1, 1999, 100),
63     ( 'Computer', 1, 1999,1200),
64     ( 'Computer', 2, 2000,1500),
65     ( 'Calculator', 2, 2000,75),
66     ( 'Phone', 3, 2003,10)
67     ;
68 create table t2 (country_id int primary key, country char(20) not null); 
69 insert into t2 values (1, 'USA'),(2,'India'), (3,'Finland');
70 select product, sum(profit),avg(profit) from t1 group by product with rollup procedure analyse();
71 drop table t1,t2;
74 # Bug #20305 PROCEDURE ANALYSE() returns wrong M for FLOAT(M, D) and DOUBLE(M, D)
77 create table t1 (f1 double(10,5), f2 char(10), f3 double(10,5));
78 insert into t1 values (5.999, "5.9999", 5.99999), (9.555, "9.5555", 9.55555);
79 select f1 from t1 procedure analyse(1, 1);
80 select f2 from t1 procedure analyse(1, 1);
81 select f3 from t1 procedure analyse(1, 1);
82 drop table t1;
85 # Bug#46184 Crash, SELECT ... FROM derived table procedure analyze
87 CREATE TABLE t1(a INT,b INT,c INT,d INT,e INT,f INT,g INT,h INT,i INT,j INT,k INT);
88 INSERT INTO t1 VALUES ();
89 --error ER_WRONG_USAGE
90 SELECT * FROM (SELECT * FROM t1) d PROCEDURE ANALYSE();
91 DROP TABLE t1;
93 --echo End of 4.1 tests
95 --echo #
96 --echo # Bug #48293: crash with procedure analyse, view with > 10 columns, 
97 --echo #  having clause...
98 --echo #
100 CREATE TABLE t1(a INT, b INT, c INT, d INT, e INT,
101                 f INT, g INT, h INT, i INT, j INT,k INT);
102 INSERT INTO t1 VALUES (),();
104 CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
105 --echo #should have a derived table
106 EXPLAIN SELECT * FROM v1;
107 --echo #should not crash
108 --error ER_WRONG_USAGE
109 SELECT * FROM v1 PROCEDURE analyse();
110 --echo #should not crash
111 --error ER_WRONG_USAGE
112 SELECT * FROM t1 a, v1, t1 b PROCEDURE analyse();
113 --echo #should not crash
114 --error ER_WRONG_USAGE
115 SELECT * FROM (SELECT * FROM t1 having a > 1) x PROCEDURE analyse();
116 --echo #should not crash
117 --error ER_WRONG_USAGE
118 SELECT * FROM t1 a, (SELECT * FROM t1 having a > 1) x, t1 b PROCEDURE analyse();
119 --echo #should not crash
120 --error ER_ORDER_WITH_PROC
121 SELECT 1 FROM t1 group by a having a > 1 order by 1 PROCEDURE analyse();
123 DROP VIEW v1;
124 DROP TABLE t1;
126 CREATE TABLE t1(a INT);
127 INSERT INTO t1 VALUES (1),(2);
129 --echo # should not crash
130 --error ER_WRONG_USAGE
131 CREATE TABLE t2 SELECT 1 FROM t1, t1 t3 GROUP BY t3.a PROCEDURE ANALYSE();
133 DROP TABLE t1;
136 --echo End of 5.0 tests
138 --echo #
139 --echo # Bug#11765202: Dbug_violation_helper::~Dbug_violation_helper(): Assertion `!_entered' failed.
140 --echo #
142 DROP TABLE IF EXISTS t1;
143 CREATE TABLE t1 (a VARCHAR(2) CHARSET UTF8 NOT NULL);
144 INSERT INTO t1 VALUES ('e'),('e'),('e-');
145 SELECT * FROM t1 PROCEDURE ANALYSE();
146 DROP TABLE t1;
148 --echo #
149 --echo # Bug#11756242  48137: PROCEDURE ANALYSE() LEAKS MEMORY WHEN RETURNING NULL
150 --echo #
152 CREATE TABLE t1(f1 INT) ENGINE=MYISAM;
153 CREATE TABLE t2(f2 INT) ENGINE=INNODB;
154 INSERT INTO t2 VALUES (1);
155 SELECT DISTINCTROW f1 FROM t1 NATURAL RIGHT OUTER JOIN t2 PROCEDURE ANALYSE();
156 SELECT * FROM t2 LIMIT 1 PROCEDURE ANALYSE();
157 DROP TABLE t1, t2;
159 --echo End of 5.1 tests