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: cluster setting for persisting gateway node ID #88583

Merged
merged 1 commit into from Sep 23, 2022

Conversation

maryliag
Copy link
Contributor

When persisting statement statistics, one of the columns is the gateway node id, but because it needs to be a unique value, users who have a large amount of data are creating a lot of rows on the system.statement_statistics table.
To help decrease the amount of rows, the new cluster setting sql.metrics.statement_details.gateway_node.enabled define if the value on that column should be the gateway node ID or 0. We still display the node ID on the statistics column.

Fixes #88484

Release note (sql change): New cluster setting
sql.metrics.statement_details.gateway_node.enabled that controls if the gateway node ID should be persisted to the system.statement_statistics table as is or as a 0, to decrease cardinality on the table. The node id is still available on the statistics column.

@maryliag maryliag requested a review from a team September 23, 2022 16:33
@maryliag maryliag requested a review from a team as a code owner September 23, 2022 16:33
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@j82w j82w 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 @j82w and @maryliag)


docs/generated/settings/settings.html line 183 at r1 (raw file):

<tr><td><code>sql.metrics.statement_details.dump_to_logs</code></td><td>boolean</td><td><code>false</code></td><td>dump collected statement statistics to node logs when periodically cleared</td></tr>
<tr><td><code>sql.metrics.statement_details.enabled</code></td><td>boolean</td><td><code>true</code></td><td>collect per-statement query statistics</td></tr>
<tr><td><code>sql.metrics.statement_details.gateway_node.enabled</code></td><td>boolean</td><td><code>true</code></td><td>save the gateway node for each statement fingerprint. If false, the value will be stored as 0.</td></tr>

Is 0 a valid node id? Just wondering if it is possible for users to confuse it being disabled and just using 1 node.


pkg/sql/sqlstats/persistedsqlstats/flush.go line 578 at r1 (raw file):

	nodeID := s.GetSQLInstanceID()
	if !sqlstats.GatewayNodeEnabled.Get(&s.cfg.Settings.SV) {

should this just be a function to avoid duplicate code? It will also make sure everywhere uses the same default value.

Copy link
Contributor Author

@maryliag maryliag 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 @j82w)


docs/generated/settings/settings.html line 183 at r1 (raw file):

Previously, j82w wrote…

Is 0 a valid node id? Just wondering if it is possible for users to confuse it being disabled and just using 1 node.

It's not a valid node, it starts at 1. So the 0 should indicate is disabled


pkg/sql/sqlstats/persistedsqlstats/flush.go line 578 at r1 (raw file):

Previously, j82w wrote…

should this just be a function to avoid duplicate code? It will also make sure everywhere uses the same default value.

Good idea! Done

@maryliag maryliag removed the request for review from a team September 23, 2022 17:40
@maryliag maryliag added backport-22.2.x Flags PRs that need to be backported to 22.2. backport-22.1.x 22.1 is EOL backport-21.2.x 21.2 is EOL labels Sep 23, 2022
Copy link
Contributor

@j82w j82w 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 @j82w and @maryliag)


pkg/sql/sqlstats/persistedsqlstats/provider.go line 172 at r2 (raw file):

// GetEnabledSQLInstanceID returns the SQLInstanceID when gateway node is enabled,
// and zero otherwise.
func (s *PersistedSQLStats) GetEnabledSQLInstanceID(gatewayNodeIDEnabled bool) base.SQLInstanceID {

Is there any reason to not just get the config in the function?

// GetEnabledSQLInstanceID returns the SQLInstanceID when gateway node is enabled,
// and zero otherwise.
func (s *PersistedSQLStats) GetEnabledSQLInstanceID() base.SQLInstanceID {
gatewayNodeIDEnabled := sqlstats.GatewayNodeEnabled.Get(&s.cfg.Settings.SV)
if gatewayNodeIDEnabled {
return s.cfg.SQLIDContainer.SQLInstanceID()
}
return 0
}

When persisting statement statistics, one of the columns
is the gateway node id, but because it needs to be a unique value,
users who have a large amount of data are creating a lot of
rows on the system.statement_statistics table.
To help decrease the amount of rows, the new cluster setting
`sql.metrics.statement_details.gateway_node.enabled` define
if the value on that column should be the gateway node ID or 0.
We still display the node ID on the statistics column.

Fixes cockroachdb#88484

Release note (sql change): New cluster setting
`sql.metrics.statement_details.gateway_node.enabled` that controls
if the gateway node ID should be persisted to the `system.statement_statistics`
table as is or as a 0, to decrease cardinality on the table.
The node id is still available on the statistics column.
Copy link
Contributor Author

@maryliag maryliag 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 @j82w)


pkg/sql/sqlstats/persistedsqlstats/provider.go line 172 at r2 (raw file):

Previously, j82w wrote…

Is there any reason to not just get the config in the function?

// GetEnabledSQLInstanceID returns the SQLInstanceID when gateway node is enabled,
// and zero otherwise.
func (s *PersistedSQLStats) GetEnabledSQLInstanceID() base.SQLInstanceID {
gatewayNodeIDEnabled := sqlstats.GatewayNodeEnabled.Get(&s.cfg.Settings.SV)
if gatewayNodeIDEnabled {
return s.cfg.SQLIDContainer.SQLInstanceID()
}
return 0
}

Done.

Copy link
Contributor

@j82w j82w left a comment

Choose a reason for hiding this comment

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

:lgtm:

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

@maryliag
Copy link
Contributor Author

TFTR!
bors r+

@craig
Copy link
Contributor

craig bot commented Sep 23, 2022

Build succeeded:

@craig craig bot merged commit 2fddd36 into cockroachdb:master Sep 23, 2022
@blathers-crl
Copy link

blathers-crl bot commented Sep 23, 2022

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from f49ec12 to blathers/backport-release-21.2-88583: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 21.2.x failed. See errors above.


error creating merge commit from f49ec12 to blathers/backport-release-22.1-88583: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 22.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-21.2.x 21.2 is EOL backport-22.1.x 22.1 is EOL backport-22.2.x Flags PRs that need to be backported to 22.2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create cluster setting for gateway node being stored
3 participants