Commit b96e4424 authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-17613 MIN/MAX Optimization (Select tables optimized away) does not work

Current easy fix is not possible, because SELECT clones ha_partition
and then closes the clone which leads to unclosed transaction in
partitions we forcely prune out. We cound solve this by closing these
partitions (and release from transaction) in
change_partitions_to_open() at versioning conditions stage, but this
is problematic because table lock is acquired for each partition at
open stage and therefore must be released when we close partition
handler in change_partitions_to_open(). More details in MDEV-20376.

This should change after MDEV-20250 where mechanism of opening
partitions will be improved.

This reverts commit cdbac54d.
parent 32ec5fb9
...@@ -547,17 +547,6 @@ t1 CREATE TABLE `t1` ( ...@@ -547,17 +547,6 @@ t1 CREATE TABLE `t1` (
create or replace table t1 (f int) with system versioning partition by hash(f); create or replace table t1 (f int) with system versioning partition by hash(f);
insert delayed into t1 values (1); insert delayed into t1 values (1);
# #
# MDEV-17613 MIN/MAX Optimization (Select tables optimized away) does not work
#
create or replace table t1 (pk int primary key) with system versioning
partition by system_time (
partition p1 history,
partition pn current);
insert into t1 values (1), (2);
explain select max(pk) from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
#
# MDEV-20068 History partition rotation is not done under LOCK TABLES # MDEV-20068 History partition rotation is not done under LOCK TABLES
# #
create or replace table t1 (x int) with system versioning partition by system_time limit 1 create or replace table t1 (x int) with system versioning partition by system_time limit 1
......
...@@ -44,7 +44,7 @@ i ...@@ -44,7 +44,7 @@ i
6 6
explain partitions select * from t1; explain partitions select * from t1;
id select_type table partitions type possible_keys key key_len ref rows Extra id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL 2 1 SIMPLE t1 pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL 2 Using where
explain partitions select * from t1 for system_time as of '2001-02-04 10:20:30'; explain partitions select * from t1 for system_time as of '2001-02-04 10:20:30';
id select_type table partitions type possible_keys key key_len ref rows Extra id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1_p1sp0,p1_p1sp1,p0_p0sp0,p0_p0sp1,p2_p2sp0,p2_p2sp1,pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL # Using where 1 SIMPLE t1 p1_p1sp0,p1_p1sp1,p0_p0sp0,p0_p0sp1,p2_p2sp0,p2_p2sp1,pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL # Using where
......
...@@ -497,27 +497,6 @@ create or replace table t1 (f int) with system versioning partition by hash(f); ...@@ -497,27 +497,6 @@ create or replace table t1 (f int) with system versioning partition by hash(f);
--error 0,ER_DELAYED_NOT_SUPPORTED --error 0,ER_DELAYED_NOT_SUPPORTED
insert delayed into t1 values (1); insert delayed into t1 values (1);
--echo #
--echo # MDEV-17613 MIN/MAX Optimization (Select tables optimized away) does not work
--echo #
--disable_query_log
set @saved_storage_engine= @@default_storage_engine;
if ($MTR_COMBINATION_HEAP)
{
# This case does not work with HEAP
set default_storage_engine= myisam;
}
--enable_query_log
create or replace table t1 (pk int primary key) with system versioning
partition by system_time (
partition p1 history,
partition pn current);
insert into t1 values (1), (2);
explain select max(pk) from t1;
--disable_query_log
set default_storage_engine= @saved_storage_engine;
--enable_query_log
--echo # --echo #
--echo # MDEV-20068 History partition rotation is not done under LOCK TABLES --echo # MDEV-20068 History partition rotation is not done under LOCK TABLES
--echo # --echo #
......
...@@ -721,19 +721,6 @@ void vers_select_conds_t::print(String *str, enum_query_type query_type) const ...@@ -721,19 +721,6 @@ void vers_select_conds_t::print(String *str, enum_query_type query_type) const
} }
} }
/**
Setup System Versioning conditions
Add WHERE condition according to FOR SYSTEM_TIME clause.
If the table is partitioned by SYSTEM_TIME and there is no FOR SYSTEM_TIME
clause, then select now-partition instead of modifying WHERE condition.
@retval
-1 on error
@retval
0 on success
*/
int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
{ {
DBUG_ENTER("SELECT_LEX::vers_setup_cond"); DBUG_ENTER("SELECT_LEX::vers_setup_cond");
...@@ -801,13 +788,12 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) ...@@ -801,13 +788,12 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
vers_select_conds_t &vers_conditions= table->vers_conditions; vers_select_conds_t &vers_conditions= table->vers_conditions;
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
Vers_part_info *vers_info; /*
if (table->table->part_info && (vers_info= table->table->part_info->vers_info)) if the history is stored in partitions, then partitions
{ themselves are not versioned
if (table->partition_names) */
if (table->partition_names && table->table->part_info->vers_info)
{ {
/* If the history is stored in partitions, then partitions
themselves are not versioned. */
if (vers_conditions.is_set()) if (vers_conditions.is_set())
{ {
my_error(ER_VERS_QUERY_IN_PARTITION, MYF(0), table->alias.str); my_error(ER_VERS_QUERY_IN_PARTITION, MYF(0), table->alias.str);
...@@ -816,19 +802,6 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) ...@@ -816,19 +802,6 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
else else
vers_conditions.init(SYSTEM_TIME_ALL); vers_conditions.init(SYSTEM_TIME_ALL);
} }
else if (!vers_conditions.is_set() &&
/* We cannot optimize REPLACE .. SELECT because it may need
to call vers_set_hist_part() to update history. */
thd->lex->sql_command != SQLCOM_REPLACE_SELECT)
{
table->partition_names= newx List<String>;
String *s= newx String(vers_info->now_part->partition_name,
system_charset_info);
table->partition_names->push_back(s);
table->table->file->change_partitions_to_open(table->partition_names);
vers_conditions.init(SYSTEM_TIME_ALL);
}
}
#endif #endif
if (outer_table && !vers_conditions.is_set()) if (outer_table && !vers_conditions.is_set())
...@@ -978,7 +951,6 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) ...@@ -978,7 +951,6 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
DBUG_RETURN(0); DBUG_RETURN(0);
#undef newx #undef newx
} }
#undef newx
/***************************************************************************** /*****************************************************************************
Check fields, find best join, do the select and output fields. Check fields, find best join, do the select and output fields.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment