2000-12-28 02:56:38 +01:00
#
# Test of procedure analyse
#
2011-04-14 10:11:57 +02:00
-- source include/have_innodb.inc
2000-12-28 02:56:38 +01:00
2003-01-06 00:48:59 +01:00
--disable_warnings
2001-08-02 05:29:50 +02:00
drop table if exists t1,t2;
2003-01-06 00:48:59 +01:00
--enable_warnings
2003-03-12 15:43:01 +01:00
create table t1 (i int, j int, empty_string char(10), bool char(1), d date);
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");
2003-01-10 16:36:59 +01:00
select count(*) from t1 procedure analyse();
2000-12-28 02:56:38 +01:00
select * from t1 procedure analyse();
2003-03-12 15:43:01 +01:00
select * from t1 procedure analyse(2);
2016-05-06 09:42:48 +02:00
--error ER_PARSE_ERROR
2000-12-28 02:56:38 +01:00
create table t2 select * from t1 procedure analyse();
2009-10-30 10:40:44 +01:00
drop table t1;
2002-12-12 15:09:06 +01:00
2009-08-27 12:22:19 +02:00
--error ER_WRONG_USAGE
2003-01-06 00:48:59 +01:00
EXPLAIN SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE();
2004-05-04 14:02:38 +02:00
2005-01-12 21:55:10 +01:00
#
# Bug#2813 - analyse does not quote string values in enums from string
#
2024-05-28 07:08:51 +02:00
create table t1 (v varchar(128)) charset=latin1;
2005-01-11 18:40:33 +01:00
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');
2024-05-23 03:54:14 +02:00
#Enable after fix MDEV-31538
--disable_cursor_protocol
2005-01-11 18:40:33 +01:00
select * from t1 procedure analyse();
2024-05-23 03:54:14 +02:00
--enable_cursor_protocol
2005-01-11 18:40:33 +01:00
drop table t1;
2005-02-21 16:20:05 +01:00
2005-09-11 21:10:04 +02:00
#decimal-related test
create table t1 (df decimal(5,1));
insert into t1 values(1.1);
insert into t1 values(2.2);
select * from t1 procedure analyse();
drop table t1;
2005-09-09 19:02:13 +02:00
#
# Bug#10716 - Procedure Analyse results in wrong values for optimal field type
#
create table t1 (d double);
insert into t1 values (100000);
select * from t1 procedure analyse (1,1);
drop table t1;
2005-10-28 13:24:46 +02:00
#
# Bug #14138 ROLLUP and PROCEDURE ANALYSE() hang server
#
create table t1 (product varchar(32), country_id int not null, year int,
profit int);
insert into t1 values ( 'Computer', 2,2000, 1200),
( 'TV', 1, 1999, 150),
( 'Calculator', 1, 1999,50),
( 'Computer', 1, 1999,1500),
( 'Computer', 1, 2000,1500),
( 'TV', 1, 2000, 150),
( 'TV', 2, 2000, 100),
( 'TV', 2, 2000, 100),
( 'Calculator', 1, 2000,75),
( 'Calculator', 2, 2000,75),
( 'TV', 1, 1999, 100),
( 'Computer', 1, 1999,1200),
( 'Computer', 2, 2000,1500),
( 'Calculator', 2, 2000,75),
( 'Phone', 3, 2003,10)
;
create table t2 (country_id int primary key, country char(20) not null);
insert into t2 values (1, 'USA'),(2,'India'), (3,'Finland');
select product, sum(profit),avg(profit) from t1 group by product with rollup procedure analyse();
drop table t1,t2;
2005-07-28 16:09:54 +02:00
2006-09-28 20:30:20 +02:00
#
# Bug #20305 PROCEDURE ANALYSE() returns wrong M for FLOAT(M, D) and DOUBLE(M, D)
#
create table t1 (f1 double(10,5), f2 char(10), f3 double(10,5));
insert into t1 values (5.999, "5.9999", 5.99999), (9.555, "9.5555", 9.55555);
select f1 from t1 procedure analyse(1, 1);
select f2 from t1 procedure analyse(1, 1);
select f3 from t1 procedure analyse(1, 1);
drop table t1;
2009-08-27 12:22:19 +02:00
#
# Bug#46184 Crash, SELECT ... FROM derived table procedure analyze
#
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);
INSERT INTO t1 VALUES ();
--error ER_WRONG_USAGE
SELECT * FROM (SELECT * FROM t1) d PROCEDURE ANALYSE();
DROP TABLE t1;
2006-09-28 20:30:20 +02:00
--echo End of 4.1 tests
2009-10-30 10:40:44 +01:00
--echo #
--echo # Bug #48293: crash with procedure analyse, view with > 10 columns,
--echo # having clause...
--echo #
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);
INSERT INTO t1 VALUES (),();
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
--echo #should have a derived table
EXPLAIN SELECT * FROM v1;
--echo #should not crash
--error ER_WRONG_USAGE
SELECT * FROM v1 PROCEDURE analyse();
--echo #should not crash
--error ER_WRONG_USAGE
SELECT * FROM t1 a, v1, t1 b PROCEDURE analyse();
--echo #should not crash
--error ER_WRONG_USAGE
SELECT * FROM (SELECT * FROM t1 having a > 1) x PROCEDURE analyse();
--echo #should not crash
--error ER_WRONG_USAGE
SELECT * FROM t1 a, (SELECT * FROM t1 having a > 1) x, t1 b PROCEDURE analyse();
--echo #should not crash
--error ER_ORDER_WITH_PROC
SELECT 1 FROM t1 group by a having a > 1 order by 1 PROCEDURE analyse();
DROP VIEW v1;
DROP TABLE t1;
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (1),(2);
--echo # should not crash
2016-05-06 09:42:48 +02:00
--error ER_PARSE_ERROR
2009-10-30 10:40:44 +01:00
CREATE TABLE t2 SELECT 1 FROM t1, t1 t3 GROUP BY t3.a PROCEDURE ANALYSE();
DROP TABLE t1;
--echo End of 5.0 tests
2011-03-14 19:03:22 +01:00
--echo #
--echo # Bug#11765202: Dbug_violation_helper::~Dbug_violation_helper(): Assertion `!_entered' failed.
--echo #
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(2) CHARSET UTF8 NOT NULL);
INSERT INTO t1 VALUES ('e'),('e'),('e-');
SELECT * FROM t1 PROCEDURE ANALYSE();
DROP TABLE t1;
2011-04-14 10:11:57 +02:00
--echo #
--echo # Bug#11756242 48137: PROCEDURE ANALYSE() LEAKS MEMORY WHEN RETURNING NULL
--echo #
CREATE TABLE t1(f1 INT) ENGINE=MYISAM;
CREATE TABLE t2(f2 INT) ENGINE=INNODB;
INSERT INTO t2 VALUES (1);
SELECT DISTINCTROW f1 FROM t1 NATURAL RIGHT OUTER JOIN t2 PROCEDURE ANALYSE();
SELECT * FROM t2 LIMIT 1 PROCEDURE ANALYSE();
DROP TABLE t1, t2;
2011-03-14 19:03:22 +01:00
--echo End of 5.1 tests
2016-05-06 09:42:48 +02:00
--echo #
--echo # Start of 10.2 tests
--echo #
2018-05-22 19:08:39 +02:00
--error ER_PARSE_ERROR
2016-05-06 09:42:48 +02:00
(SELECT 1 FROM DUAL PROCEDURE ANALYSE());
2018-05-22 19:08:39 +02:00
--error ER_PARSE_ERROR
2016-05-06 09:42:48 +02:00
((SELECT 1 FROM DUAL PROCEDURE ANALYSE()));
2018-05-22 19:08:39 +02:00
(SELECT 1 FROM DUAL) PROCEDURE ANALYSE();
((SELECT 1 FROM DUAL)) PROCEDURE ANALYSE();
2016-05-06 09:42:48 +02:00
2018-05-22 19:08:39 +02:00
create table t1 (a int);
--error ER_CANT_USE_OPTION_HERE
2016-05-06 09:42:48 +02:00
SELECT * FROM t1 UNION SELECT * FROM t1 PROCEDURE analyse();
2018-05-22 19:08:39 +02:00
drop table t1;
2016-05-06 09:42:48 +02:00
--echo #
--echo # MDEV-10030 sql_yacc.yy: Split table_expression and remove PROCEDURE from create_select, select_paren_derived, select_derived2, query_specification
--echo #
--error ER_PARSE_ERROR
SELECT * FROM (SELECT * FROM t1 PROCEDURE ANALYSE());
--ERROR ER_PARSE_ERROR
SELECT * FROM t1 NATURAL JOIN (SELECT * FROM t2 PROCEDURE ANALYSE());
--error ER_PARSE_ERROR
SELECT (SELECT 1 FROM t1 PROCEDURE ANALYSE()) FROM t2;
--error ER_PARSE_ERROR
SELECT ((SELECT 1 FROM t1 PROCEDURE ANALYSE())) FROM t2;
2018-05-28 14:57:59 +02:00
--echo #
--echo # Start of 10.4 tests
--echo #
--echo #
--echo # MDEV-16309 Split ::create_tmp_field() into virtual methods in Item
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2),(3);
--vertical_results
DELIMITER $$;
BEGIN NOT ATOMIC
DECLARE rec ROW(Field_name TEXT,
Min_value TEXT,
Max_value TEXT,
Min_length TEXT,
Max_length TEXT,
Empties_or_zeros TEXT,
Nulls TEXT,
Avg_value_or_avg_length TEXT,
Std TEXT,
Optimal_fieldtype TEXT);
DECLARE c CURSOR FOR SELECT * FROM t1 PROCEDURE analyse();
OPEN c;
FETCH c INTO rec;
CLOSE c;
SELECT rec.field_name,
rec.Min_value, rec.Max_value,
rec.Min_length, rec. Max_length,
rec.Empties_or_zeros, rec.Nulls,
rec.Avg_value_or_avg_length, rec.Std,
rec.Optimal_fieldtype;
END;
$$
DELIMITER ;$$
--horizontal_results
DROP TABLE t1;
--echo #
--echo # End of 10.4 tests
--echo #
2024-07-17 06:39:43 +02:00
--echo #
--echo # Start of 10.5 tests
--echo #
--echo #
--echo # MDEV-28345 ASAN: use-after-poison or unknown-crash in my_strtod_int from charset_info_st::strntod or test_if_number
--echo #
SET sql_mode='';
CREATE TABLE t1 (c CHAR(10) KEY);
INSERT INTO t1 VALUES (1.755555555);
SELECT * FROM t1 PROCEDURE ANALYSE();
DROP TABLE t1;
SET sql_mode=DEFAULT;
2024-07-18 06:15:43 +02:00
CREATE TABLE t1 (c BLOB) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1.3),(1.1);
SELECT * FROM t1 PROCEDURE ANALYSE();
DROP TABLE t1;
2024-07-17 06:39:43 +02:00
--echo #
--echo # End of 10.5 tests
--echo #