Commit e77080c7 authored by Sergei Golubchik's avatar Sergei Golubchik

if a table is partitioned by system_time, its partitions are not versioned

they store history and the history does not have history
parent 21d0a9fe
...@@ -21,10 +21,10 @@ select * from t1 for system_time all; ...@@ -21,10 +21,10 @@ select * from t1 for system_time all;
x x
3 3
300 300
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0);
x x
3 3
select * from t1 partition (p1) for system_time all; select * from t1 partition (p1);
x x
300 300
create or replace table t1 (x int) create or replace table t1 (x int)
...@@ -104,9 +104,9 @@ set @now= now(6); ...@@ -104,9 +104,9 @@ set @now= now(6);
insert into t1 values (1); insert into t1 values (1);
set @ts_start= sys_commit_ts('sys_trx_start'); set @ts_start= sys_commit_ts('sys_trx_start');
set @ts_end= sys_commit_ts('sys_trx_end'); set @ts_end= sys_commit_ts('sys_trx_end');
set @str= concat('select x, ', @ts_start, ' < @now as A, ', @ts_end, ' > @now as B from t1 partition (p0) for system_time all'); set @str= concat('select x, ', @ts_start, ' < @now as A, ', @ts_end, ' > @now as B from t1 partition (p0)');
prepare select_p0 from @str; prepare select_p0 from @str;
set @str= concat('select x, ', @ts_start, ' > @now as C, ', @ts_end, ' = timestamp\'2038-01-19 03:14:07.999999\' as D from t1 partition (pn) for system_time all'); set @str= concat('select x, ', @ts_start, ' > @now as C, ', @ts_end, ' = timestamp\'2038-01-19 03:14:07.999999\' as D from t1 partition (pn)');
prepare select_pn from @str; prepare select_pn from @str;
execute select_p0; execute select_p0;
x A B x A B
...@@ -127,7 +127,7 @@ x A B ...@@ -127,7 +127,7 @@ x A B
1 1 1 1 1 1
execute select_pn; execute select_pn;
x C D x C D
set @str= concat('select ', @ts_start, ' from t1 partition (p0) for system_time all into @ts1'); set @str= concat('select ', @ts_start, ' from t1 partition (p0) into @ts1');
prepare stmt from @str; prepare stmt from @str;
execute stmt; execute stmt;
drop prepare stmt; drop prepare stmt;
...@@ -157,11 +157,11 @@ x C D ...@@ -157,11 +157,11 @@ x C D
3 1 1 3 1 1
drop prepare select_p0; drop prepare select_p0;
drop prepare select_pn; drop prepare select_pn;
set @str= concat('select ', @ts_start, ' from t1 partition (p0) for system_time all where x = 2 into @ts1'); set @str= concat('select ', @ts_start, ' from t1 partition (p0) where x = 2 into @ts1');
prepare stmt from @str; prepare stmt from @str;
execute stmt; execute stmt;
drop prepare stmt; drop prepare stmt;
set @str= concat('select ', @ts_end, ' from t1 partition (p0) for system_time all where x = 2 into @ts2'); set @str= concat('select ', @ts_end, ' from t1 partition (p0) where x = 2 into @ts2');
prepare stmt from @str; prepare stmt from @str;
execute stmt; execute stmt;
drop prepare stmt; drop prepare stmt;
...@@ -210,17 +210,17 @@ x ...@@ -210,17 +210,17 @@ x
delete from t1; delete from t1;
Warnings: Warnings:
Note 4116 Versioned table `test`.`t1`: switching from partition `p0` to `p1` Note 4116 Versioned table `test`.`t1`: switching from partition `p0` to `p1`
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0);
x x
1 1
select * from t1 partition (p1) for system_time all; select * from t1 partition (p1);
x x
2 2
insert into t1 values (3); insert into t1 values (3);
delete from t1; delete from t1;
Warnings: Warnings:
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more VERSIONING partitions Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more VERSIONING partitions
select * from t1 partition (p1) for system_time all; select * from t1 partition (p1);
x x
2 2
3 3
...@@ -244,7 +244,7 @@ x ...@@ -244,7 +244,7 @@ x
2 2
3 3
delete from t1; delete from t1;
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0);
x x
1 1
2 2
...@@ -253,7 +253,7 @@ insert into t1 values (4); ...@@ -253,7 +253,7 @@ insert into t1 values (4);
delete from t1; delete from t1;
Warnings: Warnings:
Note 4116 Versioned table `test`.`t1`: switching from partition `p0` to `p1` Note 4116 Versioned table `test`.`t1`: switching from partition `p0` to `p1`
select * from t1 partition (p1) for system_time all; select * from t1 partition (p1);
x x
4 4
create or replace table t1 (x int) create or replace table t1 (x int)
...@@ -276,15 +276,15 @@ delete from t1; ...@@ -276,15 +276,15 @@ delete from t1;
Warnings: Warnings:
Note 4116 Versioned table `test`.`t1`: switching from partition `p0` to `p1` Note 4116 Versioned table `test`.`t1`: switching from partition `p0` to `p1`
Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more VERSIONING partitions Warning 4114 Versioned table `test`.`t1`: partition `p1` is full, add more VERSIONING partitions
select * from t1 partition (p0sp0) for system_time all; select * from t1 partition (p0sp0);
x x
1 1
select * from t1 partition (p0sp1) for system_time all; select * from t1 partition (p0sp1);
x x
select * from t1 partition (p1sp0) for system_time all; select * from t1 partition (p1sp0);
x x
3 3
select * from t1 partition (p1sp1) for system_time all; select * from t1 partition (p1sp1);
x x
2 2
create or replace table t1 (a bigint) create or replace table t1 (a bigint)
......
...@@ -16,8 +16,8 @@ select * from t1 partition (p1); ...@@ -16,8 +16,8 @@ select * from t1 partition (p1);
delete from t1; delete from t1;
select * from t1; select * from t1;
select * from t1 for system_time all; select * from t1 for system_time all;
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0);
select * from t1 partition (p1) for system_time all; select * from t1 partition (p1);
### check server-level partitioning ### check server-level partitioning
...@@ -100,9 +100,9 @@ set @now= now(6); ...@@ -100,9 +100,9 @@ set @now= now(6);
insert into t1 values (1); insert into t1 values (1);
set @ts_start= sys_commit_ts('sys_trx_start'); set @ts_start= sys_commit_ts('sys_trx_start');
set @ts_end= sys_commit_ts('sys_trx_end'); set @ts_end= sys_commit_ts('sys_trx_end');
set @str= concat('select x, ', @ts_start, ' < @now as A, ', @ts_end, ' > @now as B from t1 partition (p0) for system_time all'); set @str= concat('select x, ', @ts_start, ' < @now as A, ', @ts_end, ' > @now as B from t1 partition (p0)');
prepare select_p0 from @str; prepare select_p0 from @str;
set @str= concat('select x, ', @ts_start, ' > @now as C, ', @ts_end, ' = timestamp\'2038-01-19 03:14:07.999999\' as D from t1 partition (pn) for system_time all'); set @str= concat('select x, ', @ts_start, ' > @now as C, ', @ts_end, ' = timestamp\'2038-01-19 03:14:07.999999\' as D from t1 partition (pn)');
prepare select_pn from @str; prepare select_pn from @str;
execute select_p0; execute select_p0;
...@@ -120,7 +120,7 @@ delete from t1; ...@@ -120,7 +120,7 @@ delete from t1;
execute select_p0; execute select_p0;
execute select_pn; execute select_pn;
set @str= concat('select ', @ts_start, ' from t1 partition (p0) for system_time all into @ts1'); set @str= concat('select ', @ts_start, ' from t1 partition (p0) into @ts1');
prepare stmt from @str; execute stmt; drop prepare stmt; prepare stmt from @str; execute stmt; drop prepare stmt;
select @ts0 = @ts1; select @ts0 = @ts1;
...@@ -141,9 +141,9 @@ execute select_pn; ...@@ -141,9 +141,9 @@ execute select_pn;
drop prepare select_p0; drop prepare select_p0;
drop prepare select_pn; drop prepare select_pn;
set @str= concat('select ', @ts_start, ' from t1 partition (p0) for system_time all where x = 2 into @ts1'); set @str= concat('select ', @ts_start, ' from t1 partition (p0) where x = 2 into @ts1');
prepare stmt from @str; execute stmt; drop prepare stmt; prepare stmt from @str; execute stmt; drop prepare stmt;
set @str= concat('select ', @ts_end, ' from t1 partition (p0) for system_time all where x = 2 into @ts2'); set @str= concat('select ', @ts_end, ' from t1 partition (p0) where x = 2 into @ts2');
prepare stmt from @str; execute stmt; drop prepare stmt; prepare stmt from @str; execute stmt; drop prepare stmt;
set @str= concat('select ', @ts_start, ' from t1 partition (pn) into @ts3'); set @str= concat('select ', @ts_start, ' from t1 partition (pn) into @ts3');
prepare stmt from @str; execute stmt; drop prepare stmt; prepare stmt from @str; execute stmt; drop prepare stmt;
...@@ -176,12 +176,12 @@ alter table t1 drop partition non_existent; ...@@ -176,12 +176,12 @@ alter table t1 drop partition non_existent;
insert into t1 values (1), (2); insert into t1 values (1), (2);
select * from t1 partition (pn); select * from t1 partition (pn);
delete from t1; delete from t1;
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0);
select * from t1 partition (p1) for system_time all; select * from t1 partition (p1);
insert into t1 values (3); insert into t1 values (3);
delete from t1; delete from t1;
select * from t1 partition (p1) for system_time all; select * from t1 partition (p1);
# rotation by INTERVAL # rotation by INTERVAL
--error ER_PART_WRONG_VALUE --error ER_PART_WRONG_VALUE
...@@ -202,12 +202,12 @@ partition by system_time interval 1 second ( ...@@ -202,12 +202,12 @@ partition by system_time interval 1 second (
insert into t1 values (1), (2), (3); insert into t1 values (1), (2), (3);
select * from t1 partition (pn); select * from t1 partition (pn);
delete from t1; delete from t1;
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0);
--sleep 2 --sleep 2
insert into t1 values (4); insert into t1 values (4);
delete from t1; delete from t1;
select * from t1 partition (p1) for system_time all; select * from t1 partition (p1);
# Subpartitions # Subpartitions
create or replace table t1 (x int) create or replace table t1 (x int)
...@@ -224,10 +224,10 @@ select * from t1 partition (pnsp0); ...@@ -224,10 +224,10 @@ select * from t1 partition (pnsp0);
select * from t1 partition (pnsp1); select * from t1 partition (pnsp1);
delete from t1; delete from t1;
select * from t1 partition (p0sp0) for system_time all; select * from t1 partition (p0sp0);
select * from t1 partition (p0sp1) for system_time all; select * from t1 partition (p0sp1);
select * from t1 partition (p1sp0) for system_time all; select * from t1 partition (p1sp0);
select * from t1 partition (p1sp1) for system_time all; select * from t1 partition (p1sp1);
create or replace table t1 (a bigint) create or replace table t1 (a bigint)
with system versioning with system versioning
......
...@@ -824,6 +824,27 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr ...@@ -824,6 +824,27 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr
{ {
vers_select_conds_t &vers_conditions= table->vers_conditions; vers_select_conds_t &vers_conditions= table->vers_conditions;
#ifdef WITH_PARTITION_STORAGE_ENGINE
/*
if the history is stored in partitions, then partitions
themselves are not versioned
*/
if (table->partition_names && table->table->part_info->vers_info)
{
if (vers_conditions)
{
#define PART_VERS_ERR_MSG "%s PARTITION (%s)"
char buf[NAME_LEN*2 + sizeof(PART_VERS_ERR_MSG)];
my_snprintf(buf, sizeof(buf), PART_VERS_ERR_MSG, table->alias,
table->partition_names->head()->c_ptr());
my_error(ER_VERSIONING_REQUIRED, MYF(0), buf);
DBUG_RETURN(-1);
}
else
vers_conditions.init(FOR_SYSTEM_TIME_ALL);
}
#endif
// propagate system_time from nearest outer SELECT_LEX // propagate system_time from nearest outer SELECT_LEX
if (!vers_conditions && outer_slex && vers_import_outer) if (!vers_conditions && outer_slex && vers_import_outer)
{ {
......
...@@ -740,12 +740,8 @@ bool LEX::set_bincmp(CHARSET_INFO *cs, bool bin) ...@@ -740,12 +740,8 @@ bool LEX::set_bincmp(CHARSET_INFO *cs, bool bin)
} while(0) } while(0)
inline void vers_select_conds_t::init( void vers_select_conds_t::init(vers_range_type_t t, vers_range_unit_t u_start,
vers_range_type_t t, Item *s, vers_range_unit_t u_end, Item *e)
vers_range_unit_t u_start= UNIT_AUTO,
Item * s= NULL,
vers_range_unit_t u_end= UNIT_AUTO,
Item * e= NULL)
{ {
type= t; type= t;
unit_start= u_start; unit_start= u_start;
...@@ -755,7 +751,7 @@ inline void vers_select_conds_t::init( ...@@ -755,7 +751,7 @@ inline void vers_select_conds_t::init(
import_outer= from_inner= false; import_outer= from_inner= false;
} }
inline Item *vers_select_conds_t::fix_dec(Item *item) Item *vers_select_conds_t::fix_dec(Item *item)
{ {
if (item && item->decimals == 0 && item->type() == Item::FUNC_ITEM && if (item && item->decimals == 0 && item->type() == Item::FUNC_ITEM &&
((Item_func*)item)->functype() == Item_func::NOW_FUNC) ((Item_func*)item)->functype() == Item_func::NOW_FUNC)
......
...@@ -1873,10 +1873,11 @@ struct vers_select_conds_t ...@@ -1873,10 +1873,11 @@ struct vers_select_conds_t
start= end= NULL; start= end= NULL;
} }
inline Item *fix_dec(Item *item); Item *fix_dec(Item *item);
inline void init( vers_range_type_t t, vers_range_unit_t u_start, void init(vers_range_type_t t, vers_range_unit_t u_start= UNIT_AUTO,
Item * s, vers_range_unit_t u_end, Item * e); Item * s= NULL, vers_range_unit_t u_end= UNIT_AUTO,
Item * e= NULL);
bool init_from_sysvar(THD *thd); bool init_from_sysvar(THD *thd);
......
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