2017-02-17 5 views
0

Ich habe Tabelle "Elemente". 18 Millionen Datensätze:Partitionierung von Daten mysql

CREATE TABLE IF NOT EXISTS `items` (
    `id` int(11) NOT NULL AUTO_INCREMENT, 
    `log_id` int(11) NOT NULL, 
    `res_id` int(11) NOT NULL, 
    `link` varchar(255) NOT NULL, 
    `title` text NOT NULL, 
    `content` text NOT NULL, 
    `n_date` varchar(255) NOT NULL, 
    `nd_date` int(11) NOT NULL, 
    `s_date` int(11) NOT NULL, 
    `not_date` date NOT NULL, 
    PRIMARY KEY (`id`), 
    UNIQUE KEY `link_2` (`link`), 
    KEY `log_id` (`log_id`), 
    KEY `res_id` (`res_id`), 
    KEY `now_date` (`not_date`), 
    KEY `sql_index` (`res_id`,`id`,`not_date`) 
) ENGINE=Aria DEFAULT CHARSET=utf8 PAGE_CHECKSUM=0 AUTO_INCREMENT=18382133 ; 

Der Versuch, diese Tabelle ich eine Mini-Kopie davon erstellt partitionieren und Spalte 'not_date' in primären und uniq Tasten sind:

CREATE TABLE IF NOT EXISTS `part_items` (
    `id` int(11) NOT NULL AUTO_INCREMENT, 
    `log_id` int(11) NOT NULL, 
    `res_id` int(11) NOT NULL, 
    `link` varchar(255) NOT NULL, 
    `title` text NOT NULL, 
    `content` text NOT NULL, 
    `n_date` varchar(255) NOT NULL, 
    `nd_date` int(11) NOT NULL, 
    `s_date` int(11) NOT NULL, 
    `not_date` date NOT NULL, 
    PRIMARY KEY (`not_date`,`id`), 
    UNIQUE KEY `link_2` (`not_date`,`link`), 
    KEY `log_id` (`log_id`), 
    KEY `res_id` (`res_id`), 
    KEY `now_date` (`not_date`), 
    KEY `sql_index` (`res_id`,`id`,`not_date`) 
) ENGINE=Aria DEFAULT CHARSET=utf8 PAGE_CHECKSUM=0 
/*!50100 PARTITION BY RANGE (TO_DAYS(not_date)) 
(PARTITION p_1 VALUES LESS THAN (735963) ENGINE = Aria, 
PARTITION p_2 VALUES LESS THAN (736694) ENGINE = Aria) */ AUTO_INCREMENT=18414661 ; 

Dann laufe ich sql_query:

alter table `part_items` PARTITION BY RANGE(TO_DAYS(not_date)) (
PARTITION p_1 VALUES LESS THAN(TO_DAYS('2014-12-31')), 
PARTITION p_2 VALUES LESS THAN(TO_DAYS('2016-12-31')) 
); 

Dann versuche ich Datensätze auszuwählen, die müssen in p_1 und erklären Partitionen zeigen mir, dass die Suche nur in p_1 war. Aber wenn ich Datensätze auswähle, die in p_2 sein müssen, erklären EXPLAIN-Partitionen Full-Scan (p_1, p_2). Was ist falsch in meinem Code? Abfragen:

explain partitions SELECT * FROM `part_items` where content like '%k%' and not_date < '2014-05-12' 

explain partitions SELECT * FROM `part_items` where content like '%k%' and not_date > '2015-01-01' 

Und noch eine Frage: Ist es möglich, Ansichten zu partitionieren? enter image description here

+0

der hinzufügen erkläre bitte die Ausgabe – e4c5

+0

Ich habe bearbeiten Frage, erklären dort Ausgabe – Baurzhan

+0

Kann mir jemand helfen? – Baurzhan

Antwort

0

Wenn PARTITIONing bei einigen Datumsfunktionen funktionieren, besteht die Möglichkeit, dass ein ungültiges Datum angegeben wird. Das würde zu NULL führen; Solche Werte werden in der ersten Partition gespeichert.

Dies ist ein Problem, das viele Entwickler stolperte. Der typische 'Workaround' ist, dass die erste Partition leer ist, so dass der Aufwand, um darin zu suchen, (normalerweise) minimal ist. In Ihrem Fall:

PARTITION p_0 VALUES LESS THAN(0) 

Partitionierung auf weniger als etwa 6 Partitionen ist in der Regel nicht die Mühe wert; Werden Sie weitere Partitionen hinzufügen?

(Caveat:.. Mein Rat kommt aus den Jahren von MyISAM/InnoDB Partitionierung, ich weiß nicht von Aria funktioniert anders Ich vermute, dass Partitionierung meist bei dann unabhängig vom Motor Schicht behandelt)

+0

Rick James, vielen Dank Mach! Hinzufügen der PARTITION p_0 WERTE WENIGER ALS (0) wirklich helfen Sie mir! – Baurzhan