Splitting or splitting a very large table in mysql

we have a very large table in mysql with 500,000,000 records in it with 100 queries ( SELECT) per second.
This is the diagram:

id (int), 
user_id (int), 
content (text), 
date (datetime)

as up to 90% of requests in the last 6 months. my question is about improving performance. Is it a good idea to separate these records for the last 6 months in another table and SELECT from it, or the split method, to get all the records for the last 6 months.

or if there is a better way ...

EDIT

for example, this is a request.

SELECT content,user_id FROM log
JOIN users ON users.id = log.user_id
WHERE date > DATE_SUB(CURDATE(), INTERVAL 180 DAY)
LIMIT 15

user_id, the date is indexed in the table. Log
There Usersare 2 million users in the table .

Many thanks in advanced form.

+4
1

, .

 SELECT content,user_id 
   FROM log
   JOIN users ON users.id = log.user_id
  WHERE date > DATE_SUB(CURDATE(), INTERVAL 180 DAY)
  LIMIT 15

, .

 SELECT log.content,
        log.user_id 
   FROM log                                  /* one half gigarow table */
   JOIN users ON users.id = log.user_id      /* two megarow table */
  WHERE log.date > DATE_SUB(CURDATE(), INTERVAL 180 DAY)
  LIMIT 15

(, , .)

users ? , , . , ?

 SELECT log.content,
        log.user_id 
   FROM log                                  /* one half gigarow table */
  WHERE log.date > DATE_SUB(CURDATE(), INTERVAL 180 DAY)
  LIMIT 15

, (date,user_id, content). . content TEXT (LOB), (date,user_id) , .

JOIN, , users? , .

. , , , .

http://dev.mysql.com/doc/refman/5.6/en/partitioning-range.html

- DDL

CREATE TABLE LOG (
  id         INT NOT NULL AUTO_INCREMENT,  /*maybe BIGINT? */
  user_id    INT NOT NULL,
  `date`     DATETIME NOT NULL,
  content    TEXT,
  UNIQUE KEY (id, `date`),
  KEY covering (`date`,user_id)
) 
PARTITION BY RANGE COLUMNS(`date`) (
    PARTITION p0 VALUES LESS THAN ('2012-01-01'),
    PARTITION p1 VALUES LESS THAN ('2012-07-01'),
    PARTITION p2 VALUES LESS THAN ('2013-01-01'),
    PARTITION p3 VALUES LESS THAN ('2013-07-01'),
    PARTITION p4 VALUES LESS THAN ('2014-01-01'),
    PARTITION p5 VALUES LESS THAN ('2014-07-01'),
    PARTITION p6 VALUES LESS THAN ('2015-01-01'),
    PARTITION p7 VALUES LESS THAN ('2015-07-01')
);

, UNIQUE KEY . , , .

, 2015 ( p7 ) , , .

   ALTER TABLE `log` 
 ADD PARTITION (PARTITION p8 VALUES LESS THAN ('2016-01-01'))

, , , . .

+2

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


All Articles