Skip to content

Commit

Permalink
sql: add trie tree based workload index recommendations
Browse files Browse the repository at this point in the history
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 use the 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: None
  • Loading branch information
qiyanghe1998 committed Jul 20, 2023
1 parent 6bf494c commit d16e6ac
Show file tree
Hide file tree
Showing 7 changed files with 789 additions and 23 deletions.
2 changes: 2 additions & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,7 @@ GO_TARGETS = [
"//pkg/sql/opt/testutils/testexpr:testexpr",
"//pkg/sql/opt/testutils:testutils",
"//pkg/sql/opt/testutils:testutils_test",
"//pkg/sql/opt/workloadindexrec:workloadindexrec",
"//pkg/sql/opt/xform:xform",
"//pkg/sql/opt/xform:xform_test",
"//pkg/sql/opt:opt",
Expand Down Expand Up @@ -3107,6 +3108,7 @@ GET_X_DATA_TARGETS = [
"//pkg/sql/opt/testutils/opttester:get_x_data",
"//pkg/sql/opt/testutils/testcat:get_x_data",
"//pkg/sql/opt/testutils/testexpr:get_x_data",
"//pkg/sql/opt/workloadindexrec:get_x_data",
"//pkg/sql/opt/xform:get_x_data",
"//pkg/sql/optionalnodeliveness:get_x_data",
"//pkg/sql/paramparse:get_x_data",
Expand Down
Loading

0 comments on commit d16e6ac

Please sign in to comment.