[Commits] 2288b84: MDEV-7679: ANALYZE crashes when printing WHERE when no default db

Sergei Petrunia psergey at askmonty.org
Sat Mar 7 19:51:35 EET 2015


revision-id: 2288b84df46501b89a70d7dc3b46020e0af9a95e
parent(s): 66ad265f3b58121d5a48c492dff79f48863df7c0
committer: Sergei Petrunia
branch nick: 10.1-cp2
timestamp: 2015-03-07 20:51:35 +0300
message:

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

Fix Item_ident::print() to work when there is no current database

---
 mysql-test/r/analyze_format_json.result |   29 +++++++++++++++++++++++++++++
 mysql-test/t/analyze_format_json.test   |   16 ++++++++++++++++
 sql/item.cc                             |    3 ++-
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/analyze_format_json.result b/mysql-test/r/analyze_format_json.result
index fcab200..26625cb 100644
--- a/mysql-test/r/analyze_format_json.result
+++ b/mysql-test/r/analyze_format_json.result
@@ -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;
diff --git a/mysql-test/t/analyze_format_json.test b/mysql-test/t/analyze_format_json.test
index 1adb693..f57db1d 100644
--- a/mysql-test/t/analyze_format_json.test
+++ b/mysql-test/t/analyze_format_json.test
@@ -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;
+
diff --git a/sql/item.cc b/sql/item.cc
index 5bc1273..85279b2 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -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))


More information about the commits mailing list