· 8 years ago · Mar 07, 2018, 12:08 PM
1CREATE TABLE IF NOT EXISTS `items` (
2 `id` int(11) NOT NULL AUTO_INCREMENT,
3 `log_id` int(11) NOT NULL,
4 `res_id` int(11) NOT NULL,
5 `link` varchar(255) NOT NULL,
6 `title` text NOT NULL,
7 `content` text NOT NULL,
8 `n_date` varchar(255) NOT NULL,
9 `nd_date` int(11) NOT NULL,
10 `s_date` int(11) NOT NULL,
11 `not_date` date NOT NULL,
12 PRIMARY KEY (`id`),
13 UNIQUE KEY `link_2` (`link`),
14 KEY `log_id` (`log_id`),
15 KEY `res_id` (`res_id`),
16 KEY `now_date` (`not_date`),
17 KEY `sql_index` (`res_id`,`id`,`not_date`)
18) ENGINE=Aria DEFAULT CHARSET=utf8 PAGE_CHECKSUM=0 AUTO_INCREMENT=18382133 ;
19
20CREATE TABLE IF NOT EXISTS `part_items` (
21 `id` int(11) NOT NULL AUTO_INCREMENT,
22 `log_id` int(11) NOT NULL,
23 `res_id` int(11) NOT NULL,
24 `link` varchar(255) NOT NULL,
25 `title` text NOT NULL,
26 `content` text NOT NULL,
27 `n_date` varchar(255) NOT NULL,
28 `nd_date` int(11) NOT NULL,
29 `s_date` int(11) NOT NULL,
30 `not_date` date NOT NULL,
31 PRIMARY KEY (`not_date`,`id`),
32 UNIQUE KEY `link_2` (`not_date`,`link`),
33 KEY `log_id` (`log_id`),
34 KEY `res_id` (`res_id`),
35 KEY `now_date` (`not_date`),
36 KEY `sql_index` (`res_id`,`id`,`not_date`)
37) ENGINE=Aria DEFAULT CHARSET=utf8 PAGE_CHECKSUM=0
38/*!50100 PARTITION BY RANGE ( TO_DAYS(not_date))
39(PARTITION p_1 VALUES LESS THAN (735963) ENGINE = Aria,
40 PARTITION p_2 VALUES LESS THAN (736694) ENGINE = Aria) */ AUTO_INCREMENT=18414661 ;
41
42alter table `part_items` PARTITION BY RANGE( TO_DAYS(not_date) ) (
43PARTITION p_1 VALUES LESS THAN( TO_DAYS('2014-12-31') ),
44PARTITION p_2 VALUES LESS THAN( TO_DAYS('2016-12-31') )
45);
46
47explain partitions SELECT * FROM `part_items` where content like '%k%' and not_date < '2014-05-12'
48
49explain partitions SELECT * FROM `part_items` where content like '%k%' and not_date > '2015-01-01'
50
51explain partitions
52SELECT * FROM `part_items`
53where not_date > '2015-01-01'
54and content like '%k%'