Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:02:21 * @FilePath: \go-sqlbuilder\compiler\compiler.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:06 * @FilePath: \go-sqlbuilder\compiler\interface.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:14 * @FilePath: \go-sqlbuilder\compiler\optimizer.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-11-13 11:03:21 * @FilePath: \go-sqlbuilder\compiler\planner.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
Index ¶
- type ColumnStatistics
- type CompilerConfig
- type CompilerOptions
- type CompositeOptimizer
- type DefaultCompiler
- func (c *DefaultCompiler) AddCustomTransformer(name string, transformer func(string) string)
- func (c *DefaultCompiler) AddOptimizer(optimizer Optimizer)
- func (c *DefaultCompiler) Compile(execCtx *executor.ExecutionContext) (string, []interface{}, error)
- func (c *DefaultCompiler) GetDialect() string
- func (c *DefaultCompiler) SetDialect(dialect string) error
- type DialectCompiler
- type GroupByOptimizer
- type JoinOptimizer
- type Optimizer
- type OrderByOptimizer
- type Planner
- type QueryPlan
- type SQLCompiler
- type SelectOptimizer
- type SimplePlanner
- type StatisticPlanner
- func (p *StatisticPlanner) AddTableStatistics(stats TableStatistics)
- func (p *StatisticPlanner) Analyze(execCtx *executor.ExecutionContext) map[string]interface{}
- func (p *StatisticPlanner) GetTableStatistics(tableName string) (TableStatistics, bool)
- func (p *StatisticPlanner) Plan(execCtx *executor.ExecutionContext) (*QueryPlan, error)
- type TableStatistics
- type WhereOptimizer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnStatistics ¶
type ColumnStatistics struct {
ColumnName string
Cardinality int64
AvgLength int32
NullCount int64
DistinctVals int64
}
ColumnStatistics 列统计信息
type CompilerConfig ¶
type CompilerConfig struct {
// 选项
Options CompilerOptions
// 优化器列表
Optimizers []Optimizer
// 查询计划器
Planner Planner
// 自定义SQL转换函数
CustomTransformers map[string]func(string) string
}
CompilerConfig 编译器配置
type CompilerOptions ¶
type CompilerOptions struct {
// 方言
Dialect string
// 是否启用优化
EnableOptimization bool
// 是否启用查询计划
EnablePlanning bool
// 最大查询复杂度
MaxQueryComplexity int
// 是否启用参数化查询
EnableParameterization bool
// 是否启用查询缓存
EnableQueryCache bool
}
CompilerOptions 编译器选项
type CompositeOptimizer ¶
type CompositeOptimizer struct {
// contains filtered or unexported fields
}
CompositeOptimizer 组合优化器
func (*CompositeOptimizer) AddOptimizer ¶
func (o *CompositeOptimizer) AddOptimizer(optimizer Optimizer)
AddOptimizer 添加优化器
func (*CompositeOptimizer) Optimize ¶
func (o *CompositeOptimizer) Optimize(execCtx *executor.ExecutionContext) (*executor.ExecutionContext, error)
Optimize 应用所有优化器
type DefaultCompiler ¶
type DefaultCompiler struct {
// contains filtered or unexported fields
}
DefaultCompiler 默认SQL编译器实现
func (*DefaultCompiler) AddCustomTransformer ¶
func (c *DefaultCompiler) AddCustomTransformer(name string, transformer func(string) string)
AddCustomTransformer 添加自定义转换器
func (*DefaultCompiler) AddOptimizer ¶
func (c *DefaultCompiler) AddOptimizer(optimizer Optimizer)
AddOptimizer 添加优化器
func (*DefaultCompiler) Compile ¶
func (c *DefaultCompiler) Compile(execCtx *executor.ExecutionContext) (string, []interface{}, error)
Compile 编译SQL查询
func (*DefaultCompiler) SetDialect ¶
func (c *DefaultCompiler) SetDialect(dialect string) error
SetDialect 设置方言
type DialectCompiler ¶
type DialectCompiler struct {
// contains filtered or unexported fields
}
DialectCompiler 方言编译器工厂
func (*DialectCompiler) Compile ¶
func (dc *DialectCompiler) Compile(dialect string, execCtx *executor.ExecutionContext) (string, []interface{}, error)
Compile 使用默认编译器编译
func (*DialectCompiler) GetCompiler ¶
func (dc *DialectCompiler) GetCompiler(dialect string) (SQLCompiler, error)
GetCompiler 获取指定方言的编译器
func (*DialectCompiler) RegisterCompiler ¶
func (dc *DialectCompiler) RegisterCompiler(dialect string, compiler SQLCompiler) error
RegisterCompiler 注册自定义编译器
type GroupByOptimizer ¶
type GroupByOptimizer struct {
// contains filtered or unexported fields
}
GroupByOptimizer GROUP BY优化器
func (*GroupByOptimizer) Optimize ¶
func (o *GroupByOptimizer) Optimize(execCtx *executor.ExecutionContext) (*executor.ExecutionContext, error)
Optimize 优化GROUP BY操作
type JoinOptimizer ¶
type JoinOptimizer struct {
// contains filtered or unexported fields
}
JoinOptimizer JOIN优化器
func (*JoinOptimizer) Optimize ¶
func (o *JoinOptimizer) Optimize(execCtx *executor.ExecutionContext) (*executor.ExecutionContext, error)
Optimize 优化JOIN操作
type Optimizer ¶
type Optimizer interface {
// Optimize 优化SQL执行上下文
Optimize(execCtx *executor.ExecutionContext) (*executor.ExecutionContext, error)
// GetName 获取优化器名称
GetName() string
}
Optimizer SQL优化器接口 优化SQL查询性能
func NewCompositeOptimizer ¶
NewCompositeOptimizer 创建组合优化器
type OrderByOptimizer ¶
type OrderByOptimizer struct {
// contains filtered or unexported fields
}
OrderByOptimizer ORDER BY优化器
func (*OrderByOptimizer) Optimize ¶
func (o *OrderByOptimizer) Optimize(execCtx *executor.ExecutionContext) (*executor.ExecutionContext, error)
Optimize 优化ORDER BY操作
type Planner ¶
type Planner interface {
// Plan 生成查询执行计划
Plan(execCtx *executor.ExecutionContext) (*QueryPlan, error)
// Analyze 分析查询性能
Analyze(execCtx *executor.ExecutionContext) map[string]interface{}
}
Planner 查询计划器接口
type QueryPlan ¶
type QueryPlan struct {
// 原始SQL
OriginalSQL string
// 优化后的SQL
OptimizedSQL string
// 执行策略
Strategy string
// 估计成本
EstimatedCost float64
// 索引建议
IndexHints []string
// 优化说明
Explanation string
}
QueryPlan 查询计划
type SQLCompiler ¶
type SQLCompiler interface {
// Compile 编译执行上下文为SQL语句
Compile(execCtx *executor.ExecutionContext) (string, []interface{}, error)
// GetDialect 获取当前方言
GetDialect() string
// SetDialect 设置方言
SetDialect(dialect string) error
}
SQLCompiler SQL编译器接口 将ExecutionContext编译成特定方言的SQL语句
func NewDefaultCompiler ¶
func NewDefaultCompiler(dialect string) SQLCompiler
NewDefaultCompiler 创建默认编译器
type SelectOptimizer ¶
type SelectOptimizer struct {
// contains filtered or unexported fields
}
SelectOptimizer SELECT语句优化器
func (*SelectOptimizer) Optimize ¶
func (o *SelectOptimizer) Optimize(execCtx *executor.ExecutionContext) (*executor.ExecutionContext, error)
Optimize 优化SELECT语句
type SimplePlanner ¶
type SimplePlanner struct {
// contains filtered or unexported fields
}
SimplePlanner 简单查询计划器
func (*SimplePlanner) Analyze ¶
func (p *SimplePlanner) Analyze(execCtx *executor.ExecutionContext) map[string]interface{}
Analyze 分析查询性能
func (*SimplePlanner) Plan ¶
func (p *SimplePlanner) Plan(execCtx *executor.ExecutionContext) (*QueryPlan, error)
Plan 生成查询执行计划
type StatisticPlanner ¶
type StatisticPlanner struct {
// contains filtered or unexported fields
}
StatisticPlanner 基于统计信息的查询计划器
func NewStatisticPlanner ¶
func NewStatisticPlanner() *StatisticPlanner
NewStatisticPlanner 创建基于统计的查询计划器
func (*StatisticPlanner) AddTableStatistics ¶
func (p *StatisticPlanner) AddTableStatistics(stats TableStatistics)
AddTableStatistics 添加表统计信息
func (*StatisticPlanner) Analyze ¶
func (p *StatisticPlanner) Analyze(execCtx *executor.ExecutionContext) map[string]interface{}
Analyze 分析查询性能
func (*StatisticPlanner) GetTableStatistics ¶
func (p *StatisticPlanner) GetTableStatistics(tableName string) (TableStatistics, bool)
GetTableStatistics 获取表统计信息
func (*StatisticPlanner) Plan ¶
func (p *StatisticPlanner) Plan(execCtx *executor.ExecutionContext) (*QueryPlan, error)
Plan 生成查询执行计划
type TableStatistics ¶
type TableStatistics struct {
TableName string
RowCount int64
ColumnStat map[string]ColumnStatistics
}
TableStatistics 表统计信息
type WhereOptimizer ¶
type WhereOptimizer struct {
// contains filtered or unexported fields
}
WhereOptimizer WHERE子句优化器
func (*WhereOptimizer) Optimize ¶
func (o *WhereOptimizer) Optimize(execCtx *executor.ExecutionContext) (*executor.ExecutionContext, error)
Optimize 优化WHERE子句