Documentation
¶
Index ¶
Constants ¶
const CostKeyPrefix = "qsort1:"
CostKeyPrefix marks a sort-insensitive cost key. Deliberately not "sha1:" so joining a cost key against a fingerprint column returns empty rather than a false match. Own version digit, independent of GroupingVersion.
const GroupingVersion = 1
GroupingVersion identifies the clustering and fingerprinting rules. Bump it in any change that moves a Fingerprint value or moves a query between clusters.
Variables ¶
This section is empty.
Functions ¶
func CostKey ¶ added in v0.3.2
CostKey groups sort permutations of one statement under a single key for cost attribution. Attribution only: never EXPLAIN it, never use it as a Fingerprint — grouped members differ in sort order, which decides index column order and direction.
Same reshaped tree and fingerprint as Fingerprint, with statement-level ORDER BY dropped, so the key is never finer than Fingerprint. Aggregate and window ORDER BY survive (forEachChild does not reach them); LIMIT/ OFFSET are kept (top-N heapsort vs full sort is a real plan difference). The deparsed text is a hashing input only — its $N positions no longer line up with the fine canonical, so it is never returned or planned.
func Fingerprint ¶
Types ¶
type Cluster ¶
type Cluster struct {
Fingerprint string `json:"fingerprint"`
Canonical string `json:"canonical"`
Members []Query `json:"members"`
TotalCalls int64 `json:"total_calls"`
TotalExecTimeMs float64 `json:"total_exec_time_ms,omitempty"`
MeanExecTimeMs float64 `json:"mean_exec_time_ms,omitempty"`
Rows int64 `json:"rows,omitempty"`
Params []ParamAttribution `json:"params,omitempty"`
Owners map[string]string `json:"owners,omitempty"`
RegresqlMeta map[string]string `json:"regresql_meta,omitempty"`
DynamicTagKeys []DynamicKeyObservation `json:"dynamic_tag_keys,omitempty"`
}
func Group ¶
Group clusters queries by canonical fingerprint. Queries that fail to parse become singleton clusters with empty Fingerprint. Output is sorted by descending TotalExecTimeMs (when any timing is present), otherwise by descending TotalCalls, with Fingerprint as the tiebreaker. Each cluster's Members are sorted by QueryID, then Raw, and Canonical is the normalized form of the first member after that sort.
type DynamicKeyObservation ¶ added in v0.3.0
type ParamAttribution ¶
type Query ¶
type Query struct {
Raw string `json:"raw"`
QueryID int64 `json:"queryid,omitempty"`
Calls int64 `json:"calls,omitempty"`
TotalExecTimeMs float64 `json:"total_exec_time_ms,omitempty"`
MeanExecTimeMs float64 `json:"mean_exec_time_ms,omitempty"`
StddevExecTimeMs float64 `json:"stddev_exec_time_ms,omitempty"`
Rows int64 `json:"rows,omitempty"`
}
type SortProfile ¶ added in v0.3.2
type SortProfile struct {
CostKey string `json:"cost_key"`
DistinctSorts int `json:"distinct_sorts"`
Variants []SortVariant `json:"variants"`
TotalCalls int64 `json:"total_calls"`
TotalExecTimeMs float64 `json:"total_exec_time_ms,omitempty"`
MeanExecTimeMs float64 `json:"mean_exec_time_ms,omitempty"`
Rows int64 `json:"rows,omitempty"`
}
func SortProfiles ¶ added in v0.3.2
func SortProfiles(clusters []Cluster) []SortProfile
SortProfiles groups clusters by CostKey and reports the distinct orderings in each
type SortVariant ¶ added in v0.3.2
type SortVariant struct {
Fingerprint string `json:"fingerprint"`
SortClauses []string `json:"sort_clauses,omitempty"`
Calls int64 `json:"calls,omitempty"`
TotalExecTimeMs float64 `json:"total_exec_time_ms,omitempty"`
MeanExecTimeMs float64 `json:"mean_exec_time_ms,omitempty"`
Rows int64 `json:"rows,omitempty"`
}