Skip to content

Commit 0f2b7e6

Browse files
committed
sql: add trie tree based workload index recommendations
This commit adds the trie and the logic for getting the workload index recommendations. In addition, it fills the gap between built-in functions and backend implementation for workload index recommendations. The whole process consists of collecting candidates and finding representative indexes. All the index recommendations in the table `system.statement_statistics` (satisfying some time requirement) will be collected as the candidates and then inserted to the trie. The trie is designed for all the indexes of one table. The indexed columns will be regarded as the key to insert into the tree in their original orders. The storing part will be attached to the node after the insertion of indexed columns. The general idea of finding representative indexes is to use all the indexes represented by the leaf nodes. One optimization is to remove the storings that are covered by some leaf nodes. Next, we will push down all the storings attached to the internal nodes to the shallowest leaf nodes (You can find the reasons in RFC). Finally, all the indexes represented by the leaf nodes will be returned. As for the `DROP INDEX`, since we collect all the indexes represented by the leaf nodes (a superset of dropped indexes), so we can directly drop all of them. Release note (sql change): new builtin functions `workload_index_recs()` and `workload_index_recs(timestamptz)`, return workload level index recommendations (columns of string, each string represent an index recommendation) from statement level index recommendations (as candidates) in `system.statement_statistics`. If the timestamptz is given, it will only consider those candidates who is generated after that timestampsz.
1 parent eff0185 commit 0f2b7e6

File tree

10 files changed

+1280
-58
lines changed

10 files changed

+1280
-58
lines changed

docs/generated/sql/functions.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,11 +1386,7 @@ the locality flag on node startup. Returns an error if no region is set.</p>
13861386
</span></td><td>Immutable</td></tr>
13871387
<tr><td><a name="workload_index_recs"></a><code>workload_index_recs() &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns set of index recommendations</p>
13881388
</span></td><td>Immutable</td></tr>
1389-
<tr><td><a name="workload_index_recs"></a><code>workload_index_recs(budget: <a href="string.html">string</a>) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns set of index recommendations</p>
1390-
</span></td><td>Immutable</td></tr>
13911389
<tr><td><a name="workload_index_recs"></a><code>workload_index_recs(timestamptz: <a href="timestamp.html">timestamptz</a>) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns set of index recommendations</p>
1392-
</span></td><td>Immutable</td></tr>
1393-
<tr><td><a name="workload_index_recs"></a><code>workload_index_recs(timestamptz: <a href="timestamp.html">timestamptz</a>, budget: <a href="string.html">string</a>) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns set of index recommendations</p>
13941390
</span></td><td>Immutable</td></tr></tbody>
13951391
</table>
13961392

pkg/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ ALL_TESTS = [
486486
"//pkg/sql/opt/testutils/opttester:opttester_test",
487487
"//pkg/sql/opt/testutils/testcat:testcat_test",
488488
"//pkg/sql/opt/testutils:testutils_test",
489+
"//pkg/sql/opt/workloadindexrec:workloadindexrec_test",
489490
"//pkg/sql/opt/xform:xform_test",
490491
"//pkg/sql/opt:opt_test",
491492
"//pkg/sql/parser:parser_disallowed_imports_test",
@@ -1892,6 +1893,8 @@ GO_TARGETS = [
18921893
"//pkg/sql/opt/testutils/testexpr:testexpr",
18931894
"//pkg/sql/opt/testutils:testutils",
18941895
"//pkg/sql/opt/testutils:testutils_test",
1896+
"//pkg/sql/opt/workloadindexrec:workloadindexrec",
1897+
"//pkg/sql/opt/workloadindexrec:workloadindexrec_test",
18951898
"//pkg/sql/opt/xform:xform",
18961899
"//pkg/sql/opt/xform:xform_test",
18971900
"//pkg/sql/opt:opt",

0 commit comments

Comments
 (0)