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

Add VEXPLAIN KEYS for improved sharding key selection #16830

Merged
merged 7 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions changelog/21.0/21.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- **[VTGate Tablet Balancer](#tablet-balancer)**
- **[Query Timeout Override](#query-timeout)**
- **[Dynamic VReplication Configuration](#dynamic-vreplication-configuration)**
- **[New VEXPLAIN Modes: TRACE and KEYS](#new-vexplain-modes)**


## <a id="major-changes"/>Major Changes

Expand Down Expand Up @@ -137,3 +139,27 @@ Currently many of the configuration options for VReplication Workflows are vttab
requires restarts of vttablets. We now allow these to be overridden while creating a workflow or dynamically once
the workflow is in progress. See https://github.com/vitessio/vitess/pull/16583 for details.

### <a id="new-vexplain-modes"/>New VEXPLAIN Modes: TRACE and KEYS

#### VEXPLAIN TRACE

The new TRACE mode for VEXPLAIN provides a detailed execution trace of queries, showing how they're processed through various operators and interactions with tablets. This mode is particularly useful for:

- Identifying performance bottlenecks
- Understanding query execution patterns
- Optimizing complex queries
- Debugging unexpected query behavior

TRACE mode runs the query and logs all interactions, returning a JSON representation of the query execution plan with additional statistics like number of calls, average rows processed, and number of shards queried.

#### VEXPLAIN KEYS

The KEYS mode for VEXPLAIN offers a concise summary of query structure, highlighting columns used in joins, filters, and grouping operations. This information is crucial for:

- Identifying potential sharding key candidates
- Optimizing query performance
- Analyzing query patterns to inform database design decisions

KEYS mode analyzes the query structure without executing it, providing JSON output that includes grouping columns, join columns, filter columns (potential candidates for indexes, primary keys, or sharding keys), and the statement type.

These new VEXPLAIN modes enhance Vitess's query analysis capabilities, allowing for more informed decisions about sharding strategies and query optimization.
2 changes: 2 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,8 @@ func (ty VExplainType) ToString() string {
return AllVExplainStr
case TraceVExplainType:
return TraceStr
case KeysVExplainType:
return KeysStr
default:
return "Unknown VExplainType"
}
Expand Down
2 changes: 2 additions & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ const (
AllVExplainStr = "all"
PlanStr = "plan"
TraceStr = "trace"
KeysStr = "keys"

// Lock Types
ReadStr = "read"
Expand Down Expand Up @@ -848,6 +849,7 @@ const (
PlanVExplainType
AllVExplainType
TraceVExplainType
KeysVExplainType
)

// Constant for Enum Type - SelectIntoType
Expand Down
5 changes: 3 additions & 2 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2574,8 +2574,9 @@ var (
input: "vexplain select * from t",
output: "vexplain plan select * from t",
}, {
input: "vexplain trace select * from t",
output: "vexplain trace select * from t",
input: "vexplain trace select * from t",
}, {
input: "vexplain keys select * from t",
}, {
input: "explain analyze select * from t",
}, {
Expand Down
Loading