Commit df0e1817 authored by Aleksey Midenkov's avatar Aleksey Midenkov Committed by Sergei Golubchik

Vers SQL: partition rotation by INTERVAL fix

Update partition stats on ha_partition::write_row()
parent 45e1c9bb
......@@ -268,31 +268,50 @@ partition p0 history,
partition p1 history,
partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL'
### ha_partition::update_row() check
create or replace table t1 (x int)
with system versioning
partition by system_time interval 1 second (
partition p0 history,
partition p1 history,
partition pn current);
insert into t1 values (1), (2), (3);
insert into t1 values (1), (2), (3), (4);
select * from t1 partition (pn);
x
1
2
3
4
delete from t1 where x < 3;
delete from t1;
select * from t1 partition (p0);
Warnings:
Note 4114 Versioned table `test`.`t1`: switching from partition `p0` to `p1`
select * from t1 partition (p0) order by x;
x
1
2
select * from t1 partition (p1) order by x;
x
3
insert into t1 values (4);
delete from t1;
4
### ha_partition::write_row() check
create or replace table t1 (x int)
with system versioning
partition by system_time interval 1 second (
partition p0 history,
partition p1 history,
partition pn current);
insert into t1 values (1);
update t1 set x= 2;
update t1 set x= 3;
Warnings:
Note 4114 Versioned table `test`.`t1`: switching from partition `p0` to `p1`
select * from t1 partition (p0);
x
1
select * from t1 partition (p1);
x
4
2
## Subpartitions
create or replace table t1 (x int)
with system versioning
......
......@@ -122,7 +122,6 @@ alter table t1 add partition (partition px history);
--echo ## INSERT, UPDATE, DELETE
create or replace table t1 (x int)
with system versioning
partition by system_time (
......@@ -241,6 +240,7 @@ partition by system_time interval 0 second (
partition p1 history,
partition pn current);
--echo ### ha_partition::update_row() check
create or replace table t1 (x int)
with system versioning
partition by system_time interval 1 second (
......@@ -248,14 +248,29 @@ partition by system_time interval 1 second (
partition p1 history,
partition pn current);
insert into t1 values (1), (2), (3);
insert into t1 values (1), (2), (3), (4);
select * from t1 partition (pn);
delete from t1;
select * from t1 partition (p0);
delete from t1 where x < 3;
--sleep 2
insert into t1 values (4);
delete from t1;
select * from t1 partition (p0) order by x;
select * from t1 partition (p1) order by x;
--echo ### ha_partition::write_row() check
create or replace table t1 (x int)
with system versioning
partition by system_time interval 1 second (
partition p0 history,
partition p1 history,
partition pn current);
insert into t1 values (1);
update t1 set x= 2;
sleep 2;
update t1 set x= 3;
select * from t1 partition (p0);
select * from t1 partition (p1);
--echo ## Subpartitions
......
......@@ -4269,6 +4269,10 @@ int ha_partition::write_row(uchar * buf)
if (have_auto_increment && !table->s->next_number_keypart)
set_auto_increment_if_higher(table->next_number_field);
reenable_binlog(thd);
if (m_part_info->part_type == VERSIONING_PARTITION)
m_part_info->vers_update_stats(thd, part_id);
exit:
thd->variables.sql_mode= saved_sql_mode;
table->auto_increment_field_not_null= saved_auto_inc_field_not_null;
......@@ -4378,13 +4382,7 @@ int ha_partition::update_row(const uchar *old_data, const uchar *new_data)
goto exit;
if (m_part_info->part_type == VERSIONING_PARTITION)
{
uint sub_factor= m_part_info->num_subparts ? m_part_info->num_subparts : 1;
DBUG_ASSERT(m_tot_parts == m_part_info->num_parts * sub_factor);
uint lpart_id= new_part_id / sub_factor;
// lpart_id is HISTORY partition because new_part_id != old_part_id
m_part_info->vers_update_stats(thd, lpart_id);
}
m_part_info->vers_update_stats(thd, new_part_id);
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
error= m_file[old_part_id]->ha_delete_row(old_data);
......
......@@ -521,8 +521,9 @@ class partition_info : public Sql_alloc
void vers_update_stats(THD *thd, uint part_id)
{
DBUG_ASSERT(vers_info && vers_info->initialized());
if (part_id < vers_info->now_part->id)
vers_update_stats(thd, get_partition(part_id));
uint lpart_id= num_subparts ? part_id / num_subparts : part_id;
if (lpart_id < vers_info->now_part->id)
vers_update_stats(thd, get_partition(lpart_id));
}
bool vers_update_range_constants(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