Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BottleneckInfo ¶
type BottleneckInfo struct {
Node *PlanNode `json:"node"`
Issue string `json:"issue"`
Severity string `json:"severity"` // CRITICAL, WARNING, INFO
ImpactScore float64 `json:"impact_score"`
Recommendation string `json:"recommendation"`
}
BottleneckInfo represents a performance bottleneck in the plan
type Cost ¶
type Cost struct {
StartupCost float64 `json:"startup_cost"` // Cost to get first row
TotalCost float64 `json:"total_cost"` // Total cost to get all rows
CPUCost float64 `json:"cpu_cost,omitempty"`
IOCost float64 `json:"io_cost,omitempty"`
NetworkCost float64 `json:"network_cost,omitempty"`
}
Cost represents the cost estimates for a plan node
type ExecutionPlan ¶
type ExecutionPlan struct {
Query string `json:"query"`
Dialect string `json:"dialect"`
RootNode *PlanNode `json:"root_node"`
TotalCost float64 `json:"total_cost"`
EstimatedRows int64 `json:"estimated_rows"`
ActualRows int64 `json:"actual_rows,omitempty"` // For EXPLAIN ANALYZE
ExecutionTime time.Duration `json:"execution_time,omitempty"` // For EXPLAIN ANALYZE
Warnings []string `json:"warnings,omitempty"`
Statistics *PlanStatistics `json:"statistics,omitempty"`
}
ExecutionPlan represents a query execution plan
func ParseJSONPlan ¶
func ParseJSONPlan(jsonData []byte, dialect string) (*ExecutionPlan, error)
ParseJSONPlan parses a JSON execution plan This is used for parsing output from EXPLAIN FORMAT=JSON
func (*ExecutionPlan) CalculateStatistics ¶
func (p *ExecutionPlan) CalculateStatistics()
CalculateStatistics calculates statistics for the execution plan
func (*ExecutionPlan) FindBottlenecks ¶
func (p *ExecutionPlan) FindBottlenecks() []*BottleneckInfo
FindBottlenecks identifies performance bottlenecks in the plan
type NodeType ¶
type NodeType string
NodeType represents the type of plan node
const ( // Scan operations NodeTypeSeqScan NodeType = "SEQ_SCAN" NodeTypeIndexScan NodeType = "INDEX_SCAN" NodeTypeIndexOnlyScan NodeType = "INDEX_ONLY_SCAN" NodeTypeBitmapScan NodeType = "BITMAP_SCAN" // Join operations NodeTypeNestedLoop NodeType = "NESTED_LOOP" NodeTypeHashJoin NodeType = "HASH_JOIN" NodeTypeMergeJoin NodeType = "MERGE_JOIN" // Aggregation operations NodeTypeAggregate NodeType = "AGGREGATE" NodeTypeGroupBy NodeType = "GROUP_BY" NodeTypeHashAggregate NodeType = "HASH_AGGREGATE" // Sorting operations NodeTypeSort NodeType = "SORT" NodeTypeQuickSort NodeType = "QUICKSORT" // Other operations NodeTypeFilter NodeType = "FILTER" NodeTypeLimit NodeType = "LIMIT" NodeTypeUnion NodeType = "UNION" NodeTypeIntersect NodeType = "INTERSECT" NodeTypeExcept NodeType = "EXCEPT" NodeTypeSubquery NodeType = "SUBQUERY" NodeTypeMaterialize NodeType = "MATERIALIZE" NodeTypeCTE NodeType = "CTE" // SQL Server specific NodeTypeClusteredIndexScan NodeType = "CLUSTERED_INDEX_SCAN" NodeTypeNonClusteredIndexScan NodeType = "NONCLUSTERED_INDEX_SCAN" NodeTypeTableScan NodeType = "TABLE_SCAN" // MySQL specific NodeTypeFullTableScan NodeType = "FULL_TABLE_SCAN" NodeTypeRangeScan NodeType = "RANGE_SCAN" )
type PlanAnalysis ¶
type PlanAnalysis struct {
Plan *ExecutionPlan `json:"plan"`
Issues []*PlanIssue `json:"issues"`
Recommendations []*Recommendation `json:"recommendations"`
PerformanceScore float64 `json:"performance_score"`
}
PlanAnalysis contains the results of plan analysis
type PlanAnalyzer ¶
type PlanAnalyzer struct {
// contains filtered or unexported fields
}
PlanAnalyzer analyzes execution plans and provides optimization suggestions
func NewPlanAnalyzer ¶
func NewPlanAnalyzer(dialect string) *PlanAnalyzer
NewPlanAnalyzer creates a new plan analyzer
func (*PlanAnalyzer) AnalyzePlan ¶
func (pa *PlanAnalyzer) AnalyzePlan(plan *ExecutionPlan) *PlanAnalysis
AnalyzePlan performs comprehensive analysis on an execution plan
type PlanIssue ¶
type PlanIssue struct {
Severity string `json:"severity"` // CRITICAL, WARNING, INFO
Type string `json:"type"` // BOTTLENECK, MISSING_INDEX, etc.
Description string `json:"description"`
Node *PlanNode `json:"node,omitempty"`
ImpactScore float64 `json:"impact_score"`
}
PlanIssue represents an issue found in the execution plan
type PlanNode ¶
type PlanNode struct {
NodeType NodeType `json:"node_type"`
Operation string `json:"operation"` // e.g., "Seq Scan", "Index Scan", "Hash Join"
Table string `json:"table,omitempty"`
Index string `json:"index,omitempty"`
Condition string `json:"condition,omitempty"`
Cost *Cost `json:"cost,omitempty"`
Rows *RowEstimate `json:"rows,omitempty"`
OutputColumns []string `json:"output_columns,omitempty"`
Children []*PlanNode `json:"children,omitempty"`
Extra map[string]any `json:"extra,omitempty"` // Dialect-specific fields
}
PlanNode represents a single node in the execution plan tree
func (*PlanNode) IsExpensive ¶
IsExpensive returns true if the node is considered expensive
func (*PlanNode) IsFullTableScan ¶
IsFullTableScan returns true if the node performs a full table scan
func (*PlanNode) IsIndexScan ¶
IsIndexScan returns true if the node uses an index
type PlanStatistics ¶
type PlanStatistics struct {
TotalNodes int `json:"total_nodes"`
ScanNodes int `json:"scan_nodes"`
JoinNodes int `json:"join_nodes"`
IndexScans int `json:"index_scans"`
FullTableScans int `json:"full_table_scans"`
TotalEstimatedRows int64 `json:"total_estimated_rows"`
TotalActualRows int64 `json:"total_actual_rows,omitempty"`
MaxDepth int `json:"max_depth"`
BottleneckNodes []*BottleneckInfo `json:"bottleneck_nodes,omitempty"`
}
PlanStatistics contains overall plan statistics
type Recommendation ¶
type Recommendation struct {
Type string `json:"type"` // INDEX, OPTIMIZATION, QUERY_REWRITE, etc.
Description string `json:"description"`
Priority string `json:"priority"` // CRITICAL, HIGH, MEDIUM, LOW
}
Recommendation represents an optimization recommendation
type RowEstimate ¶
type RowEstimate struct {
Estimated int64 `json:"estimated"` // Estimated rows
Actual int64 `json:"actual,omitempty"` // Actual rows (EXPLAIN ANALYZE)
Width int `json:"width,omitempty"` // Average row width in bytes
Accuracy float64 `json:"accuracy,omitempty"` // Estimation accuracy (actual/estimated)
}
RowEstimate represents row count estimates