summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-03-22 11:15:21 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2019-03-22 11:15:21 +0200
commit031fa8f1d260cd9fae67a307d901bd4432bdf1cb (patch)
tree36c96ba92e2f345dd26cc8ebe521dde1906ad384 /sql
parent1caec9c8982a73f3db78fabc570934b837658109 (diff)
parent8be02be08bf6a7227e2ab6a5443b63f3a155e2a9 (diff)
downloadmariadb-git-031fa8f1d260cd9fae67a307d901bd4432bdf1cb.tar.gz
Merge 10.1 into 10.2
Diffstat (limited to 'sql')
-rw-r--r--sql/item_strfunc.cc39
-rw-r--r--sql/item_strfunc.h25
-rw-r--r--sql/item_sum.cc17
-rw-r--r--sql/opt_subselect.cc2
-rw-r--r--sql/wsrep_binlog.cc1
5 files changed, 40 insertions, 44 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 76f3a98cd2d..b88f376e8dd 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2017, Oracle and/or its affiliates.
- Copyright (c) 2009, 2018, MariaDB Corporation
+ Copyright (c) 2009, 2019, MariaDB Corporation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -3086,8 +3086,12 @@ err:
}
-bool Item_func_rpad::fix_length_and_dec()
+bool Item_func_pad::fix_length_and_dec()
{
+ String *str;
+ if (!args[2]->basic_const_item() || !(str= args[2]->val_str(&pad_str)) || !str->length())
+ maybe_null= true;
+
// Handle character set for args[0] and args[2].
if (agg_arg_charsets_for_string_result(collation, &args[0], 2, 2))
return TRUE;
@@ -3122,7 +3126,7 @@ String *Item_func_rpad::val_str(String *str)
longlong count= args[1]->val_int();
longlong byte_count;
String *res= args[0]->val_str(str);
- String *rpad= args[2]->val_str(&rpad_str);
+ String *rpad= args[2]->val_str(&pad_str);
if (!res || args[1]->null_value || !rpad ||
((count < 0) && !args[1]->unsigned_flag))
@@ -3195,33 +3199,6 @@ String *Item_func_rpad::val_str(String *str)
}
-bool Item_func_lpad::fix_length_and_dec()
-{
- // Handle character set for args[0] and args[2].
- if (agg_arg_charsets_for_string_result(collation, &args[0], 2, 2))
- return TRUE;
-
- if (args[1]->const_item())
- {
- ulonglong char_length= (ulonglong) args[1]->val_int();
- DBUG_ASSERT(collation.collation->mbmaxlen > 0);
- /* Assumes that the maximum length of a String is < INT_MAX32. */
- /* Set here so that rest of code sees out-of-bound value as such. */
- if (args[1]->null_value)
- char_length= 0;
- else if (char_length > INT_MAX32)
- char_length= INT_MAX32;
- fix_char_length_ulonglong(char_length);
- }
- else
- {
- max_length= MAX_BLOB_WIDTH;
- maybe_null= 1;
- }
- return FALSE;
-}
-
-
String *Item_func_lpad::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
@@ -3230,7 +3207,7 @@ String *Item_func_lpad::val_str(String *str)
longlong count= args[1]->val_int();
longlong byte_count;
String *res= args[0]->val_str(&tmp_value);
- String *pad= args[2]->val_str(&lpad_str);
+ String *pad= args[2]->val_str(&pad_str);
if (!res || args[1]->null_value || !pad ||
((count < 0) && !args[1]->unsigned_flag))
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index b3baae99c15..9a78a7f34f5 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -3,7 +3,7 @@
/*
Copyright (c) 2000, 2011, Oracle and/or its affiliates.
- Copyright (c) 2009, 2015, MariaDB
+ Copyright (c) 2009, 2019, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -932,28 +932,35 @@ public:
};
-class Item_func_rpad :public Item_str_func
+class Item_func_pad: public Item_str_func
{
- String tmp_value, rpad_str;
+protected:
+ String tmp_value, pad_str;
public:
- Item_func_rpad(THD *thd, Item *arg1, Item *arg2, Item *arg3):
+ Item_func_pad(THD *thd, Item *arg1, Item *arg2, Item *arg3):
Item_str_func(thd, arg1, arg2, arg3) {}
- String *val_str(String *);
bool fix_length_and_dec();
+};
+
+
+class Item_func_rpad :public Item_func_pad
+{
+public:
+ Item_func_rpad(THD *thd, Item *arg1, Item *arg2, Item *arg3):
+ Item_func_pad(thd, arg1, arg2, arg3) {}
+ String *val_str(String *);
const char *func_name() const { return "rpad"; }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_rpad>(thd, mem_root, this); }
};
-class Item_func_lpad :public Item_str_func
+class Item_func_lpad :public Item_func_pad
{
- String tmp_value, lpad_str;
public:
Item_func_lpad(THD *thd, Item *arg1, Item *arg2, Item *arg3):
- Item_str_func(thd, arg1, arg2, arg3) {}
+ Item_func_pad(thd, arg1, arg2, arg3) {}
String *val_str(String *);
- bool fix_length_and_dec();
const char *func_name() const { return "lpad"; }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_lpad>(thd, mem_root, this); }
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 9e59ec4e373..4405477b6a1 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1808,6 +1808,18 @@ double Item_sum_std::val_real()
{
DBUG_ASSERT(fixed == 1);
double nr= Item_sum_variance::val_real();
+ if (isnan(nr))
+ {
+ /*
+ variance_fp_recurrence_next() can overflow in some cases and return "nan":
+
+ CREATE OR REPLACE TABLE t1 (a DOUBLE);
+ INSERT INTO t1 VALUES (1.7e+308), (-1.7e+308), (0);
+ SELECT STDDEV_SAMP(a) FROM t1;
+ */
+ null_value= true; // Convert "nan" to NULL
+ return 0;
+ }
if (my_isinf(nr))
return DBL_MAX;
DBUG_ASSERT(nr >= 0.0);
@@ -1855,8 +1867,9 @@ static void variance_fp_recurrence_next(double *m, double *s, ulonglong *count,
else
{
double m_kminusone= *m;
- *m= m_kminusone + (nr - m_kminusone) / (double) *count;
- *s= *s + (nr - m_kminusone) * (nr - *m);
+ volatile double diff= nr - m_kminusone;
+ *m= m_kminusone + diff / (double) *count;
+ *s= *s + diff * (nr - *m);
}
}
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index d0be72b8d51..e7bd7e88af3 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -677,7 +677,7 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
select_lex->outer_select()->join && // 6
parent_unit->first_select()->leaf_tables.elements && // 7
!in_subs->has_strategy() && // 8
- select_lex->outer_select()->leaf_tables.elements && // 9
+ select_lex->outer_select()->table_list.first && // 9
!((join->select_options | // 10
select_lex->outer_select()->join->select_options) // 10
& SELECT_STRAIGHT_JOIN) && // 10
diff --git a/sql/wsrep_binlog.cc b/sql/wsrep_binlog.cc
index 672e1d77f47..292cbe6ee25 100644
--- a/sql/wsrep_binlog.cc
+++ b/sql/wsrep_binlog.cc
@@ -505,7 +505,6 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf,
if (init_io_cache(&cache, file, 0, WRITE_CACHE, 0, 0, MYF(MY_WME | MY_NABP)))
{
- mysql_file_close(file, MYF(MY_WME));
goto cleanup2;
}