一、what is partitioning the database tables?什么是数据库表分区呢?
就是对数据库表里面的数据,按照一定的方式,进行逻辑上或者物理上分开。
This section discusses how to partition a database to maximize throughput, using the flight reservation casestudy as an example. To partition a table, you choose a column of the table that VoltDB can use to uniquely identify and distribute the rows into partitions.
The goal of partitioning a database table is to ensure that the most frequent transactions on the table execute in the same partition as the data accessed.
总结:
通过对上面文字的理解,知道分区不一定是分在主键上面,但是确实是经常被使用的列上面。分区个人理解就像是一个类一样,将一批有独特的行数据,分配到一片区域上面,而不只是一行数据。分区的目的是每一个数据库执行事务都在同一片区域上面进行。
We call this a single-partitioned transaction. Thus the stored procedure must uniquely identify a row by the partitioning column value. This is particularly important for queries that modify the data, such as INSERT, UPDATE,and DELETE statements.
二、分表的原则
4.4.3. Design Rules for Partitioning Tables
The following are the rules to keep in mind when choosing a column by which to partition table rows: • There can be only one partition column per table. If you need to partition a table on two columns(for example first and last name), add an additional column (fullname) that combines the values of the two columns and use this new column to partition the table.每一张表只有一个分区并且只分在一列上面。
• If the table has a primary key, the partitioning column must be included in the primary key.如果一张表有主键,那么分区列一定要分在主键上面。
• Any integer or string column can identify the partition. VoltDB can partition rows on any column that is an integer (TINYINT, SMALLINT, INTEGER, or BIGINT) or string (VARCHAR) datatype. (See also Table A.1, “Supported SQL Datatypes”.)不过表的字段类型是什么类型,都可以作为分区。
• Partition column values cannot be null. The partition columns do not need to have unique values, but you must specify NOT NULL in the schema for the partition column. Numeric fields can be zero and string or character fields can be empty, but the column cannot contain a null value.分区的列不能为空。
其它的一些建议。
The following are some additional recommendations: • Choose a column with a reasonable distribution of values so that rows of data will be evenly partitioned. • Choose a column that maximizes use of single-partitioned stored procedures. If one procedure uses column A to lookup data and two procedures use column B to lookup data, partition on column B. The goal of partitioning is to make the most frequent transactions single-partitioned. • If you partition more than one table on the same column attribute, VoltDB will partition them together.2.1关于是否复制表
对于一些常用的 read次数 比较多的表,最好让其在每个节点都能够复制一份。在VoltDB里面,不显示分区,就会默认复制。
Specifying Replicated Tables
In VoltDB, you do not explicitly state that a table is replicated. If you do not specify a partitioning column in the database schema, the table will by default be replicated. So, in our flight reservation example, there is no explicit action required to replicate the Flight table. However, it is very important to specify partitioning information for tables that you want to partition. If not, they will be replicated by default, significantly changing the performance characteristics of your application.