summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2017-07-04 15:31:25 +0400
committerAlexander Barkov <bar@mariadb.org>2017-07-04 15:31:25 +0400
commit5c0df0e4a89b12813cef665533e852a50ecaafae (patch)
treeb75df302abedca56d679ef04a019fac3a5fc7dbc /sql
parent25ad623d64ebc34093544875e5b0ebd6101e975b (diff)
parentad2d722acd7bd7a816dff7838f3fa2dcaaeec8da (diff)
downloadmariadb-git-5c0df0e4a89b12813cef665533e852a50ecaafae.tar.gz
Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Diffstat (limited to 'sql')
-rw-r--r--sql/filesort.cc3
-rw-r--r--sql/item.cc6
-rw-r--r--sql/item_cmpfunc.h5
-rw-r--r--sql/item_func.cc7
-rw-r--r--sql/item_sum.cc4
-rw-r--r--sql/opt_subselect.cc8
-rw-r--r--sql/sql_base.cc2
-rw-r--r--sql/sql_class.h3
-rw-r--r--sql/sql_prepare.cc2
-rw-r--r--sql/sql_select.cc22
-rw-r--r--sql/sql_show.cc4
-rw-r--r--sql/sys_vars.cc22
-rw-r--r--sql/table.cc4
-rw-r--r--sql/temporary_tables.cc46
14 files changed, 68 insertions, 70 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 8ca6cd04cda..31ff2e511a9 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -1486,8 +1486,6 @@ int merge_many_buff(Sort_param *param, uchar *sort_buffer,
if (flush_io_cache(to_file))
break; /* purecov: inspected */
temp=from_file; from_file=to_file; to_file=temp;
- setup_io_cache(from_file);
- setup_io_cache(to_file);
*maxbuffer= (uint) (lastbuff-buffpek)-1;
}
cleanup:
@@ -1495,7 +1493,6 @@ cleanup:
if (to_file == t_file)
{
*t_file=t_file2; // Copy result file
- setup_io_cache(t_file);
}
DBUG_RETURN(*maxbuffer >= MERGEBUFF2); /* Return 1 if interrupted */
diff --git a/sql/item.cc b/sql/item.cc
index 7279c79cef9..5f08f26b1de 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -2193,6 +2193,9 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
point to the temporary table.
*/
split_sum_func(thd, ref_pointer_array, fields, split_flags);
+ if (type() == FUNC_ITEM) {
+ return;
+ }
}
else
{
@@ -2252,9 +2255,6 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
&name))))
return; // fatal_error is set
}
- else if (type() == FUNC_ITEM &&
- ((Item_func *) this)->with_window_func)
- return;
else
{
if (!(item_ref= (new (thd->mem_root)
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 0afbd875ac2..73e45d4f108 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -2313,11 +2313,6 @@ public:
Item_func_isnull(THD *thd, Item *a): Item_func_null_predicate(thd, a) {}
longlong val_int();
enum Functype functype() const { return ISNULL_FUNC; }
- void fix_length_and_dec()
- {
- Item_func_null_predicate::fix_length_and_dec();
- update_used_tables();
- }
const char *func_name() const { return "isnull"; }
void print(String *str, enum_query_type query_type);
enum precedence precedence() const { return CMP_PRECEDENCE; }
diff --git a/sql/item_func.cc b/sql/item_func.cc
index c36f177223b..f56ede71b40 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -245,8 +245,9 @@ bool Item_func::check_argument_types_scalar(uint start, uint end) const
is to allow all Item_field() objects to setup pointers to the table fields.
Sets as a side effect the following class variables:
- maybe_null Set if any argument may return NULL
- with_sum_func Set if any of the arguments contains a sum function
+ maybe_null Set if any argument may return NULL
+ with_sum_func Set if any of the arguments contains a sum function
+ with_window_func Set if any of the arguments contain a window function
with_field Set if any of the arguments contains or is a field
used_tables_cache Set to union of the tables used by arguments
@@ -3649,7 +3650,7 @@ longlong Item_master_gtid_wait::val_int()
{
DBUG_ASSERT(fixed == 1);
longlong result= 0;
- String *gtid_pos = args[0]->val_str(&value);
+ String *gtid_pos __attribute__((unused)) = args[0]->val_str(&value);
if (args[0]->null_value)
{
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index a712ca67eef..97be5f15a8d 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -38,8 +38,8 @@
ulonglong Item_sum::ram_limitation(THD *thd)
{
- return MY_MIN(thd->variables.tmp_table_size,
- thd->variables.max_heap_table_size);
+ return MY_MIN(thd->variables.tmp_memory_table_size,
+ thd->variables.max_heap_table_size);
}
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index 1b245342f76..e34a80b7572 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -4214,13 +4214,13 @@ SJ_TMP_TABLE::create_sj_weedout_tmp_table(THD *thd)
field->set_table_name(&table->alias);
}
- if (thd->variables.tmp_table_size == ~ (ulonglong) 0) // No limit
+ if (thd->variables.tmp_memory_table_size == ~ (ulonglong) 0) // No limit
share->max_rows= ~(ha_rows) 0;
else
share->max_rows= (ha_rows) (((share->db_type() == heap_hton) ?
- MY_MIN(thd->variables.tmp_table_size,
- thd->variables.max_heap_table_size) :
- thd->variables.tmp_table_size) /
+ MY_MIN(thd->variables.tmp_memory_table_size,
+ thd->variables.max_heap_table_size) :
+ thd->variables.tmp_memory_table_size) /
share->reclength);
set_if_bigger(share->max_rows,1); // For dummy start options
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index e272a0e4a7f..995debc9f90 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -4806,7 +4806,7 @@ bool open_tables_only_view_structure(THD *thd, TABLE_LIST *table_list,
MYSQL_OPEN_GET_NEW_TABLE |
(can_deadlock ?
MYSQL_OPEN_FAIL_ON_MDL_CONFLICT : 0)),
- DT_PREPARE | DT_CREATE));
+ DT_INIT | DT_PREPARE | DT_CREATE));
/*
Restore old value of sql_command back as it is being looked at in
process_table() function.
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 79097d818a4..eab078fe62d 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -521,7 +521,8 @@ typedef struct system_variables
uint dynamic_variables_size; /* how many bytes are in use */
ulonglong max_heap_table_size;
- ulonglong tmp_table_size;
+ ulonglong tmp_memory_table_size;
+ ulonglong tmp_disk_table_size;
ulonglong long_query_time;
ulonglong max_statement_time;
ulonglong optimizer_switch;
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 4d7a3d81bd6..37d70bdc7ba 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1576,7 +1576,7 @@ static int mysql_test_select(Prepared_statement *stmt,
}
if (open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL,
- DT_PREPARE | DT_CREATE))
+ DT_INIT | DT_PREPARE | DT_CREATE))
goto error;
thd->lex->used_tables= 0; // Updated by setup_fields
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 8e977334593..656dd66506c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -16681,7 +16681,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
if (blob_count || using_unique_constraint
|| (thd->variables.big_tables && !(select_options & SELECT_SMALL_RESULT))
|| (select_options & TMP_TABLE_FORCE_MYISAM)
- || thd->variables.tmp_table_size == 0)
+ || thd->variables.tmp_memory_table_size == 0)
{
share->db_plugin= ha_lock_engine(0, TMP_ENGINE_HTON);
table->file= get_new_handler(share, &table->mem_root,
@@ -16845,14 +16845,14 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
param->recinfo= recinfo; // Pointer to after last field
store_record(table,s->default_values); // Make empty default record
- if (thd->variables.tmp_table_size == ~ (ulonglong) 0) // No limit
+ if (thd->variables.tmp_memory_table_size == ~ (ulonglong) 0) // No limit
share->max_rows= ~(ha_rows) 0;
else
share->max_rows= (ha_rows) (((share->db_type() == heap_hton) ?
- MY_MIN(thd->variables.tmp_table_size,
+ MY_MIN(thd->variables.tmp_memory_table_size,
thd->variables.max_heap_table_size) :
- thd->variables.tmp_table_size) /
- share->reclength);
+ thd->variables.tmp_memory_table_size) /
+ share->reclength);
set_if_bigger(share->max_rows,1); // For dummy start options
/*
Push the LIMIT clause to the temporary table creation, so that we
@@ -17390,10 +17390,7 @@ bool create_internal_tmp_table(TABLE *table, KEY *keyinfo,
}
}
bzero((char*) &create_info,sizeof(create_info));
-
- /* Use long data format, to ensure we never get a 'table is full' error */
- if (!(options & SELECT_SMALL_RESULT))
- create_info.data_file_length= ~(ulonglong) 0;
+ create_info.data_file_length= table->in_use->variables.tmp_disk_table_size;
/*
The logic for choosing the record format:
@@ -17589,9 +17586,7 @@ bool create_internal_tmp_table(TABLE *table, KEY *keyinfo,
}
MI_CREATE_INFO create_info;
bzero((char*) &create_info,sizeof(create_info));
-
- if (!(options & SELECT_SMALL_RESULT))
- create_info.data_file_length= ~(ulonglong) 0;
+ create_info.data_file_length= table->in_use->variables.tmp_disk_table_size;
if ((error=mi_create(share->table_name.str, share->keys, &keydef,
(uint) (*recinfo-start_recinfo),
@@ -26303,7 +26298,8 @@ AGGR_OP::put_record(bool end_of_records)
{
// Lasy tmp table creation/initialization
if (!join_tab->table->file->inited)
- prepare_tmp_table();
+ if (prepare_tmp_table())
+ return NESTED_LOOP_ERROR;
enum_nested_loop_state rc= (*write_func)(join_tab->join, join_tab,
end_of_records);
return rc;
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index b2ee8a2eef0..dcf8e62dce2 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -1166,7 +1166,7 @@ mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
bool open_error=
open_tables(thd, &table_list, &counter,
MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL) ||
- mysql_handle_derived(thd->lex, DT_PREPARE);
+ mysql_handle_derived(thd->lex, DT_INIT | DT_PREPARE);
thd->pop_internal_handler();
if (open_error && (thd->killed || thd->is_error()))
goto exit;
@@ -1428,7 +1428,7 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
if (open_normal_and_derived_tables(thd, table_list,
MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL,
- DT_PREPARE | DT_CREATE))
+ DT_INIT | DT_PREPARE | DT_CREATE))
DBUG_VOID_RETURN;
table= table_list->table;
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 6558d930e72..e897574f65b 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -3421,12 +3421,30 @@ static Sys_var_tx_read_only Sys_tx_read_only(
static Sys_var_ulonglong Sys_tmp_table_size(
"tmp_table_size",
+ "Alias for tmp_memory_table_size. "
"If an internal in-memory temporary table exceeds this size, MySQL "
- "will automatically convert it to an on-disk MyISAM or Aria table",
- SESSION_VAR(tmp_table_size), CMD_LINE(REQUIRED_ARG),
+ "will automatically convert it to an on-disk MyISAM or Aria table.",
+ SESSION_VAR(tmp_memory_table_size), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(1024, (ulonglong)~(intptr)0), DEFAULT(16*1024*1024),
BLOCK_SIZE(1));
+static Sys_var_ulonglong Sys_tmp_memory_table_size(
+ "tmp_memory_table_size",
+ "If an internal in-memory temporary table exceeds this size, MySQL "
+ "will automatically convert it to an on-disk MyISAM or Aria table. "
+ "Same as tmp_table_size.",
+ SESSION_VAR(tmp_memory_table_size), CMD_LINE(REQUIRED_ARG),
+ VALID_RANGE(1024, (ulonglong)~(intptr)0), DEFAULT(16*1024*1024),
+ BLOCK_SIZE(1));
+
+static Sys_var_ulonglong Sys_tmp_disk_table_size(
+ "tmp_disk_table_size",
+ "Max size for data for an internal temporary on-disk MyISAM or Aria table.",
+ SESSION_VAR(tmp_disk_table_size), CMD_LINE(REQUIRED_ARG),
+ VALID_RANGE(1024, (ulonglong)~(intptr)0),
+ DEFAULT((ulonglong)~(intptr)0),
+ BLOCK_SIZE(1));
+
static Sys_var_mybool Sys_timed_mutexes(
"timed_mutexes",
"Specify whether to time mutexes. Deprecated, has no effect.",
diff --git a/sql/table.cc b/sql/table.cc
index dcfb3edff33..4a1214cbb70 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -8249,8 +8249,12 @@ Item* TABLE_LIST::build_pushable_cond_for_table(THD *thd, Item *cond)
Item *left_item_clone= left_item->build_clone(thd, thd->mem_root);
Item *right_item_clone= item->build_clone(thd, thd->mem_root);
if (left_item_clone && right_item_clone)
+ {
+ left_item_clone->set_item_equal(NULL);
+ right_item_clone->set_item_equal(NULL);
eq= new (thd->mem_root) Item_func_eq(thd, right_item_clone,
left_item_clone);
+ }
if (eq)
{
i++;
diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc
index 0aa5396f35b..87993e0af2b 100644
--- a/sql/temporary_tables.cc
+++ b/sql/temporary_tables.cc
@@ -323,16 +323,6 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
TABLE *table= NULL;
/*
- Since temporary tables are not safe for parallel replication, lets
- wait for the prior commits in case the table is found to be in use.
- */
- if (rgi_slave &&
- rgi_slave->is_parallel_exec &&
- find_temporary_table(tl) &&
- wait_for_prior_commit())
- DBUG_RETURN(true);
-
- /*
Code in open_table() assumes that TABLE_LIST::table can be non-zero only
for pre-opened temporary tables.
*/
@@ -353,6 +343,22 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
}
/*
+ Temporary tables are not safe for parallel replication. They were
+ designed to be visible to one thread only, so have no table locking.
+ Thus there is no protection against two conflicting transactions
+ committing in parallel and things like that.
+
+ So for now, anything that uses temporary tables will be serialised
+ with anything before it, when using parallel replication.
+ */
+
+ if (rgi_slave &&
+ rgi_slave->is_parallel_exec &&
+ find_temporary_table(tl) &&
+ wait_for_prior_commit())
+ DBUG_RETURN(true);
+
+ /*
First check if there is a reusable open table available in the
open table list.
*/
@@ -380,26 +386,6 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
DBUG_RETURN(false);
}
- /*
- Temporary tables are not safe for parallel replication. They were
- designed to be visible to one thread only, so have no table locking.
- Thus there is no protection against two conflicting transactions
- committing in parallel and things like that.
-
- So for now, anything that uses temporary tables will be serialised
- with anything before it, when using parallel replication.
-
- TODO: We might be able to introduce a reference count or something
- on temp tables, and have slave worker threads wait for it to reach
- zero before being allowed to use the temp table. Might not be worth
- it though, as statement-based replication using temporary tables is
- in any case rather fragile.
- */
- if (rgi_slave &&
- rgi_slave->is_parallel_exec &&
- wait_for_prior_commit())
- DBUG_RETURN(true);
-
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (tl->partition_names)
{