doc-exports/docs/ddm/umn/ddm_10_0015.html
Hasko, Vladimir a5cc543164 reverting ddm umn to state before last commit in #613
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>
2024-01-17 13:06:49 +00:00

50 lines
3.7 KiB
HTML

<a name="ddm_10_0015"></a><a name="ddm_10_0015"></a>
<h1 class="topictitle1">DD</h1>
<div id="body1600411218249"><div class="section" id="ddm_10_0015__section15760711132611"><h4 class="sectiontitle">Application Scenarios</h4><p id="ddm_10_0015__p10397733115415">This algorithm applies if you want to shard data by date. One table shard for one day is recommended, and its name is the day number.</p>
</div>
<div class="section" id="ddm_10_0015__section1877171510217"><h4 class="sectiontitle">Instructions</h4><ul id="ddm_10_0015__ul17758162314519"><li id="ddm_10_0015__li3758112316453">The sharding key must be DATE, DATETIME, or TIMESTAMP.</li><li id="ddm_10_0015__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_0015__section149331275411"><h4 class="sectiontitle">Data Routing</h4><p id="ddm_10_0015__p437891923811">Use the day 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 the table shard.</p>
<p id="ddm_10_0015__p943757175514">For example, if the sharding key value is <strong id="ddm_10_0015__b019516142319">2019-01-15</strong>, the calculation of the table shard is: Day number in a month mod Table shards, that is, 15 mod 31 = 15.</p>
</div>
<div class="section" id="ddm_10_0015__section1022216812166"><h4 class="sectiontitle">Calculation Method</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="ddm_10_0015__table39571721711" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Required calculation methods</caption><thead align="left"><tr id="ddm_10_0015__row209571741719"><th align="left" class="cellrowborder" valign="top" width="18%" id="mcps1.3.4.2.2.4.1.1"><p id="ddm_10_0015__p1173121415175"><strong id="ddm_10_0015__b343133380">Condition</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="49%" id="mcps1.3.4.2.2.4.1.2"><p id="ddm_10_0015__p151739144179"><strong id="ddm_10_0015__b286517574168">Calculation Method</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="33%" id="mcps1.3.4.2.2.4.1.3"><p id="ddm_10_0015__p317314149177"><strong id="ddm_10_0015__b135090355812">Example</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="ddm_10_0015__row49585712177"><td class="cellrowborder" valign="top" width="18%" headers="mcps1.3.4.2.2.4.1.1 "><p id="ddm_10_0015__p2035318193178">None</p>
</td>
<td class="cellrowborder" valign="top" width="49%" headers="mcps1.3.4.2.2.4.1.2 "><p id="ddm_10_0015__p189715455019">Table routing result = Table sharding key value % Table shards</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.4.2.2.4.1.3 "><p id="ddm_10_0015__p87551319205111">Sharding key value: 2019-01-15</p>
<p id="ddm_10_0015__p27551619175118">Table shard: 15 mod 31 = 15</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="ddm_10_0015__section83236412181"><h4 class="sectiontitle">Syntax for Creating Tables</h4><pre class="screen" id="ddm_10_0015__screen1337070162210">create table test_dd_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 DD(create_time) tbpartitions 31;</pre>
</div>
<div class="section" id="ddm_10_0015__section121681236151812"><h4 class="sectiontitle">Precautions</h4><p id="ddm_10_0015__p3681143814562">Table shards in each database shard cannot exceed 31 because there are at most 31 days in a month.</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>