1 drop table if exists t1,t2;
2 create table t1 (i int, j int, empty_string char(10), bool char(1), d date);
3 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");
4 select count(*) from t1 procedure analyse();
5 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
6 count(*) 4 4 1 1 0 0 4.0000 0.0000 ENUM('4') NOT NULL
7 select * from t1 procedure analyse();
8 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
9 test.t1.i 1 7 1 1 0 0 4.0000 2.2361 ENUM('1','3','5','7') NOT NULL
10 test.t1.j 2 8 1 1 0 0 5.0000 2.2361 ENUM('2','4','6','8') NOT NULL
11 test.t1.empty_string 0 0 4 0 0.0000 NULL CHAR(0) NOT NULL
12 test.t1.bool N Y 1 1 0 0 1.0000 NULL ENUM('N','Y') NOT NULL
13 test.t1.d 2002-03-03 2002-03-05 10 10 0 0 10.0000 NULL ENUM('2002-03-03','2002-03-04','2002-03-05') NOT NULL
14 select * from t1 procedure analyse(2);
15 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
16 test.t1.i 1 7 1 1 0 0 4.0000 2.2361 TINYINT(1) UNSIGNED NOT NULL
17 test.t1.j 2 8 1 1 0 0 5.0000 2.2361 TINYINT(1) UNSIGNED NOT NULL
18 test.t1.empty_string 0 0 4 0 0.0000 NULL CHAR(0) NOT NULL
19 test.t1.bool N Y 1 1 0 0 1.0000 NULL ENUM('N','Y') NOT NULL
20 test.t1.d 2002-03-03 2002-03-05 10 10 0 0 10.0000 NULL ENUM('2002-03-03','2002-03-04','2002-03-05') NOT NULL
21 create table t2 select * from t1 procedure analyse();
22 ERROR HY000: Incorrect usage of PROCEDURE and non-SELECT
24 EXPLAIN SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE();
25 ERROR HY000: Incorrect usage of PROCEDURE and subquery
26 create table t1 (v varchar(128));
27 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');
28 select * from t1 procedure analyse();
29 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
30 test.t1.v " \\ 1 19 0 0 3.7619 NULL ENUM('"','""','"c','\'\0\\"','\'','\'\'','\'b','a\0\0\0b','a\0','a""""b','a\'\'\'\'b','abc','abc\'def\\hij"klm\0opq','a\\\\\\\\b','b\'','c"','d\\','The\ZEnd','\\','\\d','\\\\') NOT NULL
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 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
37 test.t1.df 1.1 2.2 13 13 0 0 1.65000 0.55000 ENUM('1.1','2.2') NOT NULL
39 create table t1 (d double);
40 insert into t1 values (100000);
41 select * from t1 procedure analyse (1,1);
42 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
43 test.t1.d 100000 100000 6 6 0 0 100000 0 MEDIUMINT(6) UNSIGNED NOT NULL
45 create table t1 (product varchar(32), country_id int not null, year int,
47 insert into t1 values ( 'Computer', 2,2000, 1200),
48 ( 'TV', 1, 1999, 150),
49 ( 'Calculator', 1, 1999,50),
50 ( 'Computer', 1, 1999,1500),
51 ( 'Computer', 1, 2000,1500),
52 ( 'TV', 1, 2000, 150),
53 ( 'TV', 2, 2000, 100),
54 ( 'TV', 2, 2000, 100),
55 ( 'Calculator', 1, 2000,75),
56 ( 'Calculator', 2, 2000,75),
57 ( 'TV', 1, 1999, 100),
58 ( 'Computer', 1, 1999,1200),
59 ( 'Computer', 2, 2000,1500),
60 ( 'Calculator', 2, 2000,75),
61 ( 'Phone', 3, 2003,10)
63 create table t2 (country_id int primary key, country char(20) not null);
64 insert into t2 values (1, 'USA'),(2,'India'), (3,'Finland');
65 select product, sum(profit),avg(profit) from t1 group by product with rollup procedure analyse();
66 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
67 test.t1.product Computer TV 2 8 0 0 4.2500 NULL ENUM('Computer','Phone','TV') NOT NULL
68 sum(profit) 10 6900 11 11 0 0 1946.2500 2867.6719 ENUM('10','275','600','6900') NOT NULL
69 avg(profit) 10.0000 1380.0000 16 16 0 0 394.68750000 570.20033144 ENUM('10.0000','68.7500','120.0000','1380.0000') NOT NULL
71 create table t1 (f1 double(10,5), f2 char(10), f3 double(10,5));
72 insert into t1 values (5.999, "5.9999", 5.99999), (9.555, "9.5555", 9.55555);
73 select f1 from t1 procedure analyse(1, 1);
74 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
75 test.t1.f1 5.99900 9.55500 7 7 0 0 7.77700 1.77800 FLOAT(4,3) NOT NULL
76 select f2 from t1 procedure analyse(1, 1);
77 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
78 test.t1.f2 5.9999 9.5555 6 6 0 0 6.0000 NULL FLOAT(5,4) UNSIGNED NOT NULL
79 select f3 from t1 procedure analyse(1, 1);
80 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
81 test.t1.f3 5.99999 9.55555 7 7 0 0 7.77777 1.77778 FLOAT(6,5) NOT NULL
83 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);
84 INSERT INTO t1 VALUES ();
85 SELECT * FROM (SELECT * FROM t1) d PROCEDURE ANALYSE();
86 ERROR HY000: Incorrect usage of PROCEDURE and subquery
90 # Bug #48293: crash with procedure analyse, view with > 10 columns,
93 CREATE TABLE t1(a INT, b INT, c INT, d INT, e INT,
94 f INT, g INT, h INT, i INT, j INT,k INT);
95 INSERT INTO t1 VALUES (),();
96 CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
97 #should have a derived table
98 EXPLAIN SELECT * FROM v1;
99 id select_type table type possible_keys key key_len ref rows Extra
100 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
101 2 DERIVED t1 ALL NULL NULL NULL NULL 2
103 SELECT * FROM v1 PROCEDURE analyse();
104 ERROR HY000: Incorrect usage of PROCEDURE and view
106 SELECT * FROM t1 a, v1, t1 b PROCEDURE analyse();
107 ERROR HY000: Incorrect usage of PROCEDURE and view
109 SELECT * FROM (SELECT * FROM t1 having a > 1) x PROCEDURE analyse();
110 ERROR HY000: Incorrect usage of PROCEDURE and subquery
112 SELECT * FROM t1 a, (SELECT * FROM t1 having a > 1) x, t1 b PROCEDURE analyse();
113 ERROR HY000: Incorrect usage of PROCEDURE and subquery
115 SELECT 1 FROM t1 group by a having a > 1 order by 1 PROCEDURE analyse();
116 ERROR HY000: Can't use ORDER clause with this procedure
119 CREATE TABLE t1(a INT);
120 INSERT INTO t1 VALUES (1),(2);
122 CREATE TABLE t2 SELECT 1 FROM t1, t1 t3 GROUP BY t3.a PROCEDURE ANALYSE();
123 ERROR HY000: Incorrect usage of PROCEDURE and non-SELECT
127 # Bug#11765202: Dbug_violation_helper::~Dbug_violation_helper(): Assertion `!_entered' failed.
129 DROP TABLE IF EXISTS t1;
131 Note 1051 Unknown table 't1'
132 CREATE TABLE t1 (a VARCHAR(2) CHARSET UTF8 NOT NULL);
133 INSERT INTO t1 VALUES ('e'),('e'),('e-');
134 SELECT * FROM t1 PROCEDURE ANALYSE();
135 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
136 test.t1.a e e- 1 2 0 0 1.3333 NULL ENUM('e','e-') NOT NULL
139 # Bug#11756242 48137: PROCEDURE ANALYSE() LEAKS MEMORY WHEN RETURNING NULL
141 CREATE TABLE t1(f1 INT) ENGINE=MYISAM;
142 CREATE TABLE t2(f2 INT) ENGINE=INNODB;
143 INSERT INTO t2 VALUES (1);
144 SELECT DISTINCTROW f1 FROM t1 NATURAL RIGHT OUTER JOIN t2 PROCEDURE ANALYSE();
145 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
146 test.t1.f1 NULL NULL 0 0 0 1 0.0 0.0 CHAR(0)
147 SELECT * FROM t2 LIMIT 1 PROCEDURE ANALYSE();
148 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype
149 test.t2.f2 1 1 1 1 0 0 1.0000 0.0000 ENUM('1') NOT NULL