Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

Summary

This PR continues the MySQL AST formatting work with several improvements:

New AST Nodes

  • VariableExpr - MySQL user variables (@var), distinct from sqlc's @param syntax
  • IntervalExpr - MySQL INTERVAL expressions
  • OnDuplicateKeyUpdate - MySQL ON DUPLICATE KEY UPDATE clause
  • ParenExpr - Explicit parentheses for expression grouping

DELETE with JOIN Support

  • Extended DeleteStmt with Targets and FromClause fields
  • Multi-table DELETE now properly formats: DELETE t1.*, t2.* FROM t1 JOIN t2 ON ...
  • Updated compiler/output_columns.go to handle new structure for table resolution

Bug Fixes

  • MySQL @variable now preserved as-is in output (not treated as sqlc named parameter)
  • Column type lengths only output for types where meaningful (varchar, char) - fixes datetime(39) issue
  • Fixed sqlc.arg() handling in ON DUPLICATE KEY UPDATE clause by adding field to rewrite traversal

Documentation

Added CLAUDE.md files documenting key packages:

  • internal/sql/ast/ - AST nodes and formatting
  • internal/sql/astutils/ - Walk and Apply functions
  • internal/sql/named/ - Named parameter detection
  • internal/sql/rewrite/ - Parameter rewriting
  • internal/engine/dolphin/ - MySQL/TiDB conversion patterns

Test plan

  • All TestFormat tests pass (including previously failing delete_join tests)
  • All TestReplay tests pass
  • No regressions in existing functionality

🤖 Generated with Claude Code

This PR continues the MySQL AST formatting work with several improvements:

**New AST Nodes:**
- `VariableExpr` - MySQL user variables (@var), distinct from sqlc @param
- `IntervalExpr` - MySQL INTERVAL expressions
- `OnDuplicateKeyUpdate` - MySQL ON DUPLICATE KEY UPDATE clause
- `ParenExpr` - Explicit parentheses for expression grouping

**DELETE with JOIN Support:**
- Extended DeleteStmt with Targets and FromClause fields
- Multi-table DELETE now properly formats: DELETE t1.*, t2.* FROM t1 JOIN t2...
- Updated compiler/output_columns.go to handle new structure

**Bug Fixes:**
- MySQL @variable now preserved as-is (not treated as sqlc named parameter)
- Column type lengths only output for types where meaningful (varchar, char)
- Fixed sqlc.arg() handling in ON DUPLICATE KEY UPDATE clause

**Documentation:**
- Added CLAUDE.md files documenting AST, astutils, named, rewrite packages
- Added CLAUDE.md for dolphin engine with conversion patterns

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. 🔧 golang labels Nov 30, 2025
@kyleconroy kyleconroy merged commit a9f7eae into main Nov 30, 2025
13 checks passed
@kyleconroy kyleconroy deleted the kyle/mysql-ast-format-improvements branch November 30, 2025 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files. 🔧 golang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants