Commit e2de8044 authored by Sergei Golubchik's avatar Sergei Golubchik

Merge branch '10.1' into bb-10.1-serg

parents 5bff6c5d 2288b84d
......@@ -24,7 +24,7 @@ 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 t0 ALL NULL NULL NULL NULL 10 10.00 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;
......@@ -61,8 +61,8 @@ EXPLAIN
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
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
analyze format=json
select * from t0, t1 where t1.a=t0.a and t1.b<4;
EXPLAIN
......@@ -99,8 +99,8 @@ EXPLAIN
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)
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)
analyze format=json
select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60;
EXPLAIN
......@@ -170,3 +170,72 @@ EXPLAIN
}
drop table t1;
drop table t0;
#
# 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,
"table": {
"table_name": "t1",
"access_type": "ALL",
"r_loops": 1,
"rows": 10,
"r_rows": 10,
"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,
"filtered": 100,
"r_filtered": 100,
"using_index": true
}
}
}
drop table t1,t2;
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,
"table": {
"table_name": "t1",
"access_type": "ALL",
"r_loops": 1,
"rows": 10,
"r_rows": 10,
"filtered": 100,
"r_filtered": 50,
"attached_condition": "(test.t1.a < 5)"
}
}
}
drop table t1;
This diff is collapsed.
......@@ -10,6 +10,6 @@ drop table t1;
# explain: id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
# explain: 1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL
# explain: id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
# explain: 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 30.00 Using where
# explain: 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 100.00 30.00 Using where
# explain: id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
# explain: 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
......@@ -36,3 +36,34 @@ select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60 and tbl1.c > tbl2.c
drop table t1;
drop table t0;
--echo #
--echo # MDEV-7674: ANALYZE shows r_rows=0
--echo #
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;
drop table t1,t2;
create table t1(a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
--echo #
--echo # MDEV-7679: ANALYZE crashes when printing WHERE when no default db
--echo #
select database();
connect (con1,localhost,root,,*NO-ONE*);
connection con1;
select database();
analyze format=json select * from test.t1 where t1.a<5;
disconnect con1;
connection default;
drop table t1;
......@@ -244,3 +244,18 @@ create table t1(a int);
prepare stmt from "analyze select * from t1";
execute stmt;
drop table t1;
--echo #
--echo # MDEV-7674: ANALYZE shows r_rows=0
--echo #
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 select * from t1 straight_join t2 force index(a) where t2.a=t1.a;
drop table t1,t2;
......@@ -2380,7 +2380,8 @@ void Item_ident::print(String *str, enum_query_type query_type)
When printing EXPLAIN, don't print database name when it's the same as
current database.
*/
bool skip_db= (query_type & QT_EXPLAIN) && !strcmp(thd->db, db_name);
bool skip_db= (query_type & QT_EXPLAIN) && thd->db &&
!strcmp(thd->db, db_name);
if (!skip_db &&
!(cached_table && cached_table->belong_to_view &&
cached_table->belong_to_view->compact_view_format))
......
......@@ -2454,8 +2454,7 @@ void THD::make_explain_field_list(List<Item> &field_list, uint8 explain_flags,
MYSQL_TYPE_LONGLONG));
if (is_analyze)
{
field_list.push_back(item= new Item_return_int("r_rows", 10,
MYSQL_TYPE_LONGLONG));
field_list.push_back(item= new Item_float("r_rows", 0.1234, 10, 4));
item->maybe_null=1;
}
......
......@@ -298,7 +298,7 @@ int print_explain_row(select_result_sink *result,
const char *key_len,
const char *ref,
ha_rows *rows,
ha_rows *r_rows,
double *r_rows,
double r_filtered,
const char *extra)
{
......@@ -356,10 +356,7 @@ int print_explain_row(select_result_sink *result,
if (is_analyze)
{
if (r_rows)
{
item_list.push_back(new Item_int(*r_rows,
MY_INT64_NUM_DECIMAL_DIGITS));
}
item_list.push_back(new Item_float(*r_rows, 2));
else
item_list.push_back(item_null);
}
......@@ -472,9 +469,8 @@ int Explain_union::print_explain(Explain_query *query,
/* `r_rows` */
if (is_analyze)
{
ha_rows avg_rows= fake_select_lex_tracker.get_avg_rows();
item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows,
MY_INT64_NUM_DECIMAL_DIGITS));
double avg_rows= fake_select_lex_tracker.get_avg_rows();
item_list.push_back(new Item_float(avg_rows, 2));
}
/* `filtered` */
......@@ -1004,9 +1000,8 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
}
else
{
ha_rows avg_rows= tracker.get_avg_rows();
item_list.push_back(new Item_int((longlong) (ulonglong) avg_rows,
MY_INT64_NUM_DECIMAL_DIGITS));
double avg_rows= tracker.get_avg_rows();
item_list.push_back(new Item_float(avg_rows, 2));
}
}
......@@ -1289,8 +1284,8 @@ void Explain_table_access::print_explain_json(Explain_query *query,
writer->add_member("r_rows");
if (tracker.has_scans())
{
ha_rows avg_rows= tracker.get_avg_rows();
writer->add_ll(avg_rows);
double avg_rows= tracker.get_avg_rows();
writer->add_double(avg_rows);
}
else
writer->add_null();
......@@ -1756,7 +1751,7 @@ int Explain_update::print_explain(Explain_query *query,
"Using index condition" is also not possible (which is an unjustified limitation)
*/
double r_filtered= 100 * tracker.get_filtered_after_where();
ha_rows r_rows= tracker.get_avg_rows();
double r_rows= tracker.get_avg_rows();
print_explain_row(output, explain_flags, is_analyze,
1, /* id */
......@@ -1877,8 +1872,8 @@ void Explain_update::print_explain_json(Explain_query *query,
/* `r_rows` */
if (is_analyze && tracker.has_scans())
{
ha_rows avg_rows= tracker.get_avg_rows();
writer->add_member("r_rows").add_ll(avg_rows);
double avg_rows= tracker.get_avg_rows();
writer->add_member("r_rows").add_double(avg_rows);
}
/* UPDATE/DELETE do not produce `filtered` estimate */
......
......@@ -44,9 +44,9 @@ public:
bool has_scans() { return (r_scans != 0); }
ha_rows get_loops() { return r_scans; }
ha_rows get_avg_rows()
double get_avg_rows()
{
return r_scans ? (ha_rows)rint((double) r_rows / r_scans): 0;
return r_scans ? ((double)r_rows / r_scans): 0;
}
double get_filtered_after_where()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment