Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs/design: add the table partition proposal #7969

Merged
merged 7 commits into from
Nov 20, 2018

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Oct 19, 2018

What problem does this PR solve?

Add a table partition design proposal document #7907

@CaitinChen @shenli


This change is Reviewable

@CaitinChen
Copy link
Contributor

OK. I will review it later~

docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
@tiancaiamao
Copy link
Contributor Author

Comment addressed, PTAL, thanks @CaitinChen

docs/design/2018-10-19-table-partition.md Outdated Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Show resolved Hide resolved
docs/design/2018-10-19-table-partition.md Show resolved Hide resolved
@tiancaiamao
Copy link
Contributor Author

PTAL @CaitinChen

Copy link
Contributor

@CaitinChen CaitinChen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tiancaiamao tiancaiamao added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 12, 2018
@tiancaiamao
Copy link
Contributor Author

/run-all-tests
PTAL @shenli

@tiancaiamao
Copy link
Contributor Author

tiancaiamao commented Nov 13, 2018

CI fail, blocked by #8287

@tiancaiamao
Copy link
Contributor Author

/run-all-tests

1 similar comment
@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@tiancaiamao
Copy link
Contributor Author

PTAL @shenli

2 similar comments
@tiancaiamao
Copy link
Contributor Author

PTAL @shenli

@tiancaiamao
Copy link
Contributor Author

PTAL @shenli

@shenli shenli self-requested a review November 19, 2018 02:22
@zz-jason
Copy link
Member

/run-all-tests

@tiancaiamao
Copy link
Contributor Author

PTAL @shenli


## Background

MySQL has the [table partition](https://dev.mysql.com/doc/refman/8.0/en/partitioning.html) feature. If this feature is supported in TiDB, many issues could be addressed. For example, drop ranged partitions could be used to remove old data; partition by hash could address the hot data issue and thus the write performance is improved; query on partitioned tables could be faster than on manual sharding tables because of the partition pruning.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query on partitioned tables could be faster than unpartitioned tables because of the partition pruning.

There are two levels of mapping in TiDB: SQL data to a logical key range, logical key range to the physical storage.
When TiDB maps table data to key-value storage, it first encodes `table id + row id` as key, row data as value. Then the logical key range is split into regions and stored into TiKV.

Table partition works on the first level of mapping, partition ID will be made equivalent of the table ID. A partitioned table row uses `partition id + row id` as encoded key.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention that PartitionID is unique in cluster scope.

select * from p3 where id < 30)
```

During the logical optimization phase, the `DataSource` plan is translated into `UnionAll`, and then each partition generates its own `TableReader` in the physical optimization phase.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataSource plan -> DataSource operator
UnionAll -> UnionAll operator

The drawbacks of this implementation are:

* If the table has many partitions, there will be many readers, and then the `explain` result is not friendly to the user
* The `UnionAll` executor cannot keep the results in order, so if some executor needs ordered results such as `IndexReader`, an extra `Sort` executor is needed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are talking about plan phrase, so there is no executor.


### How to write to the partitioned table

All the write operation calls functions like `table.AddRecord` eventually, so implementing the write operation on a partitioned table simply implements this interface method on the `PartitionedTable` struct.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

singular? or plural?

All the write operation calls

@tiancaiamao
Copy link
Contributor Author

Comment addressed @shenli

@shenli
Copy link
Member

shenli commented Nov 20, 2018

LGTM

@tiancaiamao tiancaiamao merged commit 012cb6d into pingcap:master Nov 20, 2018
@tiancaiamao tiancaiamao deleted the proposal branch November 20, 2018 08:20
lysu added a commit that referenced this pull request Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/docs status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants