Skip to content

Commit

Permalink
MDEV-7679: ANALYZE crashes when printing WHERE when no default db
Browse files Browse the repository at this point in the history
Fix Item_ident::print() to work when there is no current database
  • Loading branch information
spetrunia committed Mar 7, 2015
1 parent 66ad265 commit 2288b84
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
29 changes: 29 additions & 0 deletions mysql-test/r/analyze_format_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 16 additions & 0 deletions mysql-test/t/analyze_format_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;

3 changes: 2 additions & 1 deletion sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 2288b84

Please sign in to comment.