Skip to content

Commit 9511194

Browse files
committed
Merge branch 'mysql-5.6' into mysql-5.7
2 parents c60528f + 3674603 commit 9511194

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

mysql-test/r/func_math.result

+2-2
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,9 @@ ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 DIV
664664
CREATE TABLE t1(a BIGINT, b BIGINT UNSIGNED);
665665
INSERT INTO t1 VALUES(-9223372036854775808, 9223372036854775809);
666666
SELECT -a FROM t1;
667-
ERROR 22003: BIGINT value is out of range in '-('-9223372036854775808')'
667+
ERROR 22003: BIGINT value is out of range in '-(`test`.`t1`.`a`)'
668668
SELECT -b FROM t1;
669-
ERROR 22003: BIGINT value is out of range in '-('9223372036854775809')'
669+
ERROR 22003: BIGINT value is out of range in '-(`test`.`t1`.`b`)'
670670
DROP TABLE t1;
671671
SET @a:=999999999999999999999999999999999999999999999999999999999999999999999999999999999;
672672
SELECT @a + @a;

sql/item.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -4407,7 +4407,8 @@ Item_param::eq(const Item *arg, bool binary_cmp) const
44074407

44084408
void Item_param::print(String *str, enum_query_type query_type)
44094409
{
4410-
if (state == NO_VALUE || query_type & QT_NORMALIZED_FORMAT)
4410+
if (state == NO_VALUE ||
4411+
query_type & (QT_NORMALIZED_FORMAT | QT_NO_DATA_EXPANSION))
44114412
{
44124413
str->append('?');
44134414
}
@@ -7828,7 +7829,8 @@ Item *Item_field::update_value_transformer(uchar *select_arg)
78287829

78297830
void Item_field::print(String *str, enum_query_type query_type)
78307831
{
7831-
if (field && field->table->const_table)
7832+
if (field && field->table->const_table &&
7833+
!(query_type & QT_NO_DATA_EXPANSION))
78327834
{
78337835
char buff[MAX_FIELD_WIDTH];
78347836
String tmp(buff,sizeof(buff),str->charset());

sql/item_func.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ITEM_FUNC_INCLUDED
22
#define ITEM_FUNC_INCLUDED
33

4-
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -337,7 +337,7 @@ class Item_func :public Item_result_field
337337
char buf[256];
338338
String str(buf, sizeof(buf), system_charset_info);
339339
str.length(0);
340-
print(&str, QT_ORDINARY);
340+
print(&str, QT_NO_DATA_EXPANSION);
341341
my_error(ER_DATA_OUT_OF_RANGE, MYF(0), type_name, str.c_ptr_safe());
342342
}
343343
inline double raise_float_overflow()

sql/item_geofunc.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ITEM_GEOFUNC_INCLUDED
22
#define ITEM_GEOFUNC_INCLUDED
33

4-
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -630,7 +630,7 @@ class Item_func_spatial_collection: public Item_geometry_func
630630
if (args[i]->fixed && args[i]->field_type() != MYSQL_TYPE_GEOMETRY)
631631
{
632632
String str;
633-
args[i]->print(&str, QT_ORDINARY);
633+
args[i]->print(&str, QT_NO_DATA_EXPANSION);
634634
str.append('\0');
635635
my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "non geometric",
636636
str.ptr());

sql/mysqld.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,13 @@ enum enum_query_type
929929
Change all Item_basic_constant to ? (used by query rewrite to compute
930930
digest.) Un-resolved hints will also be printed in this format.
931931
*/
932-
QT_NORMALIZED_FORMAT= (1 << 8)
932+
QT_NORMALIZED_FORMAT= (1 << 8),
933+
/**
934+
If an expression is constant, print the expression, not the value
935+
it evaluates to. Should be used for error messages, so that they
936+
don't reveal values.
937+
*/
938+
QT_NO_DATA_EXPANSION= (1 << 9),
933939
};
934940

935941
/* query_id */

sql/sql_lex.cc

+32-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -2876,26 +2876,46 @@ static void print_join(THD *thd,
28762876
/* List is reversed => we should reverse it before using */
28772877
List_iterator_fast<TABLE_LIST> ti(*tables);
28782878
TABLE_LIST **table;
2879-
uint non_const_tables= 0;
2879+
2880+
/*
2881+
If the QT_NO_DATA_EXPANSION flag is specified, we print the
2882+
original table list, including constant tables that have been
2883+
optimized away, as the constant tables may be referenced in the
2884+
expression printed by Item_field::print() when this flag is given.
2885+
Otherwise, only non-const tables are printed.
2886+
2887+
Example:
2888+
2889+
Original SQL:
2890+
select * from (select 1) t
2891+
2892+
Printed without QT_NO_DATA_EXPANSION:
2893+
select '1' AS `1` from dual
2894+
2895+
Printed with QT_NO_DATA_EXPANSION:
2896+
select `t`.`1` from (select 1 AS `1`) `t`
2897+
*/
2898+
const bool print_const_tables= (query_type & QT_NO_DATA_EXPANSION);
2899+
size_t tables_to_print= 0;
28802900

28812901
for (TABLE_LIST *t= ti++; t ; t= ti++)
2882-
if (!t->optimized_away)
2883-
non_const_tables++;
2884-
if (!non_const_tables)
2902+
if (print_const_tables || !t->optimized_away)
2903+
tables_to_print++;
2904+
if (tables_to_print == 0)
28852905
{
28862906
str->append(STRING_WITH_LEN("dual"));
28872907
return; // all tables were optimized away
28882908
}
28892909
ti.rewind();
28902910

2891-
if (!(table= (TABLE_LIST **)thd->alloc(sizeof(TABLE_LIST*) *
2892-
non_const_tables)))
2911+
if (!(table= static_cast<TABLE_LIST **>(thd->alloc(sizeof(TABLE_LIST*) *
2912+
tables_to_print))))
28932913
return; // out of memory
28942914

2895-
TABLE_LIST *tmp, **t= table + (non_const_tables - 1);
2915+
TABLE_LIST *tmp, **t= table + (tables_to_print - 1);
28962916
while ((tmp= ti++))
28972917
{
2898-
if (tmp->optimized_away)
2918+
if (tmp->optimized_away && !print_const_tables)
28992919
continue;
29002920
*t--= tmp;
29012921
}
@@ -2907,7 +2927,7 @@ static void print_join(THD *thd,
29072927
*/
29082928
if ((*table)->sj_cond())
29092929
{
2910-
TABLE_LIST **end= table + non_const_tables;
2930+
TABLE_LIST **end= table + tables_to_print;
29112931
for (TABLE_LIST **t2= table; t2!=end; t2++)
29122932
{
29132933
if (!(*t2)->sj_cond())
@@ -2919,8 +2939,8 @@ static void print_join(THD *thd,
29192939
}
29202940
}
29212941
}
2922-
DBUG_ASSERT(non_const_tables >= 1);
2923-
print_table_array(thd, str, table, table + non_const_tables, query_type);
2942+
DBUG_ASSERT(tables_to_print >= 1);
2943+
print_table_array(thd, str, table, table + tables_to_print, query_type);
29242944
}
29252945

29262946

0 commit comments

Comments
 (0)