cockroachdb / cockroachdb/cockroach
sql: improve performance of vtable generators
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Finding the root cause for a hotspot often requires knowing what ranges are being queried by a particular replica. In a cluster with ~2 million ranges, the sequential scans are painfully slow. E.g., below query took nearly 2 minutes to identify the ranges corresponding to a replica in the store identified by `427`,
```
roachprod@localhost:26257/defaultdb> explain analyze SELECT
-> COALESCE(NULLIF(regexp_extract(start_pretty, '^(/[^/]+/[^/]+)'), ''), start_pretty) AS prefix2,
-> count(*) AS ranges
-> FROM crdb_internal.ranges
-> WHERE 427 = ANY (replicas)
-> GROUP BY 1
-> ORDER BY ranges DESC
-> LIMIT 100;
info
-----------------------------------------------------
planning time: 2ms
execution time: 1m40s
distribution: local
vectorized: true
plan type: custom
maximum memory usage: 2.9 MiB
DistSQL network usage: 0 B (0 messages)
regions: us-central1
sql cpu time: 1m15s
isolation level: serializable
priority: normal
quality of service: regular
• top-k
│ sql nodes: n204
│ regions: us-central1
│ actual row count: 18
│ execution time: 37µs
│ estimated max memory allocated: 10 KiB
│ sql cpu time: 37µs
│ order: -count_rows
│ k: 100
│
└── • group (hash)
│ sql nodes: n204
│ regions: us-central1
│ actual row count: 18
│ execution time: 15ms
│ estimated max memory allocated: 700 KiB
│ estimated max sql temp disk usage: 0 B
│ sql cpu time: 15ms
│ group by: prefix2
│
└── • render
│
└── • filter
│ sql nodes: n204
│ regions: us-central1
│ actual row count: 13,196
│ execution time: 1.6s
│ sql cpu time: 1.5s
│ filter: 427 = ANY replicas
│
└── • virtual table
sql nodes: n204
regions: us-central1
actual row count: 2,051,106
execution time: 1m38s
sql cpu time: 1m14s
table: ranges_no_leases@primary
(50 rows)
Time: 100.086s total (execution 100.086s / network 0.001s)
```
Jira issue: CRDB-58225
Contributor guide
Assessment
This issue has not been assessed yet.