mirror of
https://github.com/MariaDB/server.git
synced 2025-01-20 14:02:32 +01:00
172 lines
4.3 KiB
Text
172 lines
4.3 KiB
Text
drop table if exists t0,t1,t2,t3;
|
|
create table t0 (a int);
|
|
INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
|
# r_filtered=30%, because 3 rows match: 0,1,2
|
|
analyze format=json select * from t0 where a<3;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t0",
|
|
"access_type": "ALL",
|
|
"r_loops": 1,
|
|
"rows": 10,
|
|
"r_rows": 10,
|
|
"filtered": 100,
|
|
"r_filtered": 30,
|
|
"attached_condition": "(t0.a < 3)"
|
|
}
|
|
}
|
|
}
|
|
create table t1 (a int, b int, c int, key(a));
|
|
insert into t1 select A.a*10 + B.a, A.a*10 + B.a, A.a*10 + B.a from t0 A, t0 B;
|
|
analyze
|
|
select * from t0, t1 where t1.a=t0.a and t0.a > 9;
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10 100.00 0.00 Using where
|
|
1 SIMPLE t1 ref a a 5 test.t0.a 1 NULL 100.00 NULL
|
|
analyze format=json
|
|
select * from t0, t1 where t1.a=t0.a and t0.a > 9;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t0",
|
|
"access_type": "ALL",
|
|
"r_loops": 1,
|
|
"rows": 10,
|
|
"r_rows": 10,
|
|
"filtered": 100,
|
|
"r_filtered": 0,
|
|
"attached_condition": "((t0.a > 9) and (t0.a is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ref",
|
|
"possible_keys": ["a"],
|
|
"key": "a",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t0.a"],
|
|
"r_loops": 0,
|
|
"rows": 1,
|
|
"r_rows": null,
|
|
"filtered": 100,
|
|
"r_filtered": null
|
|
}
|
|
}
|
|
}
|
|
analyze
|
|
select * from t0, t1 where t1.a=t0.a and t1.b<4;
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10 100.00 100.00 Using where
|
|
1 SIMPLE t1 ref a a 5 test.t0.a 1 1 100.00 40.00 Using where
|
|
analyze format=json
|
|
select * from t0, t1 where t1.a=t0.a and t1.b<4;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t0",
|
|
"access_type": "ALL",
|
|
"r_loops": 1,
|
|
"rows": 10,
|
|
"r_rows": 10,
|
|
"filtered": 100,
|
|
"r_filtered": 100,
|
|
"attached_condition": "(t0.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ref",
|
|
"possible_keys": ["a"],
|
|
"key": "a",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t0.a"],
|
|
"r_loops": 10,
|
|
"rows": 1,
|
|
"r_rows": 1,
|
|
"filtered": 100,
|
|
"r_filtered": 40,
|
|
"attached_condition": "(t1.b < 4)"
|
|
}
|
|
}
|
|
}
|
|
analyze
|
|
select * from t1 tbl1, t1 tbl2 where tbl1.b<2 and tbl2.b>5;
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
1 SIMPLE tbl1 ALL NULL NULL NULL NULL 100 100 100.00 2.00 Using where
|
|
1 SIMPLE tbl2 ALL NULL NULL NULL NULL 100 100 100.00 94.00 Using where; Using join buffer (flat, BNL join)
|
|
analyze format=json
|
|
select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "tbl1",
|
|
"access_type": "ALL",
|
|
"r_loops": 1,
|
|
"rows": 100,
|
|
"r_rows": 100,
|
|
"filtered": 100,
|
|
"r_filtered": 20,
|
|
"attached_condition": "(tbl1.b < 20)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "tbl2",
|
|
"access_type": "ALL",
|
|
"r_loops": 1,
|
|
"rows": 100,
|
|
"r_rows": 100,
|
|
"filtered": 100,
|
|
"r_filtered": 60,
|
|
"attached_condition": "(tbl2.b < 60)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"join_type": "BNL",
|
|
"r_filtered": 100
|
|
}
|
|
}
|
|
}
|
|
analyze format=json
|
|
select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60 and tbl1.c > tbl2.c;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "tbl1",
|
|
"access_type": "ALL",
|
|
"r_loops": 1,
|
|
"rows": 100,
|
|
"r_rows": 100,
|
|
"filtered": 100,
|
|
"r_filtered": 20,
|
|
"attached_condition": "(tbl1.b < 20)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "tbl2",
|
|
"access_type": "ALL",
|
|
"r_loops": 1,
|
|
"rows": 100,
|
|
"r_rows": 100,
|
|
"filtered": 100,
|
|
"r_filtered": 60,
|
|
"attached_condition": "(tbl2.b < 60)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(tbl1.c > tbl2.c)",
|
|
"r_filtered": 15.833
|
|
}
|
|
}
|
|
}
|
|
drop table t1;
|
|
drop table t0;
|