cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.22k stars 3.82k forks source link

sql: in-memory sql stats should be keyed by fingerprint ID instead of query string #69036

Closed Azhng closed 1 year ago

Azhng commented 3 years ago

Currently, in-memory statement statistics is keyed by a struct. The ordering is currently defined via anonymized query field in that struct. This introduce additional overhead for storage, IO and sorting comparison.

Since we are already computing the statement fingerprint id, for each of the stmtKey and we should use this fingerprint id for the dictionary key. Custom sorting behaviour can be delegated to SQL engine since the stats are also exported in a virtual table.

Jira issue: CRDB-9417

Azhng commented 2 years ago

Thanks for taking a look at this issue @gtr. Though the code and the features have changed quite significantly since the issue has been filed.

The key changes here is that the statement fingerprint ID no longer uniquely identify a statements stats. This is because of the introduction of plan_hash and transaction_fingerprint_id.

This means that, a tuple of (statement fingerprint ID, plan_hash, transaction_fingerprint_id) now uniquely identifies a single statements stats in the ssmemstorage.Container.

The intention of this issue is really to get rid of sampledPlanKey in the map. Since a sampledPlanKey is one-to-one mapped to a statement fingerprint ID.

github-actions[bot] commented 1 year ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!