Commit 2288b84d authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-7679: ANALYZE crashes when printing WHERE when no default db

Fix Item_ident::print() to work when there is no current database
parent 66ad265f
......@@ -210,3 +210,32 @@ EXPLAIN
}
}
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;
......@@ -51,3 +51,19 @@ analyze format=json select * from t1 straight_join t2 force index(a) where t2.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;
......@@ -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))
......
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