Preserve index prefix lengths and order in SHOW CREATE TABLE primary keys - #500
Preserve index prefix lengths and order in SHOW CREATE TABLE primary keys#500samuelmbabhazi wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe table-definition generator now uses shared formatting for primary and secondary index columns. The formatter preserves column names, prefix lengths, and descending order. Metadata tests cover single-column and composite primary keys. ChangesMySQL-on-SQLite metadata
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized change preserves primary-key prefix lengths and descending order in generated table definitions, preventing invalid exports while leaving other index formatting unchanged. No actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment |
9e45b6e to
ae52afd
Compare
Summary
SHOW CREATE TABLEreconstructs thePRIMARY KEYclause from the information schema, but unlike the branch that handles all other indexes, it emitted only the quoted column names. Index prefix lengths (SUB_PART) and descending order (COLLATION = 'D') were dropped, so a table created withPRIMARY KEY (session_id(100))on aMEDIUMTEXTcolumn came back asPRIMARY KEY (session_id).The practical impact: exports built on top of
SHOW CREATE TABLE(for examplewp sqlite export, which WordPress Studio uses for its push feature) produce a dump that MySQL rejects withERROR 1170 (42000): BLOB/TEXT column used in key specification without a key length. The prefix is recorded correctly in_wp_sqlite_mysql_information_schema_statistics(SUB_PART = 100); the bug was emission only. Discovered through Automattic/studio#4739.Fixes #501
Fix
The column formatting closure that already handled
SUB_PARTandDESCfor regular keys is hoisted and shared by thePRIMARY KEYbranch, so both paths emit identical column definitions.Testing
PRIMARY KEY (session_id(100))onMEDIUMTEXTround-trips throughSHOW CREATE TABLEwith its prefix, a composite keyPRIMARY KEY (a, b(50))keeps the prefix only where defined, andPRIMARY KEY (a DESC, b)keeps its descending key part. The test fails on the previous code.SHOW CREATE TABLEemitsPRIMARY KEY (session_id(100))andPRIMARY KEY (aDESC,b)for the same tables, matching the fixed output; the previous output fails to import there withERROR 1170, the fixed output imports cleanly.mysql-on-sqliteunit suite: 875 tests, 1428750 assertions, no failures (the same 17 skipped and 2 incomplete as on trunk, PHP 8.5).composer run check-csis clean on both changed files.Summary by CodeRabbit
SHOW CREATE TABLEoutput to preserve primary-key index prefix lengths for single-column and composite keys.