2014-11-29 03:07:24 +03:00
|
|
|
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,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_loops": 1,
|
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"table": {
|
|
|
|
"table_name": "t0",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"rows": 10,
|
|
|
|
"r_rows": 10,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"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
|
2015-03-07 19:30:19 +03:00
|
|
|
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10.00 100.00 0.00 Using where
|
2014-11-29 03:07:24 +03:00
|
|
|
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,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_loops": 1,
|
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"table": {
|
|
|
|
"table_name": "t0",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"rows": 10,
|
|
|
|
"r_rows": 10,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"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
|
2015-03-07 19:30:19 +03:00
|
|
|
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10.00 100.00 100.00 Using where
|
|
|
|
1 SIMPLE t1 ref a a 5 test.t0.a 1 1.00 100.00 40.00 Using where
|
2014-11-29 03:07:24 +03:00
|
|
|
analyze format=json
|
|
|
|
select * from t0, t1 where t1.a=t0.a and t1.b<4;
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_loops": 1,
|
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"table": {
|
|
|
|
"table_name": "t0",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"rows": 10,
|
|
|
|
"r_rows": 10,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"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,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"filtered": 100,
|
|
|
|
"r_filtered": 40,
|
|
|
|
"attached_condition": "(t1.b < 4)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
analyze
|
2014-12-02 10:35:28 +03:00
|
|
|
select * from t1 tbl1, t1 tbl2 where tbl1.b<2 and tbl2.b>5;
|
2014-11-29 03:07:24 +03:00
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
2015-03-07 19:30:19 +03:00
|
|
|
1 SIMPLE tbl1 ALL NULL NULL NULL NULL 100 100.00 100.00 2.00 Using where
|
|
|
|
1 SIMPLE tbl2 ALL NULL NULL NULL NULL 100 100.00 100.00 94.00 Using where; Using join buffer (flat, BNL join)
|
2014-11-29 03:07:24 +03:00
|
|
|
analyze format=json
|
2014-12-02 10:35:28 +03:00
|
|
|
select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60;
|
2014-11-29 03:07:24 +03:00
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_loops": 1,
|
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"table": {
|
2014-12-02 10:35:28 +03:00
|
|
|
"table_name": "tbl1",
|
2014-11-29 03:07:24 +03:00
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"rows": 100,
|
|
|
|
"r_rows": 100,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"filtered": 100,
|
|
|
|
"r_filtered": 20,
|
2014-12-02 10:35:28 +03:00
|
|
|
"attached_condition": "(tbl1.b < 20)"
|
2014-11-29 03:07:24 +03:00
|
|
|
},
|
|
|
|
"block-nl-join": {
|
|
|
|
"table": {
|
2014-12-02 10:35:28 +03:00
|
|
|
"table_name": "tbl2",
|
2014-11-29 03:07:24 +03:00
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"rows": 100,
|
|
|
|
"r_rows": 100,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"filtered": 100,
|
2014-12-02 01:58:22 +03:00
|
|
|
"r_filtered": 60,
|
2014-12-02 10:35:28 +03:00
|
|
|
"attached_condition": "(tbl2.b < 60)"
|
2014-11-29 03:07:24 +03:00
|
|
|
},
|
|
|
|
"buffer_type": "flat",
|
|
|
|
"join_type": "BNL",
|
|
|
|
"r_filtered": 100
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
analyze format=json
|
2014-12-02 10:35:28 +03:00
|
|
|
select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60 and tbl1.c > tbl2.c;
|
2014-11-29 03:07:24 +03:00
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_loops": 1,
|
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"table": {
|
2014-12-02 10:35:28 +03:00
|
|
|
"table_name": "tbl1",
|
2014-11-29 03:07:24 +03:00
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"rows": 100,
|
|
|
|
"r_rows": 100,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"filtered": 100,
|
|
|
|
"r_filtered": 20,
|
2014-12-02 10:35:28 +03:00
|
|
|
"attached_condition": "(tbl1.b < 20)"
|
2014-11-29 03:07:24 +03:00
|
|
|
},
|
|
|
|
"block-nl-join": {
|
|
|
|
"table": {
|
2014-12-02 10:35:28 +03:00
|
|
|
"table_name": "tbl2",
|
2014-11-29 03:07:24 +03:00
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"rows": 100,
|
|
|
|
"r_rows": 100,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2014-11-29 03:07:24 +03:00
|
|
|
"filtered": 100,
|
|
|
|
"r_filtered": 60,
|
2014-12-02 10:35:28 +03:00
|
|
|
"attached_condition": "(tbl2.b < 60)"
|
2014-11-29 03:07:24 +03:00
|
|
|
},
|
|
|
|
"buffer_type": "flat",
|
|
|
|
"join_type": "BNL",
|
2014-12-02 10:35:28 +03:00
|
|
|
"attached_condition": "(tbl1.c > tbl2.c)",
|
2014-11-29 03:07:24 +03:00
|
|
|
"r_filtered": 15.833
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drop table t1;
|
|
|
|
drop table t0;
|
2015-03-07 19:30:19 +03:00
|
|
|
#
|
|
|
|
# MDEV-7674: ANALYZE shows r_rows=0
|
|
|
|
#
|
|
|
|
create table t1(a int);
|
|
|
|
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
|
|
|
create table t2 (a int, key(a));
|
|
|
|
insert into t2 values (0),(1);
|
|
|
|
analyze format=json select * from t1 straight_join t2 force index(a) where t2.a=t1.a;
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_loops": 1,
|
|
|
|
"r_total_time_ms": "REPLACED",
|
2015-03-07 19:30:19 +03:00
|
|
|
"table": {
|
|
|
|
"table_name": "t1",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"rows": 10,
|
|
|
|
"r_rows": 10,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2015-03-07 19:30:19 +03:00
|
|
|
"filtered": 100,
|
|
|
|
"r_filtered": 100,
|
|
|
|
"attached_condition": "(t1.a is not null)"
|
|
|
|
},
|
|
|
|
"table": {
|
|
|
|
"table_name": "t2",
|
|
|
|
"access_type": "ref",
|
|
|
|
"possible_keys": ["a"],
|
|
|
|
"key": "a",
|
|
|
|
"key_length": "5",
|
|
|
|
"used_key_parts": ["a"],
|
|
|
|
"ref": ["test.t1.a"],
|
|
|
|
"r_loops": 10,
|
|
|
|
"rows": 2,
|
|
|
|
"r_rows": 0.2,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2015-03-07 19:30:19 +03:00
|
|
|
"filtered": 100,
|
|
|
|
"r_filtered": 100,
|
|
|
|
"using_index": true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drop table t1,t2;
|
2015-03-07 20:51:35 +03:00
|
|
|
create table t1(a int);
|
|
|
|
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
|
|
|
#
|
|
|
|
# MDEV-7679: ANALYZE crashes when printing WHERE when no default db
|
|
|
|
#
|
|
|
|
select database();
|
|
|
|
database()
|
|
|
|
test
|
|
|
|
select database();
|
|
|
|
database()
|
|
|
|
NULL
|
|
|
|
analyze format=json select * from test.t1 where t1.a<5;
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_loops": 1,
|
|
|
|
"r_total_time_ms": "REPLACED",
|
2015-03-07 20:51:35 +03:00
|
|
|
"table": {
|
|
|
|
"table_name": "t1",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"rows": 10,
|
|
|
|
"r_rows": 10,
|
2015-03-07 22:47:28 +03:00
|
|
|
"r_total_time_ms": "REPLACED",
|
2015-03-07 20:51:35 +03:00
|
|
|
"filtered": 100,
|
|
|
|
"r_filtered": 50,
|
|
|
|
"attached_condition": "(test.t1.a < 5)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drop table t1;
|