<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Partitioning on seth-shi</title><link>https://sethix.com/tags/partitioning/</link><description>Recent content in Partitioning on seth-shi</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Fri, 27 Aug 2021 15:46:03 +0800</lastBuildDate><atom:link href="https://sethix.com/tags/partitioning/index.xml" rel="self" type="application/rss+xml"/><item><title>MySQL Partitioning Practice</title><link>https://sethix.com/posts/2021082715/</link><pubDate>Fri, 27 Aug 2021 15:46:03 +0800</pubDate><guid>https://sethix.com/posts/2021082715/</guid><description>While I&amp;rsquo;ve read many related articles before, true understanding comes from practice. Recently, the data team restructured logging formats. I designed a table schema and asked them to write cleaned client logs into it. As this is a video playback statistics table, we implemented date-based partitioning. With less than 100k videos in the library, we opted for monthly partitioning instead of daily. For auto-increment primary key id, you must create composite primary key with partitioning key In our actual implementation, we simply omitted the primary key `id` BIGINT UNSIGNED NOT NULL auto_increment, PRIMARY KEY(`id`, `date_key`) Partition by month Other playback statistics fields are omitted Records before 2021-09-01 will be stored in p_202108 partition Records from 2021-09-01 to 2021-09-30 will go to p_202109 partition CREATE TABLE `video_play_logs` ( `video_id` INT UNSIGNED NOT NULL, `date_key` date NOT NULL, index `video_play_logs_video_id_index` ( `video_id` ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PARTITION BY RANGE(to_days(`date_key`)) ( PARTITION p_202108 VALUES LESS THAN (to_days(&amp;#39;20210901&amp;#39;)), PARTITION p_202109 VALUES LESS THAN (to_days(&amp;#39;20211001&amp;#39;)), PARTITION p_202110 VALUES LESS THAN (to_days(&amp;#39;20211101&amp;#39;)), PARTITION p_202111 VALUES LESS THAN (to_days(&amp;#39;20211201&amp;#39;)), PARTITION p_202112 VALUES LESS THAN (to_days(&amp;#39;20220101&amp;#39;)) ) Verify partition configuration Insert test data and check TABLE_ROWS for record counts in each partition SELECT TABLE_NAME, PARTITION_NAME, TABLE_ROWS FROM information_schema.</description></item></channel></rss>