MySQL Partitioning: why it does not accept the corresponding section

          DROP TABLE temp;
          CREATE TABLE `temp` (
         `CallID` bigint(8) unsigned NOT NULL,
         `InfoID` bigint(8) unsigned NOT NULL,
         `CallStartTime` datetime NOT NULL,
         `PartitionID` int(4) unsigned NOT NULL,
         KEY `CallStartTime`(`CallStartTime`)
       ) ENGINE=InnoDB DEFAULT CHARSET=latin1
         PARTITION BY HASH (PartitionID)
          PARTITIONS 366 

I am using EXPLAIN in the sample request. I get the following result:

EXPLAIN PARTITIONS SELECT * FROM temp where PartitionID = 1

or

 EXPLAIN PARTITIONS SELECT * FROM temp where PartitionID = DAYOFYEAR('2013-01-01 10:24:00')

result:

   id   select_type table   partitions  type    possible_keys   key key_len ref rows    Extra
  1         SIMPLE          temp    p1  ALL                 2   Using where

I do not know why it uses the p1 partition. Here the paratiton begins with p0

+2
source share
1 answer

The HASH splitting scheme means that MySQL translates your arbitrary numeric value into the eigenvalue of the hash function. You have identified 366 sections. What do you think will happen if your request:

EXPLAIN PARTITIONS SELECT * FROM temp where PartitionID = 400

Your PartitionID cannot mean in this case the real identifier / name of the section, since there is no 400 section.

, , , MySQL HASHing . , 0 p0, 1 p1 400 34 (== 400-366).

, . , .

, KEY, , , " " HASH .

+1

Source: https://habr.com/ru/post/1537301/


All Articles