First off, your conflating two different things. One is the fact that a SELECT WHERE id = ?
should only search one partition. Something which you mentioned but didn't specify whether it currently works or not (given your table definition, I don't see why it shouldn't).
The second thing, having a SELECT distinct(id)
to only touch the partitioning information, is very different from this. However, if I understand you correctly, you're assuming that one partition only has one kind of id
. That is not how HASH
partitioning works, though. It works similar to a traditional hash-table, by mapping a large key space to a small one, in your case, 100. So each partition will have many possible IDs. Since mysql will not keep track which of the possible IDs are really in one partition all it can do is to scan each partition, do the DISTINCT
, and give back the result. That said, it could to do the DISTINCT
operation on the individual partitions instead of the whole table and it could do this in parallel, however, the explain seems to imply that it will create one big temporary to do the DISTINCT
, likely because this optimization hasn't been implemented yet.