MYSQL section excludes full scan table

Back panel: I have 8 million records and I want to speed up the query time, this is my table

    CREATE TABLE vehiclelog3 (
  ID INT(100) NOT NULL AUTO_INCREMENT,

`PNumber` VARCHAR(30) DEFAULT NULL,

  `Date` DATE DEFAULT NULL,

  `Time` TIME DEFAULT NULL,

  `Offset` VARCHAR(45) DEFAULT NULL,

  `Street1` VARCHAR(60) DEFAULT NULL,

  `Street2` VARCHAR(60) DEFAULT NULL,

`City` VARCHAR(60) DEFAULT NULL,

  `Region` VARCHAR(60) DEFAULT NULL,
ect...

  PRIMARY KEY (`ID`,`Date`),
  UNIQUE KEY ID (`ID`,`Date`),
  KEY date (`Date`),
  KEY plate (`PNumber`)
) ENGINE=INNODB
PARTITION BY HASH( MONTH(`Date`) )
   PARTITIONS 12;

My problem is that I want to avoid a full scan to the table, for example if my query looks like

EXPLAIN PARTITIONS Select * from vehiclelog3 where PNumber = "bla" and Date = "2014-01-18"

exit:

 1  SIMPLE       vehiclelog3  p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12  index   (NULL)         PRIMARY  7        (NULL)  3346217  Using where

I just want to scan only the section with this data. Is it possible?

+4
source share
1 answer

SELECT * FROM tableNmae PARTITION (section_name); as taken from http://dev.mysql.com/doc/refman/5.6/en/partitioning-selection.html can be used to limit SELECT to only one section. Therefore, since you know the relationship between the section and the date you are using, this is trivial.

+1

All Articles