Skip to content
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 query level stats to EXPLAIN ANALYZE #60641

Merged
merged 1 commit into from Feb 18, 2021

Conversation

RaduBerinde
Copy link
Member

This change adds top-level query stats to the EXPLAIN ANALYZE output.

Release note (sql change): EXPLAIN ANALYZE now shows more top-level
query statistics.

@RaduBerinde RaduBerinde requested a review from a team as a code owner February 16, 2021 23:20
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@RaduBerinde
Copy link
Member Author

I am unsure of the max-memory and network usage stats. Do we think these are currently robust enough to be useful? I could hide them behind the VERBOSE flag if not.

@awoods187
Copy link
Contributor

awoods187 commented Feb 16, 2021

Could you post some examples for the issue?

I am unsure of the max-memory and network usage stats. Do we think these are currently robust enough to be useful?

I'd vote in favor of adding them to Explain Analyze.

@RaduBerinde
Copy link
Member Author

Example:

demo@127.0.0.1:26257/movr> EXPLAIN ANALYZE SELECT * FROM rides JOIN vehicles ON rides.vehicle_id
= vehicles.id; 
                    info
--------------------------------------------
  planning time: 530µs
  execution time: 5ms
  distribution: full
  vectorized: true
  rows read from KV: 515 (89 KiB)
  cumulative time spent in KV: 3ms
  maximum memory usage: 566 KiB
  network usage: 0 B (0 messages)

  • hash join
  │ actual row count: 500
  │ equality: (vehicle_id) = (id)
  │
  ├── • scan
  │     actual row count: 500
  │     KV rows read: 500
  │     KV bytes read: 86 KiB
  │     missing stats
  │     table: rides@primary
  │     spans: FULL SCAN
  │
  └── • scan
        actual row count: 15
        KV rows read: 15
        KV bytes read: 2.3 KiB
        missing stats
        table: vehicles@primary
        spans: FULL SCAN

  WARNING: this statement is experimental!
(30 rows)

Time: 6ms total (execution 5ms / network 0ms)

I'd vote in favor of adding them to Explain Analyze.

Any thoughts on whether any of it should be VERBOSE-only?

@awoods187
Copy link
Contributor

I love it! I'd vote to keep them in EXPLAIN ANALYZE and not in a verbose only mode.

@RaduBerinde RaduBerinde force-pushed the more-explain branch 2 times, most recently from 1ac6081 to e4ea2ec Compare February 17, 2021 05:13
Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in agreement with Andy. It might not be useful in some cases but I think it's better to show more than less information (users might not even know there is a verbose mode) and iterate from there if we get negative feedback.

Reviewed 13 of 13 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @RaduBerinde)


pkg/sql/explain_plan.go, line 174 at r1 (raw file):

	if explainPlan == nil {
		return errors.New("no plan")

Is there enough context to understand this error?


pkg/sql/instrumentation.go, line 262 at r1 (raw file):

			stmtStats.mu.Unlock()
		}
		txnStats.Accumulate(queryLevelStats)

I'm not sure we want to call Accumulate outside the block. Might lead to cases where stats don't add up in the DB console (i.e. one statement in a txn has nil stmt stats but what was collected is reflected in the txn stats).


pkg/sql/logictest/testdata/logic_test/explain_analyze, line 39 at r1 (raw file):

distribution: <hidden>
vectorized: <hidden>
rows read from KV: 3 (24 B)

Are the bytes values deterministic?

This change adds top-level query stats to the EXPLAIN ANALYZE output.

Release note (sql change): EXPLAIN ANALYZE now shows more top-level
query statistics.
Copy link
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @asubiotto)


pkg/sql/explain_plan.go, line 174 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

Is there enough context to understand this error?

We are checking at a higher level, this is a "just in case" check (I ran into a NPE while working on this change). In general, no plan means that there was an error during planning. Changed to an AssertionFailedf.


pkg/sql/instrumentation.go, line 262 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

I'm not sure we want to call Accumulate outside the block. Might lead to cases where stats don't add up in the DB console (i.e. one statement in a txn has nil stmt stats but what was collected is reflected in the txn stats).

Done.


pkg/sql/logictest/testdata/logic_test/explain_analyze, line 39 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

Are the bytes values deterministic?

Yeah, 8 per row

Copy link
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @asubiotto)

@craig
Copy link
Contributor

craig bot commented Feb 18, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 18, 2021

Build succeeded:

@craig craig bot merged commit 1953aa1 into cockroachdb:master Feb 18, 2021
@RaduBerinde RaduBerinde deleted the more-explain branch February 24, 2021 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants