Documentation
¶
Overview ¶
Package sqlgunyu provides SQL parsing, analysis, and optimization capabilities with internationalization support for different SQL dialects.
This package serves as the main entry point for the sql-gunyu library, offering functionality for: - SQL parsing and analysis - Query optimization - Cost estimation - Internationalization (i18n) support for different SQL dialects
Example usage:
// Create a custom catalog for one dialect (recommended for runtime isolation)
catalog, err := sqlgunyu.NewCatalog(
sqlgunyu.WithDialects(sqlgunyu.DialectMySQL),
sqlgunyu.WithLanguages("zh", "en"),
)
if err != nil {
log.Fatal(err)
}
// Optional: initialize the shared default catalog.
// Prefer explicit dialect/language scopes to avoid loading unnecessary locales.
if err := sqlgunyu.Init(
sqlgunyu.WithDialects(sqlgunyu.DialectMySQL),
sqlgunyu.WithLanguages("zh", "en"),
); err != nil {
log.Fatal(err)
}
Supported dialects:
- MySQL
- PostgreSQL 16 and 17
Supported languages:
- English (en)
- Chinese (zh)
Note: This package embeds locale files for built-in dialects and languages. Custom translation files can be loaded using the WithFiles option. For multi-dialect applications, prefer catalog-per-dialect to avoid key collisions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrExplainUnsupported = errors.New("statement does not support EXPLAIN analysis")
ErrExplainUnsupported indicates that a valid statement is outside the connected EXPLAIN analysis pipeline's supported statement types.
Functions ¶
func Init ¶
func Init(opts ...InitOption) error
Init loads embedded/custom locale files into the default shared catalog.
Types ¶
type Catalog ¶
Catalog is the locale catalog used for message localization.
func DefaultCatalog ¶
func DefaultCatalog() *Catalog
DefaultCatalog returns the process-wide shared i18n catalog.
func NewCatalog ¶
func NewCatalog(opts ...InitOption) (*Catalog, error)
NewCatalog creates a new catalog and loads embedded/custom locale files into it.
type Dialect ¶
type Dialect string
Dialect identifies a SQL engine family for loading dialect-specific locales.
type InitOption ¶
type InitOption func(*initConfig)
InitOption configures catalog initialization behavior.
func WithAllDialects ¶
func WithAllDialects() InitOption
WithAllDialects enables loading locales for all built-in dialects.
func WithAllLanguages ¶
func WithAllLanguages() InitOption
WithAllLanguages enables loading all discovered built-in languages.
func WithCatalog ¶
func WithCatalog(catalog *Catalog) InitOption
WithCatalog sets the target catalog to load locale files into.
func WithDialects ¶
func WithDialects(dialects ...Dialect) InitOption
WithDialects limits embedded locale loading to the specified dialects.
func WithFiles ¶
func WithFiles(files ...string) InitOption
WithFiles appends custom translation files to load after embedded locales.
func WithLanguages ¶
func WithLanguages(langs ...string) InitOption
WithLanguages limits embedded locale loading to the specified languages.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
connected_mysql
command
|
|
|
docker_mysql
command
Command docker_mysql serves the SQL GunYu demo with a disposable MySQL instance.
|
Command docker_mysql serves the SQL GunYu demo with a disposable MySQL instance. |
|
postgresql_analysis
command
|
|
|
static_audit
command
|
|
|
internal
|
|
|
analysisinput
Package analysisinput holds engine computation inputs before report assembly.
|
Package analysisinput holds engine computation inputs before report assembly. |
|
analysisreport
Package analysisreport assembles reports from engine-owned computation facts.
|
Package analysisreport assembles reports from engine-owned computation facts. |
|
cache
Package cache provides bounded, concurrent LRU storage.
|
Package cache provides bounded, concurrent LRU storage. |
|
mysqltestenv
Package mysqltestenv centralizes environment-variable names used by optional MySQL integration tests and test utilities.
|
Package mysqltestenv centralizes environment-variable names used by optional MySQL integration tests and test utilities. |
|
mysqltestworkload
Package mysqltestworkload defines the shared, versioned SQL workload used by MySQL integration tests, offline replay, and physical-plan benchmarks.
|
Package mysqltestworkload defines the shared, versioned SQL workload used by MySQL integration tests, offline replay, and physical-plan benchmarks. |
|
postgresqltestenv
Package postgresqltestenv centralizes environment variables and destructive PostgreSQL test safety checks.
|
Package postgresqltestenv centralizes environment variables and destructive PostgreSQL test safety checks. |
|
postgresqltestworkload
Package postgresqltestworkload defines the shared, versioned SQL workload used by PostgreSQL integration tests, offline replay, and physical-plan benchmarks.
|
Package postgresqltestworkload defines the shared, versioned SQL workload used by PostgreSQL integration tests, offline replay, and physical-plan benchmarks. |
|
testdbversion
Package testdbversion provides strict database-version selection for test fixtures and expectations.
|
Package testdbversion provides strict database-version selection for test fixtures and expectations. |
|
pkg
|
|
|
analysis
Package analysis defines the stable, engine-neutral API contract for SQL analysis.
|
Package analysis defines the stable, engine-neutral API contract for SQL analysis. |
|
analysis/logicalir
Package logicalir contains the experimental logical SQL IR and rewrite evaluation API.
|
Package logicalir contains the experimental logical SQL IR and rewrite evaluation API. |
|
mysql/optimizer
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. |
|
mysql/parser
Package parser converts TiDB parser nodes into sql-gunyu's MySQL AST.
|
Package parser converts TiDB parser nodes into sql-gunyu's MySQL AST. |
|
mysql/relation
Package relation defines canonical MySQL physical-relation identities.
|
Package relation defines canonical MySQL physical-relation identities. |
|
postgresql
Package postgresql provides an analysis.Agent implementation for PostgreSQL.
|
Package postgresql provides an analysis.Agent implementation for PostgreSQL. |
|
postgresql/cost/native_hypopg
Package native_hypopg implements the explicitly enabled PostgreSQL-native HypoPG what-if provider.
|
Package native_hypopg implements the explicitly enabled PostgreSQL-native HypoPG what-if provider. |
|
postgresql/db
Package db implements PostgreSQL-only connections, planning-context identity, catalog metadata, statistics, and caches.
|
Package db implements PostgreSQL-only connections, planning-context identity, catalog metadata, statistics, and caches. |
|
postgresql/explain
Package explain decodes and safely executes PostgreSQL JSON EXPLAIN.
|
Package explain decodes and safely executes PostgreSQL JSON EXPLAIN. |
|
postgresql/locale
Package locale provides PostgreSQL-scoped message catalogs.
|
Package locale provides PostgreSQL-scoped message catalogs. |
|
postgresql/profile
Package profile defines PostgreSQL-major version profiles and effective capability calculation.
|
Package profile defines PostgreSQL-major version profiles and effective capability calculation. |
|
tests
|
|
|
mysql/cmd/live_acceptance
command
|
|
|
mysql/indexmatrix
Package indexmatrix contains only synthetic input and independent data oracles for the offline MySQL index recommendation tests.
|
Package indexmatrix contains only synthetic input and independent data oracles for the offline MySQL index recommendation tests. |
|
mysql/mysqlfixture
Package mysqlfixture adapts shared evidence at MySQL's external I/O boundary.
|
Package mysqlfixture adapts shared evidence at MySQL's external I/O boundary. |
|
mysql/mysqlplanbench
command
|
|
|
mysql/mysqltestinit
command
|
|
|
mysql/testkit
Package testkit loads engine-neutral offline acceptance inputs and assertions.
|
Package testkit loads engine-neutral offline acceptance inputs and assertions. |
|
postgresql/bulkload
command
Command bulkload destructively rebuilds an explicitly selected PostgreSQL test schema with deterministic, type-rich canonical data.
|
Command bulkload destructively rebuilds an explicitly selected PostgreSQL test schema with deterministic, type-rich canonical data. |