2
# Test of procedure analyse
6
drop table if exists t1,t2;
8
create table t1 (i int, j int, empty_string char(10), bool char(1), d date);
9
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");
10
select count(*) from t1 procedure analyse();
11
select * from t1 procedure analyse();
12
select * from t1 procedure analyse(2);
13
--error ER_WRONG_USAGE
14
create table t2 select * from t1 procedure analyse();
17
--error ER_WRONG_USAGE
18
EXPLAIN SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE();
21
# Bug#2813 - analyse does not quote string values in enums from string
24
create table t1 (v varchar(128));
25
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');
26
select * from t1 procedure analyse();
31
create table t1 (df decimal(5,1));
32
insert into t1 values(1.1);
33
insert into t1 values(2.2);
34
select * from t1 procedure analyse();
38
# Bug#10716 - Procedure Analyse results in wrong values for optimal field type
41
create table t1 (d double);
42
insert into t1 values (100000);
43
select * from t1 procedure analyse (1,1);
47
# Bug #14138 ROLLUP and PROCEDURE ANALYSE() hang server
49
create table t1 (product varchar(32), country_id int not null, year int,
51
insert into t1 values ( 'Computer', 2,2000, 1200),
52
( 'TV', 1, 1999, 150),
53
( 'Calculator', 1, 1999,50),
54
( 'Computer', 1, 1999,1500),
55
( 'Computer', 1, 2000,1500),
56
( 'TV', 1, 2000, 150),
57
( 'TV', 2, 2000, 100),
58
( 'TV', 2, 2000, 100),
59
( 'Calculator', 1, 2000,75),
60
( 'Calculator', 2, 2000,75),
61
( 'TV', 1, 1999, 100),
62
( 'Computer', 1, 1999,1200),
63
( 'Computer', 2, 2000,1500),
64
( 'Calculator', 2, 2000,75),
65
( 'Phone', 3, 2003,10)
67
create table t2 (country_id int primary key, country char(20) not null);
68
insert into t2 values (1, 'USA'),(2,'India'), (3,'Finland');
69
select product, sum(profit),avg(profit) from t1 group by product with rollup procedure analyse();
73
# Bug #20305 PROCEDURE ANALYSE() returns wrong M for FLOAT(M, D) and DOUBLE(M, D)
76
create table t1 (f1 double(10,5), f2 char(10), f3 double(10,5));
77
insert into t1 values (5.999, "5.9999", 5.99999), (9.555, "9.5555", 9.55555);
78
select f1 from t1 procedure analyse(1, 1);
79
select f2 from t1 procedure analyse(1, 1);
80
select f3 from t1 procedure analyse(1, 1);
84
# Bug#46184 Crash, SELECT ... FROM derived table procedure analyze
86
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);
87
INSERT INTO t1 VALUES ();
88
--error ER_WRONG_USAGE
89
SELECT * FROM (SELECT * FROM t1) d PROCEDURE ANALYSE();
92
--echo End of 4.1 tests
95
--echo # Bug #48293: crash with procedure analyse, view with > 10 columns,
96
--echo # having clause...
99
CREATE TABLE t1(a INT, b INT, c INT, d INT, e INT,
100
f INT, g INT, h INT, i INT, j INT,k INT);
101
INSERT INTO t1 VALUES (),();
103
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
104
--echo #should have a derived table
105
EXPLAIN SELECT * FROM v1;
106
--echo #should not crash
107
--error ER_WRONG_USAGE
108
SELECT * FROM v1 PROCEDURE analyse();
109
--echo #should not crash
110
--error ER_WRONG_USAGE
111
SELECT * FROM t1 a, v1, t1 b PROCEDURE analyse();
112
--echo #should not crash
113
--error ER_WRONG_USAGE
114
SELECT * FROM (SELECT * FROM t1 having a > 1) x PROCEDURE analyse();
115
--echo #should not crash
116
--error ER_WRONG_USAGE
117
SELECT * FROM t1 a, (SELECT * FROM t1 having a > 1) x, t1 b PROCEDURE analyse();
118
--echo #should not crash
119
--error ER_ORDER_WITH_PROC
120
SELECT 1 FROM t1 group by a having a > 1 order by 1 PROCEDURE analyse();
125
CREATE TABLE t1(a INT);
126
INSERT INTO t1 VALUES (1),(2);
128
--echo # should not crash
129
--error ER_WRONG_USAGE
130
CREATE TABLE t2 SELECT 1 FROM t1, t1 t3 GROUP BY t3.a PROCEDURE ANALYSE();
135
--echo End of 5.0 tests