sql: add built-in functions for workload level index recommendations#105017
Conversation
0ae3945 to
829f922
Compare
mgartner
left a comment
There was a problem hiding this comment.
It might be better to return a string column with multiple rows, one row for each index recommendation, than an array of strings? What do you think? You can look at set-returning built-ins for inspiration: https://github.com/cockroachdb/cockroach/blob/42634711a5869bad8cde5677176cdec7a8f507d0/pkg/sql/sem/builtins/generator_builtins.go
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @DrewKimball)
1adea4b to
626c990
Compare
|
Yeah, it will be more clear using multiple rows. |
mgartner
left a comment
There was a problem hiding this comment.
Reviewed 2 of 5 files at r2.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @DrewKimball and @qiyanghe1998)
pkg/sql/sem/builtins/generator_builtins_test.go line 86 at r2 (raw file):
require.Equalf(t, false, rows.Next(), "failed test case %d", i+1) } }
It'd be more consistent with the rest of the tests if these were logic tests. Is there a reason not to put them in a logic test like pkg/sql/logictest/testdata/logic_test/workload_recs?
626c990 to
6bf494c
Compare
|
Previously, mgartner (Marcus Gartner) wrote…
You are right. Fixed. |
rytaft
left a comment
There was a problem hiding this comment.
sorry you've been waiting so long for a review! Just a few nits below.
Reviewed 1 of 5 files at r2, 11 of 11 files at r3, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball, @mgartner, and @qiyanghe1998)
-- commits line 24 at r3:
I think this should have a release note, since these functions will be user-facing
pkg/sql/sem/builtins/generator_builtins.go line 285 at r3 (raw file):
tree.ParamTypes{}, types.String, makeWorkloadIndexRecsGeneratorFactory(false, false),
nit: for each of these boolean parameters, we usually add a comment to say what it is. Something like this (here and below):
makeWorkloadIndexRecsGeneratorFactory(false /* hasTs */, false /* hasBgt */),
pkg/sql/sem/builtins/generator_builtins.go line 1121 at r3 (raw file):
// makeWorkloadIndexRecsGeneratorFactory uses the arrayValueGenerator to // return all the index recommendations as an array of strings func makeWorkloadIndexRecsGeneratorFactory(hasTs bool, hasBgt bool) eval.GeneratorOverload {
nit: I'd spell these params out: hasTimestamp and hasBudget. Also update the function comment to mention what these params mean.
pkg/sql/sem/builtins/generator_builtins.go line 1123 at r3 (raw file):
func makeWorkloadIndexRecsGeneratorFactory(hasTs bool, hasBgt bool) eval.GeneratorOverload { return func(_ context.Context, _ *eval.Context, _ tree.Datums) (eval.ValueGenerator, error) { // Invoke the workloadindexrec.FindWorkloadRecs() to get indexRecs, err once it is implemented.
nit: comment should be <= 80 characters wide. you can just wrap the text here.
pkg/sql/logictest/testdata/logic_test/workload_indexrecs line 1 at r3 (raw file):
# get workload index-recs
It would be good to add a comment to the top of this file mentioning that the data returned right now is just dummy data.
Previously, rytaft (Rebecca Taft) wrote…
Should we wait on the release note until they are implemented? They're just stubs in this PR. |
6bf494c to
34f2628
Compare
rytaft
left a comment
There was a problem hiding this comment.
Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @DrewKimball and @mgartner)
Previously, mgartner (Marcus Gartner) wrote…
Should we wait on the release note until they are implemented? They're just stubs in this PR.
Fine with me, as long as we don't forget to add one eventually (I think the docs team usually does some massaging anyway, so it's also fine to add something in both places)
|
bors r+ |
|
Merge conflict. |
34f2628 to
6e2986d
Compare
|
bors r+ |
|
Build failed (retrying...): |
|
Build failed: |
|
I think this PR is missing bors r- |
This commit adds 4 generator built-in functions for workload level index recommendations: workload_index_recs(), workload_index_recs(timestamptz: TimestampTZ), workload_index_recs(budget: string) and workload_index_recs(timestamptz: TimestampTZ, budget: string). The return types of them are all a string column with multiple rows, one row for each index recommendation. The user can issue a command like `select workload_index_recs(...);` and then get the index recommendations for the whole workload. Only those workload after the given timestamptz will be considered for the index recommendations. If there is no timestamptz, all the workload stored in `system.statement_statistics` will be taken into account. As for the budget, it represents the space limit for the recommended indexes, e.g. 42GB, 580MiB. If it is specified, the workload index recommendation engine will prune the size of all the indexes to satisfy the space constraint. A method called workloadindexrec.FindWorkloadRecs() will be implemented to return the array of indexRecs and error message for these 4 generator built-in functions to invoke. Release note: None
6e2986d to
192d241
Compare
|
bors r+ |
|
This PR was included in a batch that timed out, it will be automatically retried |
|
Build failed (retrying...): |
|
Build succeeded: |
sql: add built-in functions for workload level index recommendations
This commit adds 4 generator built-in functions for workload level index
recommendations: workload_index_recs(), workload_index_recs(timestamptz:
TimestampTZ), workload_index_recs(budget: string) and
workload_index_recs(timestamptz: TimestampTZ, budget: string). The return types
of them are all a string column with multiple rows, one row for each index
recommendation. The user can issue a command like
select workload_index_recs(...);and then get the index recommendations for the wholeworkload.
Only those workload after the given timestamptz will be considered for the
index recommendations. If there is no timestamptz, all the workload stored in
system.statement_statisticswill be taken into account. As for the budget, itrepresents the space limit for the recommended indexes, e.g. 42GB, 580MiB. If
it is specified, the workload index recommendation engine will prune the size
of all the indexes to satisfy the space constraint.
A method called workloadindexrec.FindWorkloadRecs() will be implemented to
return the array of indexRecs and error message for these 4 generator built-in
functions to invoke.
Release note: None
Epic: None