summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-07-14 17:13:37 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-07-14 22:59:19 +0300
commit8a0944080c950349aaf7c81bc8f8c63b262f98eb (patch)
tree660faff324d2f66e57e2800155196739bf972dc1 /sql
parentf3f23b5c4bdc669ad0af4a1c79bd70c40ed9c594 (diff)
parent07e89bf7d15ba9e9a3b21d087c20d687446b2ff7 (diff)
downloadmariadb-git-8a0944080c950349aaf7c81bc8f8c63b262f98eb.tar.gz
Merge 10.2 into 10.3
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc2
-rw-r--r--sql/filesort.cc5
-rw-r--r--sql/filesort_utils.cc2
-rw-r--r--sql/item_windowfunc.h2
-rw-r--r--sql/opt_subselect.cc5
-rw-r--r--sql/sp.cc10
-rw-r--r--sql/sql_lex.cc4
-rw-r--r--sql/sql_lex.h13
-rw-r--r--sql/sql_parse.cc10
-rw-r--r--sql/sql_select.cc19
-rw-r--r--sql/sql_window.cc8
-rw-r--r--sql/sys_vars.cc13
-rw-r--r--sql/winservice.c30
13 files changed, 98 insertions, 25 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 8accfb35b0b..ff158010cb6 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -62,7 +62,7 @@ const char field_separator=',';
#define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
((ulong) ((1LL << MY_MIN(arg, 4) * 8) - 1))
-// Column marked for read or the field set to read out or record[0] or [1]
+// Column marked for read or the field set to read out of record[0]
#define ASSERT_COLUMN_MARKED_FOR_READ \
DBUG_ASSERT(!table || \
(!table->read_set || \
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 2251fb2b168..0dbf8df4ec4 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
- Copyright (c) 2009, 2015, MariaDB
+ Copyright (c) 2009, 2020, 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
@@ -242,7 +242,8 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
while (memory_available >= min_sort_memory)
{
ulonglong keys= memory_available / (param.rec_length + sizeof(char*));
- param.max_keys_per_buffer= (uint) MY_MIN(num_rows, keys);
+ param.max_keys_per_buffer= (uint) MY_MAX(MERGEBUFF2,
+ MY_MIN(num_rows, keys));
if (sort->alloc_sort_buffer(param.max_keys_per_buffer, param.rec_length))
break;
size_t old_memory_available= memory_available;
diff --git a/sql/filesort_utils.cc b/sql/filesort_utils.cc
index 703db84495f..849e6ee761a 100644
--- a/sql/filesort_utils.cc
+++ b/sql/filesort_utils.cc
@@ -1,4 +1,5 @@
/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2012, 2020, 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
@@ -106,7 +107,6 @@ uchar **Filesort_buffer::alloc_sort_buffer(uint num_records,
DBUG_SET("+d,simulate_out_of_memory"););
buff_size= ((size_t)num_records) * (record_length + sizeof(uchar*));
- set_if_bigger(buff_size, record_length * MERGEBUFF2);
if (!m_idx_array.is_null())
{
diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h
index 971b316ca99..977c217cd1e 100644
--- a/sql/item_windowfunc.h
+++ b/sql/item_windowfunc.h
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2016,2017 MariaDB
+ Copyright (c) 2016, 2020, 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
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index 50f7efd6d65..83840d65876 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -697,9 +697,8 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
{
DBUG_PRINT("info", ("Subquery can't be converted to merged semi-join"));
/* Test if the user has set a legal combination of optimizer switches. */
- if (!optimizer_flag(thd, OPTIMIZER_SWITCH_IN_TO_EXISTS) &&
- !optimizer_flag(thd, OPTIMIZER_SWITCH_MATERIALIZATION))
- my_error(ER_ILLEGAL_SUBQUERY_OPTIMIZER_SWITCHES, MYF(0));
+ DBUG_ASSERT(optimizer_flag(thd, OPTIMIZER_SWITCH_IN_TO_EXISTS |
+ OPTIMIZER_SWITCH_MATERIALIZATION));
/*
Transform each subquery predicate according to its overloaded
transformer.
diff --git a/sql/sp.cc b/sql/sp.cc
index 5e162e5dfec..93c1f13e0d6 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2002, 2018, Oracle and/or its affiliates.
- Copyright (c) 2009, 2018, MariaDB
+ Copyright (c) 2009, 2020, 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
@@ -1233,20 +1233,20 @@ Sp_handler::sp_create_routine(THD *thd, const sp_head *sp) const
switch (type()) {
case TYPE_ENUM_PACKAGE:
// Drop together with its PACKAGE BODY mysql.proc record
- ret= sp_handler_package_spec.sp_find_and_drop_routine(thd, table, sp);
+ if (sp_handler_package_spec.sp_find_and_drop_routine(thd, table, sp))
+ goto done;
break;
case TYPE_ENUM_PACKAGE_BODY:
case TYPE_ENUM_FUNCTION:
case TYPE_ENUM_PROCEDURE:
- ret= sp_drop_routine_internal(thd, sp, table);
+ if (sp_drop_routine_internal(thd, sp, table))
+ goto done;
break;
case TYPE_ENUM_TRIGGER:
case TYPE_ENUM_PROXY:
DBUG_ASSERT(0);
ret= SP_OK;
}
- if (ret != SP_OK)
- goto done;
}
else if (lex->create_info.if_not_exists())
{
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 0b423355170..e2e80cb21f6 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -2344,6 +2344,7 @@ void st_select_lex::init_query()
n_sum_items= 0;
n_child_sum_items= 0;
hidden_bit_fields= 0;
+ fields_in_window_functions= 0;
subquery_in_having= explicit_limit= 0;
is_item_list_lookup= 0;
changed_elements= 0;
@@ -2888,7 +2889,8 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
select_n_having_items +
select_n_where_fields +
order_group_num +
- hidden_bit_fields) * 5;
+ hidden_bit_fields +
+ fields_in_window_functions) * 5;
if (!ref_pointer_array.is_null())
{
/*
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index ea2ca10a444..8b8a55e0c96 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1063,6 +1063,14 @@ public:
converted to a GROUP BY involving BIT fields.
*/
uint hidden_bit_fields;
+ /*
+ Number of fields used in the definition of all the windows functions.
+ This includes:
+ 1) Fields in the arguments
+ 2) Fields in the PARTITION BY clause
+ 3) Fields in the ORDER BY clause
+ */
+ uint fields_in_window_functions;
enum_parsing_place parsing_place; /* where we are parsing expression */
enum_parsing_place context_analysis_place; /* where we are in prepare */
bool with_sum_func; /* sum function indicator */
@@ -1385,10 +1393,7 @@ public:
SQL_I_List<ORDER> win_order_list,
Window_frame *win_frame);
List<Item_window_func> window_funcs;
- bool add_window_func(Item_window_func *win_func)
- {
- return window_funcs.push_back(win_func);
- }
+ bool add_window_func(Item_window_func *win_func);
bool have_window_funcs() const { return (window_funcs.elements !=0); }
ORDER *find_common_window_func_partition_fields(THD *thd);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index ead6235461e..835848d56e4 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -8645,6 +8645,11 @@ bool st_select_lex::add_window_def(THD *thd,
win_frame);
group_list= thd->lex->save_group_list;
order_list= thd->lex->save_order_list;
+ if (parsing_place != SELECT_LIST)
+ {
+ fields_in_window_functions+= win_part_list_ptr->elements +
+ win_order_list_ptr->elements;
+ }
return (win_def == NULL || window_specs.push_back(win_def));
}
@@ -8666,6 +8671,11 @@ bool st_select_lex::add_window_spec(THD *thd,
win_frame);
group_list= thd->lex->save_group_list;
order_list= thd->lex->save_order_list;
+ if (parsing_place != SELECT_LIST)
+ {
+ fields_in_window_functions+= win_part_list_ptr->elements +
+ win_order_list_ptr->elements;
+ }
thd->lex->win_spec= win_spec;
return (win_spec == NULL || window_specs.push_back(win_spec));
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 9f5a406507c..b34e6f1fc2e 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
- Copyright (c) 2009, 2019, MariaDB Corporation.
+ Copyright (c) 2009, 2020, 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
@@ -23565,10 +23565,13 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
List<Item> &fields, List<Item> &all_fields, ORDER *order,
bool from_window_spec)
{
+ SELECT_LEX *select = thd->lex->current_select;
enum_parsing_place context_analysis_place=
thd->lex->current_select->context_analysis_place;
thd->where="order clause";
- for (; order; order=order->next)
+ const bool for_union= select->master_unit()->is_unit_op() &&
+ select == select->master_unit()->fake_select_lex;
+ for (uint number = 1; order; order=order->next, number++)
{
if (find_order_in_list(thd, ref_pointer_array, tables, order, fields,
all_fields, false, true, from_window_spec))
@@ -23579,6 +23582,18 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0));
return 1;
}
+
+ /*
+ UNION queries cannot be used with an aggregate function in
+ an ORDER BY clause
+ */
+
+ if (for_union && (*order->item)->with_sum_func)
+ {
+ my_error(ER_AGGREGATE_ORDER_FOR_UNION, MYF(0), number);
+ return 1;
+ }
+
if (from_window_spec && (*order->item)->with_sum_func &&
(*order->item)->type() != Item::SUM_FUNC_ITEM)
(*order->item)->split_sum_func(thd, ref_pointer_array,
diff --git a/sql/sql_window.cc b/sql/sql_window.cc
index 35f5a83608c..abb3937096f 100644
--- a/sql/sql_window.cc
+++ b/sql/sql_window.cc
@@ -3159,6 +3159,14 @@ Window_funcs_computation::save_explain_plan(MEM_ROOT *mem_root,
return xpl;
}
+
+bool st_select_lex::add_window_func(Item_window_func *win_func)
+{
+ if (parsing_place != SELECT_LIST)
+ fields_in_window_functions+= win_func->window_func()->argument_count();
+ return window_funcs.push_back(win_func);
+}
+
/////////////////////////////////////////////////////////////////////////////
// Unneeded comments (will be removed when we develop a replacement for
// the feature that was attempted here
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 6166de2701a..120fb87ab50 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -2558,12 +2558,23 @@ static bool fix_optimizer_switch(sys_var *self, THD *thd,
"engine_condition_pushdown=on");
return false;
}
+static bool check_legal_optimizer_switch(sys_var *self, THD *thd,
+ set_var *var)
+{
+ if (var->save_result.ulonglong_value & (OPTIMIZER_SWITCH_MATERIALIZATION |
+ OPTIMIZER_SWITCH_IN_TO_EXISTS))
+ {
+ return false;
+ }
+ my_error(ER_ILLEGAL_SUBQUERY_OPTIMIZER_SWITCHES, MYF(0));
+ return true;
+}
static Sys_var_flagset Sys_optimizer_switch(
"optimizer_switch",
"Fine-tune the optimizer behavior",
SESSION_VAR(optimizer_switch), CMD_LINE(REQUIRED_ARG),
optimizer_switch_names, DEFAULT(OPTIMIZER_SWITCH_DEFAULT),
- NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
+ NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_legal_optimizer_switch),
ON_UPDATE(fix_optimizer_switch));
static Sys_var_charptr Sys_pid_file(
diff --git a/sql/winservice.c b/sql/winservice.c
index c275e6d99c8..d7cfd2f7584 100644
--- a/sql/winservice.c
+++ b/sql/winservice.c
@@ -116,6 +116,24 @@ BOOL exclude_service(mysqld_service_properties *props)
}
+static void get_datadir_from_ini(const char *ini, char *service_name, char *datadir, size_t sz)
+{
+ *datadir= 0;
+ const char *sections[]= {service_name, "mysqld", "server", "mariadb",
+ "mariadbd"};
+ for (int i= 0; i < sizeof(sections) / sizeof(sections[0]); i++)
+ {
+ if (sections[i])
+ {
+ GetPrivateProfileStringA(sections[i], "datadir", NULL, datadir,
+ (DWORD) sz, ini);
+ if (*datadir)
+ return;
+ }
+ }
+}
+
+
/*
Retrieve some properties from windows mysqld service binary path.
We're interested in ini file location and datadir, and also in version of
@@ -135,6 +153,7 @@ int get_mysql_service_properties(const wchar_t *bin_path,
wchar_t **args= NULL;
int retval= 1;
BOOL have_inifile;
+ char service_name[MAX_PATH];
props->datadir[0]= 0;
props->inifile[0]= 0;
@@ -163,6 +182,9 @@ int get_mysql_service_properties(const wchar_t *bin_path,
goto end;
}
+ /* Last parameter is the service name*/
+ wcstombs(service_name, args[numargs-1], MAX_PATH);
+
if(have_inifile && wcsncmp(args[1], L"--defaults-file=", 16) != 0)
goto end;
@@ -194,8 +216,8 @@ int get_mysql_service_properties(const wchar_t *bin_path,
normalize_path(props->inifile, MAX_PATH);
if (GetFileAttributes(props->inifile) != INVALID_FILE_ATTRIBUTES)
{
- GetPrivateProfileString("mysqld", "datadir", NULL, props->datadir, MAX_PATH,
- props->inifile);
+ get_datadir_from_ini(props->inifile, service_name, props->datadir,
+ sizeof(props->datadir));
}
else
{
@@ -244,8 +266,8 @@ int get_mysql_service_properties(const wchar_t *bin_path,
if (GetFileAttributes(props->inifile) != INVALID_FILE_ATTRIBUTES)
{
/* Ini file found, get datadir from there */
- GetPrivateProfileString("mysqld", "datadir", NULL, props->datadir,
- MAX_PATH, props->inifile);
+ get_datadir_from_ini(props->inifile, service_name, props->datadir,
+ sizeof(props->datadir));
}
else
{