Skip to content

Commit 4278d6d

Browse files
author
Alexander Barkov
committed
MDEV-8786 Wrong result for SELECT FORMAT=JSON * FROM t1 WHERE a=_latin1 0xDF
1 parent 416b811 commit 4278d6d

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

mysql-test/r/explain_json.result

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,3 +1070,23 @@ EXPLAIN
10701070
}
10711071
}
10721072
drop table t1;
1073+
#
1074+
# MDEV-8786 Wrong result for SELECT FORMAT=JSON * FROM t1 WHERE a=_latin1 0xDF
1075+
#
1076+
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1);
1077+
INSERT INTO t1 VALUES ('a'),('b');
1078+
EXPLAIN FORMAT=JSON SELECT * FROM t1 WHERE a=_latin1 0xDF;
1079+
EXPLAIN
1080+
{
1081+
"query_block": {
1082+
"select_id": 1,
1083+
"table": {
1084+
"table_name": "t1",
1085+
"access_type": "ALL",
1086+
"rows": 2,
1087+
"filtered": 100,
1088+
"attached_condition": "(t1.a = _latin1'\xDF')"
1089+
}
1090+
}
1091+
}
1092+
DROP TABLE t1;

mysql-test/t/explain_json.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,10 @@ explain format=json select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') a
279279
drop table t1;
280280

281281

282+
--echo #
283+
--echo # MDEV-8786 Wrong result for SELECT FORMAT=JSON * FROM t1 WHERE a=_latin1 0xDF
284+
--echo #
285+
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1);
286+
INSERT INTO t1 VALUES ('a'),('b');
287+
EXPLAIN FORMAT=JSON SELECT * FROM t1 WHERE a=_latin1 0xDF;
288+
DROP TABLE t1;

sql/item.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,8 +2495,8 @@ void Item_ident::print(String *str, enum_query_type query_type)
24952495
When printing EXPLAIN, don't print database name when it's the same as
24962496
current database.
24972497
*/
2498-
bool skip_db= (query_type & QT_EXPLAIN) && thd->db &&
2499-
!strcmp(thd->db, db_name);
2498+
bool skip_db= (query_type & QT_ITEM_IDENT_SKIP_CURRENT_DATABASE) &&
2499+
thd->db && !strcmp(thd->db, db_name);
25002500
if (!skip_db &&
25012501
!(cached_table && cached_table->belong_to_view &&
25022502
cached_table->belong_to_view->compact_view_format))
@@ -7601,7 +7601,7 @@ void Item_cache_wrapper::init_on_demand()
76017601

76027602
void Item_cache_wrapper::print(String *str, enum_query_type query_type)
76037603
{
7604-
if (query_type == QT_EXPLAIN)
7604+
if (query_type & QT_ITEM_CACHE_WRAPPER_SKIP_DETAILS)
76057605
{
76067606
/* Don't print the cache in EXPLAIN EXTENDED */
76077607
orig_item->print(str, query_type);

sql/item_subselect.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ void Item_subselect::update_used_tables()
899899

900900
void Item_subselect::print(String *str, enum_query_type query_type)
901901
{
902-
if (query_type == QT_EXPLAIN)
902+
if (query_type & QT_ITEM_SUBSELECT_ID_ONLY)
903903
{
904904
str->append("(subquery#");
905905
if (unit && unit->first_select())

sql/mysqld.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,12 +647,28 @@ enum enum_query_type
647647
QT_WITHOUT_INTRODUCERS= (1 << 1),
648648
/// view internal representation (like QT_ORDINARY except ORDER BY clause)
649649
QT_VIEW_INTERNAL= (1 << 2),
650+
/// If identifiers should not include database names for the current database
651+
QT_ITEM_IDENT_SKIP_CURRENT_DATABASE= (1 << 3),
652+
/// If Item_cache_wrapper should not print <expr_cache>
653+
QT_ITEM_CACHE_WRAPPER_SKIP_DETAILS= (1 << 4),
654+
/// If Item_subselect should print as just "(subquery#1)"
655+
/// rather than display the subquery body
656+
QT_ITEM_SUBSELECT_ID_ONLY= (1 << 5),
657+
650658
/// This value means focus on readability, not on ability to parse back, etc.
651-
QT_EXPLAIN= (1 << 4)
659+
QT_EXPLAIN= QT_TO_SYSTEM_CHARSET |
660+
QT_ITEM_IDENT_SKIP_CURRENT_DATABASE |
661+
QT_ITEM_CACHE_WRAPPER_SKIP_DETAILS |
662+
QT_ITEM_SUBSELECT_ID_ONLY,
663+
664+
/// This is used for EXPLAIN EXTENDED extra warnings
665+
/// Be more detailed than QT_EXPLAIN.
666+
/// Perhaps we should eventually include QT_ITEM_IDENT_SKIP_CURRENT_DATABASE
667+
/// here, as it would give better readable results
668+
QT_EXPLAIN_EXTENDED= QT_TO_SYSTEM_CHARSET
652669
};
653670

654671

655-
656672
/* query_id */
657673
typedef int64 query_id_t;
658674
extern query_id_t global_query_id;

sql/sql_parse.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5812,7 +5812,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
58125812
The warnings system requires input in utf8, @see
58135813
mysqld_show_warnings().
58145814
*/
5815-
lex->unit.print(&str, QT_TO_SYSTEM_CHARSET);
5815+
lex->unit.print(&str, QT_EXPLAIN_EXTENDED);
58165816
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
58175817
ER_YES, str.c_ptr_safe());
58185818
}

0 commit comments

Comments
 (0)