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 full table or index scan count metric #59261

Merged

Conversation

barryhe2000
Copy link
Contributor

Previously, this metric was not available, but is now added so that users can
see when full table scans or full index scans are being used for their queries.

Fixes: #58653

Release note (ui change): User can see time series custom chart in admin ui
for full table or index scans.

@barryhe2000 barryhe2000 requested review from yuzefovich and a team January 21, 2021 19:46
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@barryhe2000 barryhe2000 force-pushed the barryhe_full_table_or_index_scan branch from 2fb51dd to 6b979fd Compare January 21, 2021 20:18
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Nice work! I have some nits, but the code looks good to me in general.

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


pkg/sql/conn_executor.go, line 298 at r1 (raw file):

func makeMetrics(internal bool) Metrics {
	// fullTableIndexScan is only instantiated for non-internal queries

nit: missing period.


pkg/sql/conn_executor_exec.go, line 917 at r1 (raw file):

	flags := planner.curPlan.flags

	// We don't execute the statement if:

nit: this comment should be moved below, to right before returning an error that stops the statement execution.


pkg/sql/exec_util.go, line 478 at r1 (raw file):

	}
	MetaFullTableOrIndexScan = metric.Metadata{
		Name:        "sql.full.table.index.scan.count",

nit: I think I'd use sql.full_index_scan.count ("full table" scan is a "full primary index" scan) or just sql.full_scan.count. Maybe @jordanlewis or @asubiotto have a better suggestion.


pkg/sql/executor_statement_metrics.go, line 143 at r1 (raw file):

	FailureCount *metric.Counter

	// FullTableOrIndexScanCount counts the number of full table or index scans.

nit: I'd mention that it is only for user-initiated queries.

@barryhe2000 barryhe2000 force-pushed the barryhe_full_table_or_index_scan branch from 6b979fd to 3c15c39 Compare January 21, 2021 23:26
@barryhe2000
Copy link
Contributor Author

Fixed the nits that you mentioned @yuzefovich

@asubiotto
Copy link
Contributor

Nice! Did you manage to find a testing strategy for metrics?

@awoods187
Copy link
Contributor

Mind posting a sample output for a workload that we know about--say TPC-C?

@yuzefovich
Copy link
Member

Do we wanna add a dashboard for this metric? I initially thought it wasn't necessary since I assumed that the full table/index scan info is useful only during the debugging, but I'm not sure whether that assumption is correct - it might make sense to have a dashboard for it at the very bottom of SQL dashboard. Thoughts?

@asubiotto
Copy link
Contributor

I'm not convinced it's useful as a SQL dashboard level metric. If everything is well, that graph should flatline at zero, which isn't very interesting. It can currently be accessed through the debug page

@asubiotto
Copy link
Contributor

I think what @awoods187 is saying though, is if we could see the output of this graph (regardless of where it ends up being) for a sample workload.

@barryhe2000
Copy link
Contributor Author

Screen Shot 2021-01-20 at 8 23 45 PM

Metric currently looks something like this

@awoods187
Copy link
Contributor

I actually think we should add this as a chart in the DB Console. Operators often want some measurement of how many scans are occurring at the cluster level--in many cases full table scans are the best option so I wouldn't expect this metric to be zero. I like the way it looks in the custom chart and think we should keep this metric at the bottom of SQL reports.

@asubiotto
Copy link
Contributor

OK. In that case, @barryhe2000 note that you probably want to use a non-negative rate option so the timeseries doesn't show the count since the beginning of time, rather the count in a given time interval.

@barryhe2000 barryhe2000 force-pushed the barryhe_full_table_or_index_scan branch from 3c15c39 to 2bba3cb Compare January 27, 2021 04:10
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

There are now 4 commits in this PR, we should clean that up so that only one commit remains.

Reviewed 5 of 5 files at r5.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @barryhe2000)


pkg/sql/conn_executor.go, line 904 at r5 (raw file):

	// distSQLMetrics contains distributed metrics to be accounted for.
	distSQLMetrics *execinfra.DistSQLMetrics

This is no longer needed.

@barryhe2000 barryhe2000 force-pushed the barryhe_full_table_or_index_scan branch from 4922203 to c12c4d3 Compare January 27, 2021 23:05
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r6.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @barryhe2000)

@barryhe2000 barryhe2000 force-pushed the barryhe_full_table_or_index_scan branch from 2195d3a to 0e35a0f Compare January 27, 2021 23:10
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r7.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)

@barryhe2000 barryhe2000 force-pushed the barryhe_full_table_or_index_scan branch from ef17e1f to a79a8c5 Compare January 28, 2021 02:15
@barryhe2000
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 28, 2021

🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@craig
Copy link
Contributor

craig bot commented Jan 28, 2021

GitHub status checks took too long to complete, so bors is giving up. You can adjust bors configuration to have it wait longer if you like.

@yuzefovich
Copy link
Member

bors r-

Hm, I'm guessing the bors is complaining about the license/cla check.

Also, I see that you added the chart - I think we discussed putting it at the very bottom of the SQL dashboard, and currently it's in the middle.

@barryhe2000
Copy link
Contributor Author

CI was failing a test because the chart wasn't there, I can move it. Is there anything doable about the license/cla check? Not sure why it isn't passing

This new metric allows for users to see a time series of their full table
or index scans in the advanced debug console. This metric is part of
EngineMetrics, so there's a corresponding internal metric that counts
internal full table or index scans from internal engine queries.

Release note (ui change): User can see time series of full table or index
scans in advanced debug console.
@barryhe2000 barryhe2000 force-pushed the barryhe_full_table_or_index_scan branch from a79a8c5 to ac3b3c7 Compare January 28, 2021 21:02
@barryhe2000
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 28, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jan 29, 2021

Build succeeded:

@craig craig bot merged commit 054c618 into cockroachdb:master Jan 29, 2021
@barryhe2000 barryhe2000 deleted the barryhe_full_table_or_index_scan branch January 29, 2021 03:18
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.

sql: add metric for full index/table scans
5 participants