MySQL – Why Not Use Partitioning?

database-designMySQLpartitioning

When would one NOT want to partition a database? (thinking MySQL partitioning)

In my case

  • I'll be starting with a couple millions rows, it should grow from there.
  • Primary key on a character field that serves as the most frequent query restraint (and lookups are frequent – at least a few per second).
  • Primary key would be hashed to serve as the partition key
  • Updates will be made to every row that is pulled in the frequent queries mentioned above
  • Less frequent lookups (against date columns or other) will need to hit all partitions

Even for the last point, doesn't the lookup run in parallel so in all cases, is this a win? What are the downsides to partitioning? Why isn't it something that EVERYONE uses by default, at least when you are looking at a million+ records?

UPDATE – I selected zgguy's answer but note that I added my own answer with the results of my own research including a link to a really good answer on a similar question that was highly useful to me.

Best Answer

There is no silver bullet for performance problems, and partitioning is not one either.

Every partition is essentially a table for itself. Hence queries that are written in a way that allows the database to look for rows in only one partition become faster. Difference can be huge for queries that would need to scan the entire large table, but can restrict themselves to scanning only one partition in the partitioned table. For unique key lookups, difference is much smaller.

However, queries that use index lookups in a way that requires the database to visit all or most of table(index) partitions will run considerably slower.

Parallel execution is a topic for itself. If you run large overnight batches, and have the entire machine to do that single job, then its parallelization is a good thing. However in an OLTP system where the database constantly serves queries from many concurrent users, you don't want one user to take up all the resources.