-
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: implement IterateStatementStats() for PersistedSQLStats #68675
Conversation
This PR forks off #68555 and cherry picks the change from #68620. So only the last commit is the new addition.
|
e232019
to
d668b7c
Compare
7bf71ea
to
3597047
Compare
3597047
to
c57c032
Compare
Rebased to master to remove the previous two merged commits from the branch. |
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.
Reviewed 7 of 19 files at r2, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Azhng)
pkg/sql/sqlstats/ssprovider.go, line 87 at r2 (raw file):
// IteratorOptions provides the ability to the caller to change how it iterates // the statements and transactions. // TODO(azhng): we want to support pagination/continuation tokens as well as
are this todo no longer valid? was this implemented or dropped?
pkg/sql/sqlstats/persistedsqlstats/combined_iterator.go, line 30 at r2 (raw file):
mem struct { canBeAdvaned bool
nit: Advanced
pkg/sql/sqlstats/persistedsqlstats/combined_iterator.go, line 87 at r2 (raw file):
// If memIter is exhausted, but disk iterator can still move forward. // In this case, we promote the disk.Cur() and unpause the disk iterator if // it is paused and can be advanced.
nit: If memIter is exhausted, but the disk iterator can still move forward,
we promote the disk.Cur() and resume the disk iterator if it was paused.
pkg/sql/sqlstats/persistedsqlstats/combined_iterator.go, line 111 at r2 (raw file):
// If diskIter is exhausted, but mem iterator can still move forward. // In this case, we promote mem.Cur() and unpause mem iterator if it is paused // and can be advanced.
nit: If diskIter is exhausted, but the mem iterator can still move forward,
we promote the mem.Cur() and resume the mem iterator if it was paused.
pkg/sql/sqlstats/persistedsqlstats/combined_iterator.go, line 122 at r2 (raw file):
// Both iterators can be moved forward. Now we check the value of Cur() // for both iterator. We will have few scenarios:
nit: both iterators
nit: have a few
pkg/sql/sqlstats/persistedsqlstats/combined_iterator.go, line 125 at r2 (raw file):
// 1. mem.Cur() < disk.Cur() // this case, we promote mem.Cur() to c.nextToRead. We then pause // the disk iterator and unpause the mem iterator for next iteration.
nit: unpause > resume
nit: you can remove the this case
of all 3 cases, go directly to we promote...
pkg/sql/sqlstats/persistedsqlstats/combined_iterator.go, line 128 at r2 (raw file):
// 2. mem.Cur() == disk.Cur() // this case, we promote both mem.Cur() and disk.Cur() by merging both // stats. We unpause both iterators for next iteration.
nit: unpause > resume
pkg/sql/sqlstats/persistedsqlstats/combined_iterator.go, line 131 at r2 (raw file):
// 3. mem.Cur() > disk.Cur() // this case, we promote disk.Cur() to c.nextToRead. We then pause // mem iterator and unpause disk iterator for next iteration.
nit: unpause > resume
pkg/sql/sqlstats/persistedsqlstats/combined_iterator.go, line 171 at r2 (raw file):
// If and only if all three of the following fields are equal, lhs and rhs // are the same and they should be merged. if lhs.AggregatedTs.Equal(rhs.AggregatedTs) &&
isn't this case already being treated on the following checks? I can imagine this case would not be common, so you're making all other cases do this extra check without the need
pkg/sql/sqlstats/persistedsqlstats/mem_iterator.go, line 40 at r2 (raw file):
} // Cur calls the m.StmtStatsIterator.Cur() but also populates the m.aggregatedTs
nit: ... Cur() and populates
pkg/sql/sqlstats/persistedsqlstats/stmt_reader.go, line 33 at r2 (raw file):
ctx context.Context, options *sqlstats.IteratorOptions, visitor sqlstats.StatementVisitor, ) (err error) { // We override the sorting options since otherwise we need to implement
nit: otherwise we would need
pkg/sql/sqlstats/persistedsqlstats/stmt_reader.go, line 149 at r2 (raw file):
} stats.ID = roachpb.StmtFingerprintID(stmtFingerprintID)
nit: remove this blank line
pkg/sql/sqlstats/persistedsqlstats/stmt_reader.go, line 151 at r2 (raw file):
stats.Key.PlanHash = uint64(tree.MustBeDInt(row[2]))
nit: remove this blank line
c57c032
to
399ae20
Compare
Previously, IterateStatementStats() for PersistedSQLStats was left unimplemented and it defaults to the implementation of SQLStats.IterateStatementStats(). This means calls to IterateStatementStats() on PersistedSQLStats cannot read the statement statistitcs stored in system table. This commit implements the IterateStatementStats() through the new CombinedStmtStatsIterator which enables this method to read both in-memory and persited statement statistics. Release note: None
399ae20
to
08a8eec
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @maryliag)
pkg/sql/sqlstats/ssprovider.go, line 87 at r2 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
are this todo no longer valid? was this implemented or dropped?
I didn't have a specific implementation in mind when I wrote the initial TODOs. My original thought is that the statusServer
API would directly use this interface to handle API calls.
Now that it has become clear that it would be better to let the statusServer
to directly query the crdb_internal
tables because we can directly leverage our entire SQL Engine to do all the filtering/grouping/projection logic instead of redoing them ourselves.
Though, we should still implement the StartTime
and EndTime
fields here to support virtual index. This is so that we can issue a more optimal query against the system table.
pkg/sql/sqlstats/persistedsqlstats/combined_iterator.go, line 171 at r2 (raw file):
Previously, maryliag (Marylia Gutierrez) wrote…
isn't this case already being treated on the following checks? I can imagine this case would not be common, so you're making all other cases do this extra check without the need
Ah good call. Removed this check.
I think this case would be common if we are forced to do premature flushes due to memory pressure.
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.
Reviewed 2 of 19 files at r2, 2 of 5 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @Azhng)
bors r=maryliag |
Build succeeded: |
Follow up to cockroachdb#68675 Release note: None
This commit introduce combined iterator that iterates through both in-memory and persisted transaction statistics. Follow up to cockroachdb#68675 Release note: None
68803: sql: add ON UPDATE syntax r=otan a=pawalt Previously, we did not have parsing implemented for ON UPDATE expressions on columns. This PR adds parsing for ON UPDATE expressions. Release note: None 69013: opt: fix panic in findJoinFilterRange r=mgartner a=mgartner This commit fixes a panic produced in `findJoinFilterRange` when attempting to access the 0-th constraint in an empty constraint set. Fixes #68975 There is no release note because the bug is not present in any releases. Release note: None 69014: jobs: fix test for batch jobs creation, marked as flaky r=ajwerner a=sajjadrizvi Commit #67991 introduced a test that turned out to be flaky. The test runs out of memory sometimes as it creates a very large batch of jobs. This fix disables job adoptions to avoid large memory use. Release note: None Fixes: #68962 69022: sql: implement combined iterator for transaction statistics r=maryliag a=Azhng Follow up to #68675 Release note: None 69031: ccl/backupccl: skip TestBackupRestoreSystemJobsProgress r=otan a=otan Refs: #68571 Reason: flaky test (this is flaking regularly on PRs) Generated by bin/skip-test. Release justification: non-production code changes Release note: None 69034: roachtest/tests/cdc: effectively disable exponential backoff in jobs r=ajwerner a=ajwerner Fixes #68963. Release note: None 69045: bazel: swap order of interfaces in generated mocks in `pkg/roachpb` r=rail a=rickystewart This makes the order match up to what we have in the checked-in generated code, quashing a diff when you `dev build --hoist-generated-code`. Release note: None Co-authored-by: Peyton Walters <[email protected]> Co-authored-by: Marcus Gartner <[email protected]> Co-authored-by: Sajjad Rizvi <[email protected]> Co-authored-by: Azhng <[email protected]> Co-authored-by: Oliver Tan <[email protected]> Co-authored-by: Andrew Werner <[email protected]> Co-authored-by: Ricky Stewart <[email protected]>
68608: go.mod: update to pgx v4.13 r=otan,knz,stevendanna a=rafiss fixes #62840 This also required an update to cockroach-go/v2 to get the crdbpgx transaction retry helper. The majority of changes here are because pgx now requires the context to be passed in always. Other changes: * The way that pgx prepares statements has changed -- to disable automatic prepared statements, the PreferSimpleProtocol setting must be enabled when making the pgxpool. * The `noprepare` setting was removed from `workload`. This functionality is not supported by pgx any more. pgx will either use prepared statements and cache them automatically or use the simple protocol. * sqlproxy tests had to be modified since pgx now has more fallback logic to retry connections when using an sslmode of `prefer` or `allow`. pgx also now tries to resolve `localhost` as the IPv6 address `:::1`, which isn't well-supported by sqlproxy, so IP resolution was disabled for sqlproxy tests. * CHANGEFEED tests had to be changed since `pgx.Conn.Query` now immediately tries fetching the results, which didn't work with the synchronization that was added to TestChangefeedDataTTL. * COPY was fixed to correctly ignore CopyData after encountering an error. Release note: None 68715: sql: introduce crdb_internal.statement_statistics virtual table r=maryliag,ajwerner a=Azhng Depends on #68675 Related to: #64743 This commit introduces crdb_internal.statement_statistics virtual table that exposes both cluster-wide in-memory statement statistics as well as persited statement statistics. This new virtual table will be used to replace crdb_internal.node_statement_statistics virtual table, which only surface node-local in-memory statement statsitics. Release note (sql change): introduced new crdb_internal.statement_statistics virtual table that surfaces both cluster-wide in-memory statement statistics as well as persited statement statistics. 68749: builtins: implement a separate session_user() builtin r=richardjcai a=otan This is needed groundwork to separate current_user and session_user. Refs: #15005 Release note (sql change): Add a session_user() builtin function, which currently returns the same thing as current_user() as we do not implement `SET ROLE`. 68750: parser: SET ROLE syntax preparation r=richardjcai a=otan See commits for details. Refs: #15005 Co-authored-by: Rafi Shamim <[email protected]> Co-authored-by: Azhng <[email protected]> Co-authored-by: Oliver Tan <[email protected]>
Depends on: #68555, #68620
Related to: #64743
Previously, IterateStatementStats() for PersistedSQLStats was
left unimplemented and it defaults to the implementation of
SQLStats.IterateStatementStats(). This means calls to
IterateStatementStats() on PersistedSQLStats cannot read
the statement statistitcs stored in system table.
This commit implements the IterateStatementStats() through
the new CombinedStmtStatsIterator which enables this method
to read both in-memory and persited statement statistics.
Release note: None