Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This style of logging is practical, but you could benefit from using partitioning (and subpartitioning): <a href="http://dev.mysql.com/doc/refman/5.1/en/partitioning.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/partitioning.html</a></p> <p>Since you're storing an activity log, you'll likely have a very large data set over time. Partitioning could be especially useful since you want to look at specific months and years. </p> <p>For example, if the data type for the date column is DATE or DATETIME, you could do something like:</p> <pre><code>PARTITION BY RANGE (MONTH(the_date)) (PARTITION p0 VALUES LESS THAN (0), PARTITION p1 VALUES LESS THAN (1), PARTITION p2 VALUES LESS THAN (2), ...[and so on up to 12]); </code></pre> <p>This will give you partitions for each month of data. Once you test with different partitions, try running your queries with "explain partitions select * from..." and you'll be able to see how the query is executed and which partitions are scanned. The best approach to partitioning likely needs to be tailored around your most common queries. For example, are you mainly looking at the last 30 days of data? Monthly snapshots? Custom date ranges? Those could all have an impact on how the partitions are structured.</p> <p>Taking it a step further, you could have subpartitions in each partition. For this, a hash partition could be used: <a href="http://dev.mysql.com/doc/refman/5.1/en/partitioning-hash.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/partitioning-hash.html</a></p> <p>Your primary key question will be impacted by partitioning as well. The primary key (and any unique keys) in the table must use every column that are used in partitioning.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload