forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: luhuayi <luhuayi@huawei.com> Co-committed-by: luhuayi <luhuayi@huawei.com>
29 lines
6.3 KiB
HTML
29 lines
6.3 KiB
HTML
<a name="EN-US_TOPIC_0000002136265441"></a><a name="EN-US_TOPIC_0000002136265441"></a>
|
|
|
|
<h1 class="topictitle1">INDEX Object Design (Prioritized)</h1>
|
|
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_section13748110124413"><h4 class="sectiontitle">Rule 2.14: Creating Necessary Indexes and Selecting Optimal Columns and Sequences for Them</h4><div class="note" id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_note35031639202"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_p1692225813502"><strong id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_b141039459610738">Impact of rule violation:</strong></p>
|
|
<ul id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_ul492255815014"><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li13871839449"><p id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_p178719392048"><a name="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li13871839449"></a><a name="en-us_topic_0000002100207558_li13871839449"></a>Redundant indexes consume unnecessary space and can impact data import efficiency.</p>
|
|
</li><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li10922158145018"><p id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_p192255885012"><a name="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li10922158145018"></a><a name="en-us_topic_0000002100207558_li10922158145018"></a>The column sequence in the composite index is incorrect, affecting the query efficiency.</p>
|
|
</li></ul>
|
|
<p id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_p12922115810502"><strong id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_b306188790104323">Best practices:</strong></p>
|
|
<p id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_p15215181222514">The following conditions must be met when indexes are used:</p>
|
|
<ul id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_ul5685312192619"><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li122554537225">The index column should be a column commonly used for filtering or joining conditions.</li></ul>
|
|
<ul id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_ul6922858145014"><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li145931457142618">The index column should have more distinct values.</li><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li17321154105112">When creating a multi-column combination index, prioritize columns with more distinct values.</li><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li658094418614">The number of indexes in a single table should be limited to less than five. You can control the number of indexes by combining them.</li><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li18863194573611">In scenarios where data is added, deleted, or modified in batches, delete the index first and then add it back after the batch operation is complete to improve performance (real-time access may be affected).</li></ul>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_section114813162441"><h4 class="sectiontitle">Suggestion 2.15: Optimizing Performance by Choosing the Right Index Type and Avoiding Indexes for Column-Store Tables</h4><div class="note" id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_note31181444161114"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_p3291449204611"><strong id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_b68026888210738">Impact of rule violation:</strong></p>
|
|
<ul id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_ul13291154984618"><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li52911449154620"><p id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_p1329118491466"><a name="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li52911449154620"></a><a name="en-us_topic_0000002100207558_li52911449154620"></a>Incorrect indexes do not improve column-store access and can negatively affect query performance.</p>
|
|
</li></ul>
|
|
<p id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_p1929111496465"><strong id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_b897927060112626">Solution:</strong></p>
|
|
<ol id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_ol14532193845014"><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li165332038135015">Specify the appropriate index type when creating indexes, avoiding the default psort index.</li><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li14532438135019">In point queries where small amounts of data need to be retrieved from mass datasets, consider using a B-tree index.</li><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li853212381507">For high range query performance, create a partial cluster key (PCK) to quickly filter and scan fact tables using the min/max sparse index. Comply with the following rules to create a PCK:<ul id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_ul57251547191115"><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li115093715491">[Notice] Only one PCK can be created in a table. A PCK can contain multiple columns, preferably no more than two columns.</li><li id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_li65095711494">[Suggestion] Create a PCK for the filter condition column of the expression (e.g., <strong id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_b67410291576">col op const</strong>, where <strong id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_b13828032165719">op</strong> is the operator =, >, >=, <=, and <, and <strong id="EN-US_TOPIC_0000002136265441__en-us_topic_0000002100207558_b15373114075710">const</strong> is a constant value).</li></ul>
|
|
</li></ol>
|
|
</div></div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0104.html">GaussDB(DWS) Object Design Specifications</a></div>
|
|
</div>
|
|
</div>
|
|
|