#
# MDEV-31247 Assertion `c >= 0' failed in COST_MULT upon query with
# many joins
#
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
INSERT INTO t3 VALUES (1),(2),(3);
CREATE TABLE t4 (d CHAR(200), e INT, KEY(e)) ENGINE=Aria;
INSERT INTO t4 (e) VALUES (1),(2),(3);
CREATE TABLE t5 (f INT) ENGINE=MyISAM;
INSERT INTO t5 VALUES (1),(2),(3),(4),(5),(6);
create table t1000 engine=memory select seq from seq_1_to_1000;
create table t2000 engine=memory select seq from seq_1_to_2000;
CREATE ALGORITHM=TEMPTABLE VIEW v AS select t1000.seq
from t1000 ml1
join t1000 ml2
join t1000;
set @@max_statement_time=10;
SELECT * FROM information_schema.TABLES
JOIN t1000 ts
JOIN t1000 d1
JOIN t2000 d3
LEFT JOIN (t1 JOIN t2) ON 1
JOIN t1000 d5
JOIN t1000 PROCESSLIST
JOIN t1000 d2
JOIN t1000 event_name
JOIN t3
JOIN t4 ON ts.seq = t4.e
JOIN v ON ts.seq+1 = v.seq
JOIN t5 limit rows examined 1000;
TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	TABLE_TYPE	ENGINE	VERSION	ROW_FORMAT	TABLE_ROWS	AVG_ROW_LENGTH	DATA_LENGTH	MAX_DATA_LENGTH	INDEX_LENGTH	DATA_FREE	AUTO_INCREMENT	CREATE_TIME	UPDATE_TIME	CHECK_TIME	TABLE_COLLATION	CHECKSUM	CREATE_OPTIONS	TABLE_COMMENT	MAX_INDEX_LENGTH	TEMPORARY	seq	seq	seq	a	b	seq	seq	seq	seq	c	d	e	seq	f
Warnings:
Warning	1931	Query execution was interrupted. The query exceeded LIMIT ROWS EXAMINED 1000. The query result may be incomplete
DROP VIEW v;
DROP TABLE t1, t2, t3, t4, t5, t1000, t2000;
#
# MDEV-31391 Assertion `((best.records_out) == 0.0 &&
# (best.records) == 0.0) ||
# (best.records_out)/(best.records) < 1.0000001' failed
#
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a), KEY(b)) ENGINE=Aria;
INSERT INTO t1 VALUES
(1,13),(2,22),(3,8),(4,88),(5,6),(7,21),(9,64),(10,14),(11,15),(12,8),
(6,20),(8,39),(13,0),(14,3),(15,54),(16,85),(17,1),(18,1),(19,0),(20,0);
CREATE TABLE t2 (c INT) ENGINE=Aria;
INSERT INTO t2 VALUES (1),(2),(3);
EXPLAIN SELECT a FROM t1 JOIN t2 WHERE a = b AND c <> 7 GROUP BY a HAVING a != 6 AND a <= 9;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	PRIMARY,b	PRIMARY	4	NULL	9	Using index condition; Using where; Using temporary; Using filesort
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer (flat, BNL join)
SELECT a FROM t1 JOIN t2 WHERE a = b AND c <> 7 GROUP BY a HAVING a != 6 AND a <= 9;
a
DROP TABLE t1, t2;
#
# MDEV-31375 Assertion `dbl_records <= s->records' failed with
# optimizer_use_condition_selectivity=1
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (id INT PRIMARY KEY);
INSERT INTO t2 VALUES (2),(3);
SET optimizer_switch = 'derived_with_keys=off';
SET optimizer_use_condition_selectivity = 1;
SELECT t1.* FROM t1 JOIN (SELECT id, COUNT(*) FROM t2 GROUP BY id) sq ON sq.id = t1.a;
a
2
DROP TABLE t1, t2;
#
# End of 11.0 tests
#
