-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: add new index_recommendation column #84618
Conversation
8d61191
to
4e70c42
Compare
6ca61fd
to
cdfe661
Compare
1e81a9c
to
259d3f0
Compare
cc2e4c8
to
6ca9d27
Compare
Since I keep rebasing and after a few days get another conflict on cockroach_version and key_string files, I'll wait to get approval on this PR and do the final merge friendly ping @cockroachdb/sql-schema (for schema change), @cockroachdb/sql-queries (for the changes here) and @cockroachdb/sql-observability |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, at this time in the release cycle, avoiding these kinds of merge conflicts is a bit of a lost cause. Just a couple of minor comments on Schema's behalf.
Reviewed 1 of 25 files at r1, 1 of 9 files at r2, 7 of 13 files at r3, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @maryliag and @postamar)
pkg/sql/catalog/systemschema/system.go
line 484 at r3 (raw file):
) STORED, index_recommendations STRING[],
Consider making this NOT NULL DEFAULT (array[]::STRING[]))
instead? This way you avoid having to worry about NULL values altogether, which is always annoying with array types. You wouldn't need to add that function in tree
either.
pkg/upgrade/upgrades/alter_statement_statistics_index_recommendations.go
line 31 at r3 (raw file):
func alterSystemStatementStatisticsAddIndexRecommendations( ctx context.Context, cs clusterversion.ClusterVersion, d upgrade.TenantDeps, _ *jobs.Job, ) error {
It's worth adding a test for this upgrade step, just like the other upgrades. When spinning up your test cluster at version clusterversion.AlterSystemStatementStatisticsAddIndexRecommendations
, do an ALTER TABLE ... DROP COLUMN
to drop the index_recommendations
column from the bootstrapped table to pretend that the table was created when bootstrapping from an earlier binary. Otherwise you're just testing the idempotency of the addIndexRecommendationsCol
statement.
edit: me not use reviewable gud, test is there and lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM on Queries's (Query's?) behalf.
Reviewed 12 of 25 files at r1, 4 of 9 files at r2, 13 of 13 files at r3, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @maryliag)
3180626
to
d93614a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a few minor inconsistencies, not sure how they relate to the current test failures. Otherwise I have nothing to complain about on Schema's behalf.
Reviewed 17 of 17 files at r4, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @maryliag)
pkg/sql/catalog/systemschema/system.go
line 2015 at r4 (raw file):
Hidden: true, }, {Name: "index_recommendations", ID: 12, Type: types.StringArray, Nullable: false},
Doesn't this also need some default expr field set now?
pkg/upgrade/upgrades/alter_statement_statistics_index_recommendations.go
line 25 at r4 (raw file):
const addIndexRecommendationsCol = ` ALTER TABLE system.statement_statistics ADD COLUMN IF NOT EXISTS "index_recommendations" STRING[] DEFAULT (array[]::STRING[]))
Isn't NOT NULL missing here also?
1c047f8
to
d4982d3
Compare
This commit adds a new column index_recommendations STRING[] to: crdb_internal.node_statement_statistics crdb_internal.cluster_statement_statistics system.statement_statistics crdb_internal.statement_statistics Part of cockroachdb#83782 Release note (sql change): Adding new column index_recommendations to crdb_internal.node_statement_statistics, crdb_internal.cluster_statement_statistics, system.statement_statistics and crdb_internal.statement_statistics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mgartner and @postamar)
pkg/sql/catalog/systemschema/system.go
line 484 at r3 (raw file):
Previously, postamar (Marius Posta) wrote…
Consider making this
NOT NULL DEFAULT (array[]::STRING[]))
instead? This way you avoid having to worry about NULL values altogether, which is always annoying with array types. You wouldn't need to add that function intree
either.
Done
pkg/sql/catalog/systemschema/system.go
line 2015 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
Doesn't this also need some default expr field set now?
Done
pkg/upgrade/upgrades/alter_statement_statistics_index_recommendations.go
line 31 at r3 (raw file):
Previously, postamar (Marius Posta) wrote…
It's worth adding a test for this upgrade step, just like the other upgrades. When spinning up your test cluster at version
clusterversion.AlterSystemStatementStatisticsAddIndexRecommendations
, do anALTER TABLE ... DROP COLUMN
to drop theindex_recommendations
column from the bootstrapped table to pretend that the table was created when bootstrapping from an earlier binary. Otherwise you're just testing the idempotency of theaddIndexRecommendationsCol
statement.
Talked offline, the test was already added
pkg/upgrade/upgrades/alter_statement_statistics_index_recommendations.go
line 25 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
Isn't NOT NULL missing here also?
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a small comment, not familiar with the schema changes in pkg/upgrade
, but I imagine other 👀 have taken a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @postamar, and @THardy98)
pkg/sql/sqlstats/persistedsqlstats/flush.go
line 479 at r5 (raw file):
Previously, THardy98 (Thomas Hardy) wrote…
Should we also check for conflict on index recommendations here as well?
Is there a case where we want to insert into an existing stats row if our index recommendations have changed?
the conflict is for the things that shouldn't change from execution to execution, and the index recommendations (like plan, statistics) can change. So you try to insert, if the "key" values already exists, it will returns there was a conflict, so then it will use the update statement, that will update the recommendation column
Ahh okay, makes sense 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
TFTR!! bors r+ |
Build succeeded: |
This commit adds a new column index_recommendations
STRING[] to:
crdb_internal.node_statement_statistics
crdb_internal.cluster_statement_statistics
system.statement_statistics
crdb_internal.statement_statistics
Part of #83782
Release note (sql change): Adding new column index_recommendations
to crdb_internal.node_statement_statistics,
crdb_internal.cluster_statement_statistics, system.statement_statistics
and crdb_internal.statement_statistics