tidbparser

package
v0.511.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

TiDB Parser Module

TiDB-backed parser adapter for multi-statement SQL parsing, parser-warning collection, and query access extraction.

Files

File Responsibility
parser.go Parses SQL text and preserves raw statement nodes plus parser warnings
extractor.go Wraps TiDB AST nodes in parser-neutral extractors and performs TiDB-specific statement extraction including MutationTargets, mutation-target-only DML table facts, normalized ALTER index/constraint actions, inline/table-level primary-key metadata with implicit primary-key nullability, and database/schema lifecycle DDL (CREATE/DROP DATABASE/SCHEMA normalized to create_schema/drop_schema with ObjectType="database")
query_access.go Extracts query access facts from TiDB AST: lexical scope system, relation/column/output extraction, read classification, and candidate handoff
query_access_effect_candidates.go Defines bounded internal candidate facts, operand hints, and copy-safe candidate accumulation
query_access_effect_collector.go Traverses query locations, scopes, subqueries, CTEs, derived tables, set operations, and LIMIT/OFFSET expressions
query_access_effect_builders.go Builds function, aggregate, window, cast, and unsupported-traversal candidate facts
query_access_effect_candidates_test.go Characterizes deterministic candidate closure and fail-closed AST boundaries
parser_test.go Verifies multi-statement parsing, parse-failure behavior, and extractor-backed wrapping
query_access_test.go Verifies query access extraction for SELECT, JOIN, CTE, subquery, wildcard, function, locking, DDL, and multi-statement forms
query_access_ast_census_test.go Characterization matrix for TiDB parser AST fields and classification invariants

Exports

  • Parser
  • Result
  • ExtractedStatement
  • New()
  • WrapStatements()
  • QueryAccessExtractor
  • QueryAccessFacts
  • EffectCandidate (internal-only; untrusted; never public JSON)
  • RelationFact
  • ColumnFact
  • OutputFact
  • UnresolvedFact

Dependencies

  • Upstream: internal/application/audit, internal/application/queryaccess, internal/domain/spec
  • Downstream: github.com/pingcap/tidb/pkg/parser

Update Rule

  • If members/interfaces/dependencies change, update this file in same change.

Documentation

Overview

Package tidbparser extracts parser-neutral statements from TiDB AST nodes. input: TiDB parser statement nodes and parser-neutral dialect metadata output: extractor-backed parsed statements for the application layer, including MutationTargets and mutation-target-only DML tables, normalized ALTER index/constraint actions, and primary-key metadata pos: infrastructure extraction adapter between TiDB AST and domain spec note: if this file changes, update this header and module README.md.

Package tidbparser loads SQL text through the TiDB parser. input: SQL text and TiDB parser runtime dependencies output: raw parsed statement nodes and parser warnings for application orchestration pos: infrastructure parser adapter for MySQL and TiDB SQL parsing note: if this file changes, update this header and module README.md.

Package tidbparser extracts query access facts from TiDB AST nodes. input: SQL text, dialect, and default schema through the TiDB parser output: parser-neutral QueryAccessFacts for relation, column, output, and read-classification analysis pos: infrastructure query access adapter between TiDB AST and application query access contracts note: if this file changes, update this header and module README.md.

Package tidbparser defines bounded internal effect-candidate facts. input: TiDB AST function-like nodes and resolved parser scope output: ordered, untrusted candidate facts for application-internal gateways pos: parser candidate contract; never a public result contract

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlterDatabaseStatement added in v0.200.0

type AlterDatabaseStatement = *ast.AlterDatabaseStmt

type AlterPlacementPolicyStatement added in v0.200.0

type AlterPlacementPolicyStatement = *ast.AlterPlacementPolicyStmt

type AlterSequenceStatement added in v0.200.0

type AlterSequenceStatement = *ast.AlterSequenceStmt

type AlterTableStatement added in v0.15.0

type AlterTableStatement = *ast.AlterTableStmt

type AlterUserStatement added in v0.200.0

type AlterUserStatement = *ast.AlterUserStmt

type ColumnFact added in v0.380.0

type ColumnFact struct {
	Schema string   `json:"schema,omitempty"`
	Table  string   `json:"table"`
	Column string   `json:"column"`
	Usages []string `json:"usages"`
}

type CreateIndexStatement added in v0.15.0

type CreateIndexStatement = *ast.CreateIndexStmt

type CreatePlacementPolicyStatement added in v0.200.0

type CreatePlacementPolicyStatement = *ast.CreatePlacementPolicyStmt

type CreateSequenceStatement added in v0.200.0

type CreateSequenceStatement = *ast.CreateSequenceStmt

type CreateTableStatement added in v0.15.0

type CreateTableStatement = *ast.CreateTableStmt

type CreateUserStatement added in v0.200.0

type CreateUserStatement = *ast.CreateUserStmt

type CreateViewStatement added in v0.15.0

type CreateViewStatement = *ast.CreateViewStmt

type DeleteStatement added in v0.15.0

type DeleteStatement = *ast.DeleteStmt

type DropIndexStatement added in v0.15.0

type DropIndexStatement = *ast.DropIndexStmt

type DropPlacementPolicyStatement added in v0.200.0

type DropPlacementPolicyStatement = *ast.DropPlacementPolicyStmt

type DropProcedureStatement added in v0.200.0

type DropProcedureStatement = *ast.DropProcedureStmt

type DropResourceGroupStatement added in v0.200.0

type DropResourceGroupStatement = *ast.DropResourceGroupStmt

