Support the MySQL spatial types, SRID attribute, SPATIAL constraint, and CHAR/VARCHAR attributes - #42
Merged
Merged
Conversation
…nstraint Implement the spatial pieces of the MySQL type system, which postdate the goyacc grammar (TiDB never supported spatial data): - The spatial column data types (MySQL 26.7 §13.4.1): GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, and GEOMETRYCOLLECTION, with GEOMCOLLECTION lexing as its GEOMETRYCOLLECTION synonym via the aliases table (the DEC → DECIMAL precedent). MySQL reports every spatial column as type byte 0xff on the wire, so the subtypes get parser-only type bytes 0xe2–0xe8 following the TypeTiDBVectorFloat32 precedent; spatial FieldTypes carry the binary charset, like JSON. - The SRID column attribute (§13.1.20.10): new ColumnOptionSrid with the value in a new ColumnOption.UintValue field. - The SPATIAL [INDEX | KEY] table constraint (§15.1.20) in CREATE TABLE and ALTER TABLE ... ADD, mirroring the FULLTEXT alternative with a new ConstraintSpatial that restores canonically as SPATIAL; CREATE SPATIAL INDEX already parsed. - CAST/CONVERT to the spatial types (§14.10, castable since MySQL 8.0.24), with RestoreAsCastType coverage. The ast and types changes are backwards-compatible: appended enum values, a new ColumnOption field, and new type-byte map entries. Keyword tables: GEOMETRY, GEOMETRYCOLLECTION, LINESTRING, MULTILINESTRING, MULTIPOINT, MULTIPOLYGON, POLYGON, and SRID become unreserved keywords, matching their MySQL 26.7 classification (POINT already was); TestKeywordsLength counts updated accordingly. testdata/errors.json is unaffected. The new file-driven test group spatial_types covers the types, SRID, the constraint forms, casts, and the new keywords in identifier position. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C3dMfdpMyaWffPoh8RBia4
Auditing the MySQL 26.7 data-type chapter (§13) against parseType found no missing type names after the spatial commit, but three missing attribute spellings from §13.3.1: CHAR(5) BYTE (the documented alias for BINARY(5)), VARCHAR(10) ASCII, and VARCHAR(10) UNICODE. The goyacc grammar allowed the ASCII/UNICODE/BYTE attributes only on TEXT, ENUM, SET, and LONG (OptCharsetWithOptBinary); MySQL's grammar gives CHAR and VARCHAR the same attribute set. parseCharTail and parseVarcharTail now parse OptCharsetWithOptBinary instead of OptBinary — a superset whose default alternative is OptBinary, so every previously accepted spelling parses identically — and normalize the binary charset (spelled BYTE or CHARACTER SET binary) to BinaryFlag plus the binary collation, mirroring the TextType action, so CHAR(5) BYTE produces the same FieldType as parsing its BINARY(5) restore output. UNICODE keeps the historical goyacc semantics: the attribute maps to the ucs2 charset, which is not supported, so it fails with the same "Unknown character set: 'ucs2'" action error TEXT UNICODE has always produced; the new compat_types goldens record that error contract. testdata/errors.json is unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C3dMfdpMyaWffPoh8RBia4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the remaining data-type gaps found by auditing the MySQL 26.7 reference manual's data-type chapter (§13) against
parseType. All of this syntax postdates the goyacc grammar (TiDB never supported spatial data), so the grammar is written from the reference manual, following the precedent of the statement-coverage PRs (#38–#41).Spatial types (§13.4.1)
GEOMETRY,POINT,LINESTRING,POLYGON,MULTIPOINT,MULTILINESTRING,MULTIPOLYGON, andGEOMETRYCOLLECTION, withGEOMCOLLECTIONlexing as itsGEOMETRYCOLLECTIONsynonym via the aliases table (theDEC→DECIMALprecedent).0xffon the wire, so the subtypes get parser-only type bytes0xe2–0xe8following theTypeTiDBVectorFloat32precedent; spatialFieldTypes carry the binary charset, like JSON. This keepsPOINTround-tripping asPOINTinstead of collapsing toGEOMETRY.SRID ncolumn attribute (§13.1.20.10): newColumnOptionSrid, with the value in a newColumnOption.UintValuefield.SPATIAL [INDEX | KEY]table constraint (§15.1.20) inCREATE TABLEandALTER TABLE ... ADD, mirroring theFULLTEXTalternative with a newConstraintSpatial(CREATE SPATIAL INDEXalready parsed).CAST/CONVERTto the spatial types (§14.10, castable since MySQL 8.0.24), withRestoreAsCastTypecoverage.CHAR/VARCHAR attributes (§13.3.1)
The audit found no missing type names beyond spatial, but three missing attribute spellings:
CHAR(5) BYTE(the documented alias forBINARY(5)),VARCHAR(10) ASCII, andVARCHAR(10) UNICODE. The goyacc grammar allowed theASCII/UNICODE/BYTEattributes only on TEXT/ENUM/SET/LONG; MySQL gives CHAR and VARCHAR the same attribute set.parseCharTail/parseVarcharTailnow parseOptCharsetWithOptBinary— a superset whose default alternative isOptBinary, so every previously accepted spelling parses identically — and normalize the binary charset toBinaryFlagplus the binary collation, mirroring the TextType action, soCHAR(5) BYTEproduces the sameFieldTypeas parsing itsBINARY(5)restore output.UNICODEkeeps the historical goyacc semantics: it maps to the unsupported ucs2 charset and fails with the sameUnknown character set: 'ucs2'action errorTEXT UNICODEhas always produced; the goldens record that error contract.Bookkeeping
GEOMETRY,GEOMETRYCOLLECTION,LINESTRING,MULTILINESTRING,MULTIPOINT,MULTIPOLYGON,POLYGON, andSRIDbecome unreserved keywords, matching their MySQL 26.7 classification (POINTalready was);TestKeywordsLengthcounts updated accordingly.astandtypeschanges are backwards-compatible: appended enum values, a newColumnOptionfield, and new type-byte map entries.testdata/errors.jsonis unaffected.spatial_typesfile-driven test group covers the types, SRID, the constraint forms, casts, and the new keywords in identifier position;compat_typesgains the CHAR/VARCHAR attribute cases.🤖 Generated with Claude Code
https://claude.ai/code/session_01C3dMfdpMyaWffPoh8RBia4
Generated by Claude Code