sql: crdb_internal.reset_sql_stats() now resets persisted SQL Stats #69273
sql: crdb_internal.reset_sql_stats() now resets persisted SQL Stats #69273craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
c7f73ed to
7a88fb5
Compare
|
Reviewer note: only the last commit is the change. |
e6a2dbf to
4751895
Compare
matthewtodd
left a comment
There was a problem hiding this comment.
Reviewed 1 of 1 files at r1, 28 of 28 files at r2, 3 of 3 files at r3, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @Azhng and @dt)
pkg/sql/sqlstats/persistedsqlstats/compaction_scheduling.go, line 65 at r2 (raw file):
compactionSchedule.SetOwner(security.NodeUserName()) any, err := pbtypes.MarshalAny(&ScheduledSQLStatsCompactorExecutionArgs{})
nit: Maybe call this args or marshalledArgs or something?
pkg/sql/sqlstats/persistedsqlstats/compaction_scheduling.go, line 142 at r2 (raw file):
if err != nil { return exists, err
Would it make sense to use a literal false for this exists value, and the ones below? I'm not sure what idiomatic style is, but this confused me a bit -- I read through the function looking for a line assigning to exists but didn't find it. (I get how it works now, you're relying on the default value of bools being false.)
pkg/sql/sqlstats/persistedsqlstats/compaction_scheduling.go, line 153 at r2 (raw file):
} return tree.MustBeDInt(row[0]) == 1, nil /* err */
I suspect it would be safer / more defensive to say tree.MustBeDInt(row[0]) > 0 here.
Azhng
left a comment
There was a problem hiding this comment.
btw @matthewtodd the PR for the compaction schedule is #68401. This PR rebase off #68401 and the only relevant change the last commit.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @dt and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/compaction_scheduling.go, line 142 at r2 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
Would it make sense to use a literal
falsefor thisexistsvalue, and the ones below? I'm not sure what idiomatic style is, but this confused me a bit -- I read through the function looking for a line assigning toexistsbut didn't find it. (I get how it works now, you're relying on the default value of bools being false.)
Done.
pkg/sql/sqlstats/persistedsqlstats/compaction_scheduling.go, line 153 at r2 (raw file):
Previously, matthewtodd (Matthew Todd) wrote…
I suspect it would be safer / more defensive to say
tree.MustBeDInt(row[0]) > 0here.
Done.
matthewtodd
left a comment
There was a problem hiding this comment.
Oops, sorry. I'm confused by Reviewable & stacked PRs.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @dt and @matthewtodd)
6353d03 to
fa0fca3
Compare
maryliag
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @Azhng and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/controller.go, line 62 at r4 (raw file):
// ResetClusterSQLStats implements the tree.SQLStatsController interface. func (s *Controller) ResetClusterSQLStats(ctx context.Context) error { if err := s.Controller.ResetClusterSQLStats(ctx); err != nil {
is this part handling the in-memory and the remaining the disk? Can you add some comments?
I want to be clear that the reset is clearing both in-memory and on disk
Azhng
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @maryliag and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/controller.go, line 62 at r4 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
is this part handling the in-memory and the remaining the disk? Can you add some comments?
I want to be clear that the reset is clearing both in-memory and on disk
Added comment.
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 42 at r4 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
nit: remove extra space
Done.
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 60 at r4 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
this one is suppose to reset only disk stats? If this one is also resetting in memory, can you create a test that runs a few querys -> flush -> run a few more -> reset
Done.
maryliag
left a comment
There was a problem hiding this comment.
Reviewed 1 of 28 files at r4, 2 of 33 files at r5, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @Azhng and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 60 at r4 (raw file):
Previously, Azhng (Archer Zhang) wrote…
Done.
is it possible to check if the in-memory values are also 0 after the reset?
Azhng
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @maryliag and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 60 at r4 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
is it possible to check if the in-memory values are also 0 after the reset?
Since we are checking crdb_internal views, we are checking both in-memory and persisted stats.
maryliag
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @Azhng and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 60 at r4 (raw file):
Previously, Azhng (Archer Zhang) wrote…
Since we are checking
crdb_internalviews, we are checking both in-memory and persisted stats.
In this case, I would prefer if you have a different count for querys in-memory and disk, and check after that, so:
execute 3 querys -> run flush -> execute 2 querys (or any other number, you can even run the tests 2 other times, so you would have 6 in-memory ) -> check count = 5 (or 9 if running tests twice) -> reset -> check count = 0
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 83 at r7 (raw file):
for _, row := range result { _, found := testCases[row[0]] require.True(t, found, "expect %s to be found, not it was not", row[0])
nit: but it was not (or something like this)
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 106 at r7 (raw file):
for _, row := range result { _, found := testCases[row[0]] require.True(t, found, "expect %s to be found, not it was not", row[0])
nit: but
Azhng
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @maryliag and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 60 at r4 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
In this case, I would prefer if you have a different count for querys in-memory and disk, and check after that, so:
execute 3 querys -> run flush -> execute 2 querys (or any other number, you can even run the tests 2 other times, so you would have 6 in-memory ) -> check count = 5 (or 9 if running tests twice) -> reset -> check count = 0
Updated tests to have different numbers of in-memory stats (3) and persisted stats (4) with overlapping fingerprints.
Also updated the test to instead of check for counts, it perform deep inspection on the statement fingerprints and fingerprint IDs.
maryliag
left a comment
There was a problem hiding this comment.
Just one small nit and make sure the tests are passing, otherwise
Reviewed all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @Azhng and @matthewtodd)
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 60 at r4 (raw file):
Previously, Azhng (Archer Zhang) wrote…
Updated tests to have different numbers of in-memory stats (3) and persisted stats (4) with overlapping fingerprints.
Also updated the test to instead of check for counts, it perform deep inspection on the statement fingerprints and fingerprint IDs.
Great improvement, thanks!
pkg/sql/sqlstats/persistedsqlstats/controller_test.go, line 129 at r9 (raw file):
found = true // Populate fingerprintID
nit: period
885a0f6 to
b4fea5e
Compare
|
@maryliag, found out the cause for the unit test timeout. The culprit is Since the We created a small table so that this executes a lot faster. PTAL |
maryliag
left a comment
There was a problem hiding this comment.
can this cause an issue on production or was the issue just for testing? meaning, if there is a huge number of rows in reset, could we hit the timeout there too?
Reviewed 1 of 33 files at r5, 1 of 1 files at r10, 2 of 2 files at r11, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng and @matthewtodd)
|
I can't imagine anyone in production writing queries like that. It's like doing SELECT * FROM table WHERE crdb_internal.reset_sql_stats()The query in #62587 was randomly generated by SQLSmith (a sort-of random SQL query generator). |
maryliag
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @Azhng, @maryliag, and @matthewtodd)
f94d850 to
d0406b7
Compare
Previously, crdb_internal.reset_sql_stats() builtin only resets cluster-wide in-memory sql stats. This patch updated the builtin to be able to reset persisted sql stats as well. Release justification: category 4 Release note (sql change): crdb_internal.reset_sql_stats() now resets persisted SQL Stats.
|
TFTR! bors r=maryliag |
|
Build failed (retrying...): |
|
Build succeeded: |
Depends on #68401 and #68434
Previously, crdb_internal.reset_sql_stats() builtin only resets
cluster-wide in-memory sql stats.
This patch updated the builtin to be able to reset persisted
sql stats as well.
Release justification: category 4
Release note (sql change): crdb_internal.reset_sql_stats() now resets
persisted SQL Stats.