Documentation
¶
Index ¶
- Variables
- func WithRequestBuiltinRuleSet(name string) analysis.RequestOption
- func WithRequestDatabase(database string) analysis.RequestOption
- func WithRequestLanguage(lang string) analysis.RequestOption
- func WithRequestRuleFilter(f optimizer.RuleFilter) analysis.RequestOption
- func WithRequestRuleSet(rs *optimizer.RuleSet) analysis.RequestOption
- type Agent
- func (a *Agent) Analyze(ctx context.Context, sql string, opts ...RequestOption) (*analysis.AnalyzeResult, error)
- func (a *Agent) AnalyzeStatic(ctx context.Context, sql string, opts ...RequestOption) (*analysis.AnalyzeResult, error)
- func (a *Agent) Capabilities() []analysis.CapabilityStatus
- func (a *Agent) Close()
- func (*Agent) Engine() analysis.Engine
- func (a *Agent) Explain(ctx context.Context, sql string, opts ...RequestOption) (*analysis.ExplainResult, error)
- func (a *Agent) InvalidateTableCacheAll(schemaName, tableName string)
- func (a *Agent) InvalidateTableInfoCache(schemaName, tableName string)
- func (a *Agent) ListRules() []optimizer.RuleDescriptor
- func (a *Agent) RenderMessage(ref *analysis.MessageRef, lang string) string
- func (a *Agent) RenderResult(result *analysis.AnalyzeResult, lang string) *analysis.AnalyzeResult
- func (a *Agent) ServerVersion() analysis.ServerVersion
- func (a *Agent) UseDatabase(ctx context.Context, database string) error
- func (a *Agent) VersionProfile() analysis.VersionProfile
- type AgentConfig
- type Option
- func WithAgentConfig(config *optimizer.AgentConfig) Option
- func WithBuiltinRuleSet(name string) Option
- func WithCharset(charset string) Option
- func WithCollation(collation string) Option
- func WithDefaultDatabase(database string) Option
- func WithDefaultLanguage(lang string) Option
- func WithLanguage(lang string) Optiondeprecated
- func WithLocaleCatalog(catalog *sqli18n.Catalog) Option
- func WithOptimizationCacheConfig(cfg *cost.OptimizationCacheConfig) Option
- func WithResolvedAgentConfig(config AgentConfig) Option
- func WithRuleSet(rs *optimizer.RuleSet) Option
- func WithSchema(schema string) Option
- func WithTableInfoCacheConfig(cfg *db.TableInfoCacheConfig) Option
- func WithTranslationFiles(files ...string) Option
- type RequestOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDatabaseRequired indicates that a connected request cannot establish a // deterministic session database. ErrDatabaseRequired = errors.New("MySQL database is required") // ErrInvalidDatabaseName indicates an unsafe or invalid database identifier. ErrInvalidDatabaseName = errors.New("invalid MySQL database name") // ErrDatabaseSwitchFailed indicates that USE failed on the pinned connection. ErrDatabaseSwitchFailed = errors.New("switch MySQL database failed") // ErrExplainRelationAmbiguous identifies non-fatal native plan ambiguity. ErrExplainRelationAmbiguous = explain.ErrExplainRelationAmbiguous )
var ErrAgentClosed = errors.New("MySQL Agent is closed")
ErrAgentClosed means the Agent no longer accepts requests.
var ErrConnectionNotConfigured = errors.New("MySQL connection is not configured")
ErrConnectionNotConfigured means no online connection was configured.
Functions ¶
func WithRequestBuiltinRuleSet ¶
func WithRequestBuiltinRuleSet(name string) analysis.RequestOption
WithRequestBuiltinRuleSet selects a named builtin rule set for one Analyze or AnalyzeStatic call. Unknown names fail before analysis starts.
func WithRequestDatabase ¶
func WithRequestDatabase(database string) analysis.RequestOption
WithRequestDatabase overrides the default database for unqualified physical relations in one request. Empty values do not clear the Agent default.
func WithRequestLanguage ¶
func WithRequestLanguage(lang string) analysis.RequestOption
WithRequestLanguage sets the response language for a single request.
func WithRequestRuleFilter ¶
func WithRequestRuleFilter(f optimizer.RuleFilter) analysis.RequestOption
WithRequestRuleFilter expands a filter against the current catalog for one request.
func WithRequestRuleSet ¶
func WithRequestRuleSet(rs *optimizer.RuleSet) analysis.RequestOption
WithRequestRuleSet overrides the Agent default rule set for one request. Passing a non-nil empty RuleSet explicitly selects zero rules; passing nil clears any prior request-level selection so the Agent default applies.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is the main entry point for SQL analysis
func NewAgent ¶
NewAgent validates and freezes local configuration without opening a connection. An empty DSN enables offline use. Nonempty malformed DSNs fail immediately; connectivity and authentication failures are reported by online requests. If WithLocaleCatalog is not provided, it builds an agent-scoped catalog that loads built-in common/mysql locales to avoid cross-dialect collisions.
func (*Agent) Analyze ¶
func (a *Agent) Analyze(ctx context.Context, sql string, opts ...RequestOption) (*analysis.AnalyzeResult, error)
Analyze performs connected SQL analysis using AST rules, read-only metadata, native EXPLAIN, and internal whole-query what-if planning. It never executes the supplied statement or generated DDL/DML suggestions.
The report keeps the native plan separate from internally modeled cost comparisons. Callers must inspect each evaluation's status and the declared model identity before using its estimates.
func (*Agent) AnalyzeStatic ¶
func (a *Agent) AnalyzeStatic(ctx context.Context, sql string, opts ...RequestOption) (*analysis.AnalyzeResult, error)
AnalyzeStatic analyzes SQL text without querying database metadata or executing EXPLAIN. Its report contains AST-provable issues and no native plan or modeled whole-query evaluation. The context is accepted for symmetry with connected entry points but is not consumed by the synchronous parser.
func (*Agent) Capabilities ¶
func (a *Agent) Capabilities() []analysis.CapabilityStatus
Capabilities reports supported engine facilities without claiming that every SQL shape is modeled by what-if.
func (*Agent) Close ¶
func (a *Agent) Close()
Close rejects new requests, waits for admitted requests, and releases resources. It closes the connection pool, drops in-memory metadata and plan caches, and deletes the optimization-cache file when PersistencePath is set.
func (*Agent) Explain ¶
func (a *Agent) Explain(ctx context.Context, sql string, opts ...RequestOption) (*analysis.ExplainResult, error)
Explain returns only native plan evidence and never invokes analysis rules.
func (*Agent) InvalidateTableCacheAll ¶
InvalidateTableCacheAll removes all cached metadata levels for one table.
func (*Agent) InvalidateTableInfoCache ¶
InvalidateTableInfoCache removes the sampled metadata entry for one table.
func (*Agent) ListRules ¶
func (a *Agent) ListRules() []optimizer.RuleDescriptor
func (*Agent) RenderMessage ¶
func (a *Agent) RenderMessage(ref *analysis.MessageRef, lang string) string
RenderMessage renders one persisted public message reference.
func (*Agent) RenderResult ¶
func (a *Agent) RenderResult(result *analysis.AnalyzeResult, lang string) *analysis.AnalyzeResult
RenderResult re-renders a persisted public report without running analysis.
func (*Agent) ServerVersion ¶
func (a *Agent) ServerVersion() analysis.ServerVersion
ServerVersion returns the version observed at initialization, or unknown for an offline Agent.
func (*Agent) UseDatabase ¶
UseDatabase validates access on a pinned connection and atomically changes the default observed by requests that start after it succeeds.
func (*Agent) VersionProfile ¶
func (a *Agent) VersionProfile() analysis.VersionProfile
VersionProfile identifies the observed server generation and cost model.
type AgentConfig ¶
type AgentConfig struct {
DiagnosticPolicy analysis.DiagnosticPolicy
RulePolicy optimizer.RulePolicy
OptimizationConfig optimizer.OptimizationConfig
}
AgentConfig groups the immutable policies used by a MySQL Agent. NewAgent resolves defaults, validates every component, and freezes a defensive copy before opening a database connection.
func DefaultAgentConfig ¶
func DefaultAgentConfig() AgentConfig
DefaultAgentConfig returns a fresh MySQL Agent configuration.
func (AgentConfig) Clone ¶
func (config AgentConfig) Clone() AgentConfig
Clone returns a defensive deep copy suitable for caller mutation.
func (AgentConfig) Resolve ¶
func (config AgentConfig) Resolve() (AgentConfig, error)
Resolve validates all policy groups and fills unspecified values from their respective defaults.
func (AgentConfig) Validate ¶
func (config AgentConfig) Validate() error
Validate checks each immutable configuration group independently.
type Option ¶
type Option func(*agentOptions)
Option is a function that configures the Agent
func WithAgentConfig ¶
func WithAgentConfig(config *optimizer.AgentConfig) Option
WithAgentConfig sets all MySQL diagnostic, rule, and optimization policies. A nil pointer selects defaults. The input is copied so later caller mutations do not change an already-created Agent.
func WithBuiltinRuleSet ¶
WithBuiltinRuleSet sets the Agent default rule set to a named builtin profile. Common names are "all", "static", and "dynamic"; see optimizer.BuiltinRuleSet for the full list. Unknown names fail in NewAgent.
func WithDefaultDatabase ¶
WithDefaultDatabase sets the Agent default database. An empty value leaves DSN fallback enabled during construction.
func WithDefaultLanguage ¶
WithDefaultLanguage sets the default language for messages.
func WithLanguage
deprecated
func WithLocaleCatalog ¶
WithLocaleCatalog sets a prebuilt caller-owned locale catalog for the agent. When non-nil, it takes precedence over WithTranslationFiles so the caller's catalog is never mutated by the agent.
func WithOptimizationCacheConfig ¶
func WithOptimizationCacheConfig(cfg *cost.OptimizationCacheConfig) Option
WithOptimizationCacheConfig enables a shared whole-query what-if plan cache. PersistencePath is optional. When set, a new Agent loads that file if it exists. Close drops the in-memory entries and deletes the file.
func WithResolvedAgentConfig ¶
func WithResolvedAgentConfig(config AgentConfig) Option
WithResolvedAgentConfig sets a MySQL Agent configuration using the Agent package's value shape. It is useful when a caller already resolved defaults.
func WithRuleSet ¶
WithRuleSet sets the Agent default rule set. Pass optimizer.BuiltinRuleSet or a custom NewRuleSet result; nil restores running every registered rule.
func WithSchema ¶
WithSchema is a backward-compatible alias for WithDefaultDatabase.
func WithTableInfoCacheConfig ¶
func WithTableInfoCacheConfig(cfg *db.TableInfoCacheConfig) Option
WithTableInfoCacheConfig overrides the Agent's default table cache configuration. Passing nil disables the table cache.
func WithTranslationFiles ¶
WithTranslationFiles loads translation files into an agent-scoped catalog. Files are loaded after built-in common/mysql locale files and can override them. WithTranslationFiles loads additional TOML translation files into the agent-scoped catalog. Ignored when WithLocaleCatalog supplies an explicit caller-owned catalog.
type RequestOption ¶
type RequestOption = analysis.RequestOption
RequestOption configures request-scoped behavior for Analyze / Explain. It is shared with the engine-neutral analysis contract.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
result_model.go defines the public boundary between native EXPLAIN facts and internal whole-query what-if predictions.
|
result_model.go defines the public boundary between native EXPLAIN facts and internal whole-query what-if predictions. |
|
Package parser converts TiDB parser nodes into sql-gunyu's MySQL AST.
|
Package parser converts TiDB parser nodes into sql-gunyu's MySQL AST. |
|
Package relation defines canonical MySQL physical-relation identities.
|
Package relation defines canonical MySQL physical-relation identities. |