Skip to content

Commit

Permalink
IB: partition-wise ha_innopart::rnd_init() [fixes #208]
Browse files Browse the repository at this point in the history
  • Loading branch information
midenok committed Aug 4, 2017
1 parent 5ce6044 commit 53370de
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
10 changes: 10 additions & 0 deletions mysql-test/suite/versioning/r/partition.result
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,21 @@ t1 CREATE TABLE `t1` (
(PARTITION p0 VERSIONING ENGINE = ${INNODB_OR_MYISAM},
PARTITION p1 VERSIONING ENGINE = ${INNODB_OR_MYISAM},
PARTITION pn AS OF NOW ENGINE = ${INNODB_OR_MYISAM})
insert into t1 values (1), (2);
alter table t1 drop partition pn;
ERROR HY000: Wrong partitions consistency for `t1`: must have at least one 'VERSIONING' and exactly one last 'AS OF NOW'
alter table t1 drop partition p1;
alter table t1 drop partition p0;
ERROR HY000: Wrong partitions consistency for `t1`: must have at least one 'VERSIONING' and exactly one last 'AS OF NOW'
select x from t1;
x
1
2
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 versioning,
partition pn as of now);
set @now= now(6);
insert into t1 values (1);
set @ts_start= sys_commit_ts('sys_trx_start');
Expand Down
10 changes: 10 additions & 0 deletions mysql-test/suite/versioning/t/partition.test
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,23 @@ alter table t1 add partition (
--replace_result InnoDB ${INNODB_OR_MYISAM} MyISAM ${INNODB_OR_MYISAM} "bigint(20) unsigned" ${SYS_TRX_TYPE} timestamp(6) ${SYS_TRX_TYPE}
show create table t1;

insert into t1 values (1), (2);

--error ER_VERS_WRONG_PARTS
alter table t1 drop partition pn;
alter table t1 drop partition p1;
--error ER_VERS_WRONG_PARTS
alter table t1 drop partition p0;

select x from t1;

# insert, delete, update
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 versioning,
partition pn as of now);

set @now= now(6);
insert into t1 values (1);
set @ts_start= sys_commit_ts('sys_trx_start');
Expand Down
1 change: 1 addition & 0 deletions sql/partition_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ bool partition_info::vers_scan_min_max(THD *thd, partition_element *part)
for (; part_id < part_id_end; ++part_id)
{
handler *file= table->file->part_handler(part_id); // requires update_partition() for ha_innopart
DBUG_ASSERT(file);
int rc= file->ha_external_lock(thd, F_RDLCK); // requires ha_commit_trans() for ha_innobase
if (rc)
{
Expand Down
1 change: 1 addition & 0 deletions sql/partitioning/partition_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ Partition_helper::Partition_helper(handler *main_handler)
m_part_info(),
m_tot_parts(),
m_last_part(),
m_cur_part(NO_CURRENT_PART_ID),
m_err_rec(),
m_ordered(),
m_ordered_scan_ongoing(),
Expand Down
7 changes: 7 additions & 0 deletions sql/partitioning/partition_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,13 @@ class Partition_helper : public Sql_alloc
/** Total number of partitions. */
uint m_tot_parts;
uint m_last_part; // Last accessed partition.
uint m_cur_part; // Current partition
/* In fact m_cur_part duplicates m_part_spec, but is required due to different
rnd_init() semantics between ha_innopart and ha_partition.
ha_innopart::rnd_init() is table-wise (it has separate *_in_part() methods).
ha_partition::rnd_init() is partition-wise. m_cur_part is used to imitate
partition-wise rnd_init() and should not be merged with m_part_spec because of
different usage scenarios. */
const uchar *m_err_rec; // record which gave error.
bool m_auto_increment_safe_stmt_log_lock;
bool m_auto_increment_lock;
Expand Down
17 changes: 15 additions & 2 deletions storage/innobase/handler/ha_innopart.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ class ha_innopart:
virtual handler* part_handler(uint32 part_id)
{
set_partition(part_id);
m_cur_part = part_id;
return this;
}

Expand Down Expand Up @@ -1095,12 +1096,21 @@ class ha_innopart:
rnd_init(
bool scan)
{
return(Partition_helper::ph_rnd_init(scan));
if (m_cur_part != NO_CURRENT_PART_ID)
{
m_scan_value= scan;
m_part_spec.start_part = m_cur_part;
m_part_spec.end_part = m_cur_part;
return rnd_init_in_part(m_cur_part, scan);
}
else
return(Partition_helper::ph_rnd_init(scan));
}

int
rnd_end()
{
m_cur_part = NO_CURRENT_PART_ID;
return(Partition_helper::ph_rnd_end());
}

Expand Down Expand Up @@ -1411,7 +1421,10 @@ class ha_innopart:
rnd_next(
uchar* record)
{
return(Partition_helper::ph_rnd_next(record));
if (m_cur_part != NO_CURRENT_PART_ID)
return rnd_next_in_part(m_cur_part, record);
else
return(Partition_helper::ph_rnd_next(record));
}

int
Expand Down

0 comments on commit 53370de

Please sign in to comment.