Skip to content

Commit

Permalink
IB, SQL: InnoDB partitioning [closes #118]
Browse files Browse the repository at this point in the history
* native InnoDB partitioning for BY SYSTEM_TIME partitions.
  • Loading branch information
midenok committed Feb 21, 2017
1 parent 9181aa5 commit 3935a9a
Show file tree
Hide file tree
Showing 30 changed files with 6,557 additions and 245 deletions.
527 changes: 527 additions & 0 deletions include/priority_queue.h

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions include/template_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

#ifndef TEMPLATE_UTILS_INCLUDED
#define TEMPLATE_UTILS_INCLUDED

/**
Clears a container, but deletes all objects that the elements point to first.
@tparam Container of pointers.
*/
template<typename Container_type>
void delete_container_pointers(Container_type &container)
{
typename Container_type::iterator it1= container.begin();
typename Container_type::iterator it2= container.end();
for (; it1 != it2; ++it1)
{
delete (*it1);
}
container.clear();
}

/**
Clears a container, but frees all objects that the elements point to first.
@tparam Container of pointers.
*/
template<typename Container_type>
void my_free_container_pointers(Container_type &container)
{
typename Container_type::iterator it1= container.begin();
typename Container_type::iterator it2= container.end();
for (; it1 != it2; ++it1)
{
my_free(*it1);
}
container.clear();
}


/**
Casts from one pointer type, to another, without using
reinterpret_cast or C-style cast:
foo *f; bar *b= pointer_cast<bar*>(f);
This avoids having to do:
foo *f; bar *b= static_cast<b*>(static_cast<void*>(f));
*/
template<typename T>
inline T pointer_cast(void *p)
{
return static_cast<T>(p);
}

template<typename T>
inline const T pointer_cast(const void *p)
{
return static_cast<const T>(p);
}

/**
Casts from one pointer type to another in a type hierarchy.
In debug mode, we verify the cast is indeed legal.
*/
template<typename Target, typename Source>
inline Target down_cast(Source arg)
{
DBUG_ASSERT(NULL != dynamic_cast<Target>(arg));
return static_cast<Target>(arg);
}


/**
Sometimes the compiler insists that types be the same and does not do any
implicit conversion. For example:
Derived1 *a;
Derived2 *b; // Derived1 and 2 are children classes of Base
Base *x= cond ? a : b; // Error, need to force a cast.
Use:
Base *x= cond ? implicit_cast<Base*>(a) : implicit_cast<Base*>(b);
static_cast would work too, but would be less safe (allows any
pointer-to-pointer conversion, not only up-casts).
*/
template<typename To>
inline To implicit_cast(To x) { return x; }

#endif // TEMPLATE_UTILS_INCLUDED
16 changes: 6 additions & 10 deletions mysql-test/suite/versioning/r/partition.result
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
create table t1 (x int)
with system versioning
engine innodb
partition by range columns (x) (
partition p0 values less than (100),
partition p1 values less than (1000));
Expand Down Expand Up @@ -78,14 +77,14 @@ show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL,
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
`sys_trx_start` ${SYS_TRX_TYPE} GENERATED ALWAYS AS ROW START,
`sys_trx_end` ${SYS_TRX_TYPE} GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
) ENGINE=${INNODB_OR_MYISAM} DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME
(PARTITION p0 VERSIONING ENGINE = MyISAM,
PARTITION p1 VERSIONING ENGINE = MyISAM,
PARTITION pn AS OF NOW ENGINE = MyISAM)
(PARTITION p0 VERSIONING ENGINE = ${INNODB_OR_MYISAM},
PARTITION p1 VERSIONING ENGINE = ${INNODB_OR_MYISAM},
PARTITION pn AS OF NOW ENGINE = ${INNODB_OR_MYISAM})
alter table t1 drop partition pn;
ERROR HY000: Wrong parameters for `BY SYSTEM_TIME`: `AS OF NOW` partition can not be dropped
alter table t1 drop partition p1;
Expand All @@ -108,7 +107,6 @@ select * from t1 partition (pn) for system_time all;
x
create or replace table t1 (x int)
with system versioning
engine myisam
partition by system_time limit 1 (
partition p0 versioning,
partition p1 versioning,
Expand Down Expand Up @@ -137,7 +135,6 @@ x
3
create or replace table t1 (x int)
with system versioning
engine myisam
partition by system_time interval 1 second (
partition p0 versioning,
partition p1 versioning,
Expand All @@ -163,7 +160,6 @@ x
4
create or replace table t1 (x int)
with system versioning
engine myisam
partition by system_time limit 1
subpartition by key (x)
subpartitions 2 (
Expand Down
10 changes: 10 additions & 0 deletions mysql-test/suite/versioning/t/partition.combinations
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[innodb]
innodb
partition
default-storage-engine=innodb

[myisam]
skip-innodb
partition
default-storage-engine=myisam

11 changes: 2 additions & 9 deletions mysql-test/suite/versioning/t/partition.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
--source include/have_innodb.inc
--source include/have_partition.inc

### check InnoDB versioning and conventional partitioning
### check System Versioning and conventional partitioning

create table t1 (x int)
with system versioning
engine innodb
partition by range columns (x) (
partition p0 values less than (100),
partition p1 values less than (1000));
Expand Down Expand Up @@ -78,6 +74,7 @@ alter table t1 add partition (
alter table t1 add partition (
partition p1 versioning);

--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;

--error ER_VERS_WRONG_PARAMS
Expand All @@ -99,7 +96,6 @@ select * from t1 partition (pn) for system_time all;
# rotation by LIMIT
create or replace table t1 (x int)
with system versioning
engine myisam
partition by system_time limit 1 (
partition p0 versioning,
partition p1 versioning,
Expand All @@ -118,7 +114,6 @@ select * from t1 partition (p1) for system_time all;
# rotation by INTERVAL
create or replace table t1 (x int)
with system versioning
engine myisam
partition by system_time interval 1 second (
partition p0 versioning,
partition p1 versioning,
Expand All @@ -137,7 +132,6 @@ select * from t1 partition (p1) for system_time all;
# Subpartitions
create or replace table t1 (x int)
with system versioning
engine myisam
partition by system_time limit 1
subpartition by key (x)
subpartitions 2 (
Expand All @@ -156,4 +150,3 @@ select * from t1 partition (p1sp0) for system_time all;
select * from t1 partition (p1sp1) for system_time all;

drop table t1;

4 changes: 2 additions & 2 deletions sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ SET (SQL_SOURCE
rpl_tblmap.cc sql_binlog.cc event_scheduler.cc event_data_objects.cc
event_queue.cc event_db_repository.cc
sql_tablespace.cc events.cc ../sql-common/my_user.c
partition_info.cc rpl_utility.cc rpl_injector.cc sql_locale.cc
partition_info.cc partitioning/partition_handler.cc rpl_utility.cc rpl_injector.cc sql_locale.cc
rpl_rli.cc rpl_mi.cc sql_servers.cc sql_audit.cc
sql_connect.cc scheduler.cc sql_partition_admin.cc
sql_profile.cc event_parse_data.cc sql_alter.cc
Expand Down Expand Up @@ -162,7 +162,7 @@ IF (CMAKE_SYSTEM_NAME MATCHES "Linux" OR

ENDIF()

MYSQL_ADD_PLUGIN(partition ha_partition.cc STORAGE_ENGINE DEFAULT STATIC_ONLY
MYSQL_ADD_PLUGIN(partition ha_partition.cc partitioning/partition_handler.cc STORAGE_ENGINE DEFAULT STATIC_ONLY
RECOMPILE_FOR_EMBEDDED)

ADD_LIBRARY(sql STATIC ${SQL_SOURCE})
Expand Down
23 changes: 18 additions & 5 deletions sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ static int partition_initialize(void *p)
bool Partition_share::init(uint num_parts)
{
DBUG_ENTER("Partition_share::init");
mysql_mutex_init(key_partition_auto_inc_mutex,
&auto_inc_mutex,
MY_MUTEX_INIT_FAST);
auto_inc_initialized= false;
partition_name_hash_initialized= false;
next_auto_inc_val= 0;
Expand Down Expand Up @@ -1244,12 +1241,12 @@ int ha_partition::handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt,
(modelled after mi_check_print_msg)
TODO: move this into the handler, or rewrite mysql_admin_table.
*/
static bool print_admin_msg(THD* thd, uint len,
bool print_admin_msg(THD* thd, uint len,
const char* msg_type,
const char* db_name, String &table_name,
const char* op_name, const char *fmt, ...)
ATTRIBUTE_FORMAT(printf, 7, 8);
static bool print_admin_msg(THD* thd, uint len,
bool print_admin_msg(THD* thd, uint len,
const char* msg_type,
const char* db_name, String &table_name,
const char* op_name, const char *fmt, ...)
Expand Down Expand Up @@ -5729,6 +5726,22 @@ int ha_partition::index_next_same(uchar *buf, const uchar *key, uint keylen)
}


int ha_partition::index_read_last_map(uchar *buf,
const uchar *key,
key_part_map keypart_map)
{
DBUG_ENTER("ha_partition::index_read_last_map");

m_ordered= true; // Safety measure
end_range= NULL;
m_index_scan_type= partition_index_read_last;
m_start_key.key= key;
m_start_key.keypart_map= keypart_map;
m_start_key.flag= HA_READ_PREFIX_LAST;
DBUG_RETURN(common_index_read(buf, true));
}


/*
Read next record when performing index scan backwards
Expand Down
Loading

0 comments on commit 3935a9a

Please sign in to comment.