Bug #75978 Improve partitioning examples and include primary key information in docs
Submitted: 20 Feb 2015 11:27 Modified: 25 Mar 2015 9:48
Reporter: Simon Mudd (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.1+ OS:Any
Assigned to: Jon Stephens CPU Architecture:Any
Tags: partitioning

[20 Feb 2015 11:27] Simon Mudd
Description:
http://dev.mysql.com/doc/refman/5.6/en/partitioning-hash.html provides examples of partitioning with tables which don't have a primary key defined.

These can be a bit misleading as MySQL has restrictions that partitioning can only be done on columns which are part of the primary key yet no primary key is defined and real-world usage would almost always have an existing table defined with a primary key which you want to further partition.

So the examples look like you can partition where you want but this may not be the case.

How to repeat:
A more real life example on this page might have a primary key in the table.
Yet look what happens when I try to partition it as shown:

root@localhost [test]> alter table employees add primary key (id);
Query OK, 0 rows affected (0.07 sec)
Records: 0  Duplicates: 0  Warnings: 0

root@localhost [test]> alter table employees  PARTITION BY HASH(store_id) partitions 4;
ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function

Even if I try to make the primary key ( id, store_id ) I can't then make the id column unique:

root@localhost [test]> alter table employees drop primary key, add primary key ( id, store_id ), add unique key ( id );
Query OK, 0 rows affected (0.08 sec)
Records: 0  Duplicates: 0  Warnings: 0

root@localhost [test]> alter table employees  PARTITION BY HASH(store_id) partitions 4;
ERROR 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function

Yes, these limitations are documented, but the simple examples don't seem to work with real usage and so can confuse people.

Suggested fix:
If possible please try to ensure the documentation provides good, realistic examples, and to use tables defined with primary keys (most tables should be defined with a primary key) as the base examples of how a table might be further partitioned.

http://dev.mysql.com/doc/refman/5.6/en/partitioning-overview.html 19.1 does have the first paragraph mention restrictions but doesn't even provide a brief summary of what they might be.  This means that most people will probably skip this link (as it goes to section 19.6) as the rest of the page has quite a lot of content.

So yes the documentation is correct but more complete examples will avoid people perhaps thinking they can partition one way when actually they can not.
[20 Feb 2015 13:14] MySQL Verification Team
Thank you for the bug report.
[25 Mar 2015 9:48] Jon Stephens
Re-opened/fixed in mysqldoc rev 42290.

Closed.
[25 Mar 2015 9:51] Jon Stephens
Fixed in all versions of the Manual, 5.1+.