forked from docs/doc-exports
Reviewed-by: Wagner, Fabian <fabian.wagner@t-systems.com> Co-authored-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-committed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
50 lines
3.8 KiB
HTML
50 lines
3.8 KiB
HTML
<a name="ddm_10_0014"></a><a name="ddm_10_0014"></a>
|
|
|
|
<h1 class="topictitle1">MM</h1>
|
|
<div id="body1600411218249"><div class="section" id="ddm_10_0014__section15760711132611"><h4 class="sectiontitle">Application Scenarios</h4><p id="ddm_10_0014__p10126155410446">This algorithm applies if you want to shard data by month. One table shard for one month is recommended, and its name is the month number.</p>
|
|
</div>
|
|
<div class="section" id="ddm_10_0014__section1877171510217"><h4 class="sectiontitle">Instructions</h4><ul id="ddm_10_0014__ul17758162314519"><li id="ddm_10_0014__li3758112316453">The sharding key must be DATE, DATETIME, or TIMESTAMP.</li><li id="ddm_10_0014__li3758172313450">This algorithm can be used only for table sharding. It cannot be used for database sharding.</li></ul>
|
|
</div>
|
|
<div class="section" id="ddm_10_0014__section149331275411"><h4 class="sectiontitle">Data Routing</h4><p id="ddm_10_0014__p189364414382">Use the month number in the sharding key value to find the remainder. This remainder determines which table shard your data is routed to and serves as the name suffix of each table shard.</p>
|
|
<p id="ddm_10_0014__p12303131444815">For example, if the sharding key value is <strong id="ddm_10_0014__b07833515314">2019-01-15</strong>, the calculation of the table shard is: Month mod Shards or 1 mod 12 = 1.</p>
|
|
</div>
|
|
<div class="section" id="ddm_10_0014__section1022216812166"><h4 class="sectiontitle">Calculation Method</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ddm_10_0014__table39571721711" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Required calculation methods</caption><thead align="left"><tr id="ddm_10_0014__row209571741719"><th align="left" class="cellrowborder" valign="top" width="16.071607160716074%" id="mcps1.3.4.2.2.4.1.1"><p id="ddm_10_0014__p1173121415175"><strong id="ddm_10_0014__b1180811111505">Condition</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="50.5950595059506%" id="mcps1.3.4.2.2.4.1.2"><p id="ddm_10_0014__p151739144179"><strong id="ddm_10_0014__b1215001141417">Calculation Method</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.4.2.2.4.1.3"><p id="ddm_10_0014__p317314149177"><strong id="ddm_10_0014__b1678715995912">Example</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="ddm_10_0014__row49585712177"><td class="cellrowborder" valign="top" width="16.071607160716074%" headers="mcps1.3.4.2.2.4.1.1 "><p id="ddm_10_0014__p2035318193178">None</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50.5950595059506%" headers="mcps1.3.4.2.2.4.1.2 "><p id="ddm_10_0014__p189715455019">Table routing result = Table sharding key value % Table shards</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.2.2.4.1.3 "><p id="ddm_10_0014__p87551319205111">Sharding key value: 2019-01-15</p>
|
|
<p id="ddm_10_0014__p27551619175118">Table shard: 1 mod 12 = 1</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="ddm_10_0014__section83236412181"><h4 class="sectiontitle">Syntax for Creating Tables</h4><pre class="screen" id="ddm_10_0014__screen202711247162018">create table test_mm_tb (
|
|
id int,
|
|
name varchar(30) DEFAULT NULL,
|
|
create_time datetime DEFAULT NULL,
|
|
primary key(id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
|
dbpartition by MOD_HASH(id)
|
|
tbpartition by MM(create_time) tbpartitions 12;</pre>
|
|
</div>
|
|
<div class="section" id="ddm_10_0014__section121681236151812"><h4 class="sectiontitle">Precautions</h4><p id="ddm_10_0014__p88001652155217">Table shards in each database shard cannot exceed 12 because there are only 12 months a year.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="ddm_10_0018.html">Sharding Algorithms</a></div>
|
|
</div>
|
|
</div>
|
|
|