mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
eb483c5181
- multi_range_read_info_const now uses the new records_in_range interface - Added handler::avg_io_cost() - Don't calculate avg_io_cost() in get_sweep_read_cost if avg_io_cost is not 1.0. In this case we trust the avg_io_cost() from the handler. - Changed test_quick_select to use TIME_FOR_COMPARE instead of TIME_FOR_COMPARE_IDX to align this with the rest of the code. - Fixed bug when using test_if_cheaper_ordering where we didn't use keyread if index was changed - Fixed a bug where we didn't use index only read when using order-by-index - Added keyread_time() to HEAP. The default keyread_time() was optimized for blocks and not suitable for HEAP. The effect was the HEAP prefered table scans over ranges for btree indexes. - Fixed get_sweep_read_cost() for HEAP tables - Ensure that range and ref have same cost for simple ranges Added a small cost (MULTI_RANGE_READ_SETUP_COST) to ranges to ensure we favior ref for range for simple queries. - Fixed that matching_candidates_in_table() uses same number of records as the rest of the optimizer - Added avg_io_cost() to JT_EQ_REF cost. This helps calculate the cost for HEAP and temporary tables better. A few tests changed because of this. - heap::read_time() and heap::keyread_time() adjusted to not add +1. This was to ensure that handler::keyread_time() doesn't give higher cost for heap tables than for normal tables. One effect of this is that heap and derived tables stored in heap will prefer key access as this is now regarded as cheap. - Changed cost for index read in sql_select.cc to match multi_range_read_info_const(). All index cost calculation is now done trough one function. - 'ref' will now use quick_cost for keys if it exists. This is done so that for '=' ranges, 'ref' is prefered over 'range'. - scan_time() now takes avg_io_costs() into account - get_delayed_table_estimates() uses block_size and avg_io_cost() - Removed default argument to test_if_order_by_key(); simplifies code
144 lines
4.8 KiB
Text
144 lines
4.8 KiB
Text
#
|
|
# MDEV-16917: do not use splitting for derived with join cache
|
|
#
|
|
CREATE TABLE t1 (
|
|
n1 int(10) NOT NULL,
|
|
n2 int(10) NOT NULL,
|
|
c1 char(1) NOT NULL,
|
|
KEY c1 (c1),
|
|
KEY n1_c1_n2 (n1,c1,n2)
|
|
) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES (0, 2, 'a'), (1, 3, 'a');
|
|
insert into t1 select seq+1,seq+2,'c' from seq_1_to_1000;
|
|
ANALYZE TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status Engine-independent statistics collected
|
|
test.t1 analyze status OK
|
|
EXPLAIN SELECT t1.n1 FROM t1, (SELECT n1, n2 FROM t1 WHERE c1 = 'a' GROUP BY n1) as t
|
|
WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t1 ref c1,n1_c1_n2 c1 1 const 2 Using index condition; Using where; Using temporary; Using filesort
|
|
1 PRIMARY <derived2> ref key0 key0 8 test.t1.n1,test.t1.n2 2
|
|
2 LATERAL DERIVED t1 ref c1,n1_c1_n2 n1_c1_n2 4 test.t1.n1 1 Using where; Using index
|
|
SELECT t1.n1 FROM t1, (SELECT n1, n2 FROM t1 WHERE c1 = 'a' GROUP BY n1) as t
|
|
WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1;
|
|
n1
|
|
0
|
|
1
|
|
DROP TABLE t1;
|
|
#
|
|
# MDEV-17211: splittable materialized derived joining 3 tables with
|
|
# GROUP BY list containing fields from 2 of them
|
|
#
|
|
CREATE TABLE t1 (
|
|
id1 int, i1 int, id2 int,
|
|
PRIMARY KEY (id1), KEY (i1), KEY (id2)
|
|
) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES (1,1,1);
|
|
CREATE TABLE t2 (id2 int, i2 int) ENGINE=InnoDB;
|
|
INSERT INTO t2 VALUES (1, 1);
|
|
CREATE TABLE t3 (id3 int, i3 int, PRIMARY KEY (id3)) ENGINE=InnoDB;
|
|
INSERT INTO t3 VALUES (1,1);
|
|
EXPLAIN SELECT id3
|
|
FROM (SELECT t3.id3, t2.i2, t1.id2 FROM t3,t1,t2
|
|
WHERE t3.i3=t1.id1 AND t2.id2=t1.id2
|
|
GROUP BY t3.id3, t1.id2) AS t,
|
|
t2
|
|
WHERE t2.id2=t.id2;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.id2 2
|
|
2 DERIVED t3 ALL NULL NULL NULL NULL 1 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 eq_ref PRIMARY,id2 PRIMARY 4 test.t3.i3 1
|
|
2 DERIVED t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
|
|
SELECT id3
|
|
FROM (SELECT t3.id3, t2.i2, t1.id2 FROM t3,t1,t2
|
|
WHERE t3.i3=t1.id1 AND t2.id2=t1.id2
|
|
GROUP BY t3.id3, t1.id2) AS t,
|
|
t2
|
|
WHERE t2.id2=t.id2;
|
|
id3
|
|
1
|
|
DROP TABLE t1,t2,t3;
|
|
#
|
|
# Bug mdev-17381: equi-join of derived table with join_cache_level=4
|
|
#
|
|
CREATE TABLE t1 (
|
|
id int NOT NULL,
|
|
amount decimal DEFAULT NULL,
|
|
PRIMARY KEY (id)
|
|
) ENGINE=INNODB;
|
|
CREATE TABLE t2 (
|
|
id int NOT NULL,
|
|
name varchar(50) DEFAULT NULL,
|
|
PRIMARY KEY (id)
|
|
) ENGINE=INNODB;
|
|
INSERT INTO t1 VALUES
|
|
(1, 10.0000), (2, 20.0000), (3, 30.0000), (4, 40.0000),
|
|
(5, NULL), (6, NULL), (7, 70.0000), (8, 80.0000);
|
|
INSERT INTO t2 VALUES
|
|
(1,'A'), (2,'B'), (3,'C'), (4,'D'), (5, NULL), (6, NULL),
|
|
(7,'E'), (8,'F'), (9,'G'), (10,'H'), (11, NULL), (12, NULL);
|
|
set join_cache_level=4;
|
|
SELECT t2.id,t2.name,t.total_amt
|
|
FROM t2
|
|
LEFT JOIN
|
|
(SELECT id, sum(amount) total_amt FROM t1 GROUP BY id) AS t
|
|
ON t2.id=t.id
|
|
WHERE t2.id < 3;
|
|
id name total_amt
|
|
1 A 10
|
|
2 B 20
|
|
EXPLAIN SELECT t2.id,t2.name,t.total_amt
|
|
FROM t2
|
|
LEFT JOIN
|
|
(SELECT id, sum(amount) total_amt FROM t1 GROUP BY id) AS t
|
|
ON t2.id=t.id
|
|
WHERE t2.id < 3;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.id 2
|
|
2 LATERAL DERIVED t1 eq_ref PRIMARY PRIMARY 4 test.t2.id 1
|
|
set join_cache_level=default;
|
|
DROP TABLE t1,t2;
|
|
#
|
|
# Bug mdev-18467: join of grouping view and a base table as inner operand
|
|
# of left join with on condition containing impossible range
|
|
#
|
|
create table t1 (f1 int, f2 int, key(f2)) engine=InnoDB;
|
|
insert into t1 values (3,33), (7,77), (1,11);
|
|
create table t2 (f1 int, f2 int, primary key (f1)) engine=InnoDB;
|
|
insert into t2 values (3,33), (9,99), (1,11);
|
|
create view v1 as
|
|
select f1, max(f2) as f2 from t2 group by f1;
|
|
select t.f2
|
|
from t1
|
|
left join
|
|
(v1 join t1 as t on v1.f1=t.f1 and t.f2 = null)
|
|
on t1.f1=t.f1;
|
|
f2
|
|
NULL
|
|
NULL
|
|
NULL
|
|
explain select t.f2
|
|
from t1
|
|
left join
|
|
(v1 join t1 as t on v1.f1=t.f1 and t.f2 = null)
|
|
on t1.f1=t.f1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t const f2 NULL NULL NULL 1 Impossible ON condition
|
|
1 PRIMARY <derived2> const key1 NULL NULL NULL 1 Impossible ON condition
|
|
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
|
|
2 DERIVED t2 ALL PRIMARY NULL NULL NULL 3 Using temporary; Using filesort
|
|
set statement optimizer_switch='split_materialized=off' for explain select t.f2
|
|
from t1
|
|
left join
|
|
(v1 join t1 as t on v1.f1=t.f1 and t.f2 = null)
|
|
on t1.f1=t.f1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t const f2 NULL NULL NULL 1 Impossible ON condition
|
|
1 PRIMARY <derived3> const key1 NULL NULL NULL 1 Impossible ON condition
|
|
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
|
|
3 DERIVED t2 index NULL PRIMARY 4 NULL 3
|
|
drop view v1;
|
|
drop table t1,t2;
|