type DropSequenceStatement added in v0.200.0

type DropSequenceStatement = *ast.DropSequenceStmt

type DropTableStatement added in v0.15.0

type DropTableStatement = *ast.DropTableStmt

type DropUserStatement added in v0.200.0

type DropUserStatement = *ast.DropUserStmt

type EffectCandidate added in v0.410.0

type EffectCandidate struct {
	Kind                      EffectCandidateKind
	Ordinal                   int
	NamePath                  []string
	OriginalNamePath          []string
	ExplicitSchema            bool
	IsQuoted                  bool
	Canonical                 bool
	Ambiguous                 bool
	ParserClassification      string
	UnqualifiedRelation       bool
	Arity                     int
	OperandKinds              []OperandKindHint
	OperandColumnRefs         []OperandColumnRef
	IsAggregate               bool
	HasWindow                 bool
	HasFilter                 bool
	HasDistinct               bool
	HasAggOrder               bool
	HasWithinGroup            bool
	HasFrame                  bool
	HasNamedWindow            bool
	HasWindowPartition        bool
	HasWindowOrder            bool
	WindowPartitionKinds      []OperandKindHint
	WindowOrderKinds          []OperandKindHint
	WindowFrameKinds          []OperandKindHint
	WindowPartitionColumnRefs []OperandColumnRef
	WindowOrderColumnRefs     []OperandColumnRef
	TargetTypePath            []string
}

type EffectCandidateKind added in v0.410.0

type EffectCandidateKind string
const (
	EffectCandidateOperator EffectCandidateKind = "operator"
	EffectCandidateFunction EffectCandidateKind = "function"
	EffectCandidateCast     EffectCandidateKind = "cast"
	EffectCandidateUnknown  EffectCandidateKind = "unknown"
)

type ExtractedStatement added in v0.15.0

type ExtractedStatement struct {
	Kind      spec.Kind
	RawSQL    string
	Extractor spec.StatementExtractor
}

ExtractedStatement is the adapter-owned parser result used by the application layer.

func WrapStatements added in v0.15.0

func WrapStatements(stmts []ast.StmtNode, warnings []string) []ExtractedStatement

type GrantStatement added in v0.200.0

type GrantStatement = *ast.GrantStmt

type InsertStatement added in v0.15.0

type InsertStatement = *ast.InsertStmt

type OperandColumnRef added in v0.410.0

type OperandColumnRef struct {
	Schema string
	Table  string
	Column string
}

type OperandKindHint added in v0.410.0

type OperandKindHint string
const (
	OperandKindColumn   OperandKindHint = "column"
	OperandKindConst    OperandKindHint = "const"
	OperandKindParam    OperandKindHint = "param"
	OperandKindStar     OperandKindHint = "star"
	OperandKindExpr     OperandKindHint = "expr"
	OperandKindSubquery OperandKindHint = "subquery"
	OperandKindUnknown  OperandKindHint = "unknown"
)

type OutputFact added in v0.380.0

type OutputFact struct {
	Name    string   `json:"name"`
	Sources []string `json:"sources"`
}

type Parser

type Parser struct{}

Parser adapts TiDB parser behavior for DeltaScope.

func New

func New() *Parser

New returns a TiDB-backed parser adapter.

func (*Parser) Parse

func (p *Parser) Parse(ctx context.Context, sql string) (Result, error)

Parse parses SQL text into TiDB statements and preserves parser warnings.

type ProcedureInfoStatement added in v0.200.0

type ProcedureInfoStatement = *ast.ProcedureInfo

type QueryAccessExtractor added in v0.380.0

type QueryAccessExtractor struct{}

func (*QueryAccessExtractor) ExtractQueryAccess added in v0.380.0

func (e *QueryAccessExtractor) ExtractQueryAccess(ctx context.Context, sql string, dialect string, defaultSchema string) (*QueryAccessFacts, error)

type QueryAccessFacts added in v0.380.0

type QueryAccessFacts struct {
	ReadClassification string            `json:"read_classification"`
	Relations          []RelationFact    `json:"relations,omitempty"`
	ColumnReferences   []ColumnFact      `json:"column_references,omitempty"`
	Outputs            []OutputFact      `json:"outputs,omitempty"`
	Unresolved         []UnresolvedFact  `json:"unresolved,omitempty"`
	ReasonCodes        []string          `json:"reason_codes,omitempty"`
	EffectCandidates   []EffectCandidate `json:"-"`
}

type RelationFact added in v0.380.0

type RelationFact struct {
	Schema string `json:"schema,omitempty"`
	Name   string `json:"name"`
	Alias  string `json:"alias,omitempty"`
	Kind   string `json:"kind"`
}

type RenameTableStatement added in v0.15.0

type RenameTableStatement = *ast.RenameTableStmt

type Result

type Result struct {
	Statements []ast.StmtNode
	Warnings   []string
}

Result is the infrastructure output of the parser adapter.

type RevokeStatement added in v0.200.0

type RevokeStatement = *ast.RevokeStmt

type StatementNode added in v0.15.0

type StatementNode = ast.StmtNode

type TruncateTableStatement added in v0.15.0

type TruncateTableStatement = *ast.TruncateTableStmt

type UnresolvedFact added in v0.380.0

type UnresolvedFact struct {
	Reference string `json:"reference"`
	Reason    string `json:"reason"`
}

type UpdateStatement added in v0.15.0

type UpdateStatement = *ast.UpdateStmt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL