Fix MySQL autocomplete in multi-database setups#184
Open
Conversation
Two bugs surfaced by driving the TUI's completion engine against a real
MySQL server with multiple user databases:
1. Qualified table/view names rendered as `db`.``.`table`. MySQL has no
schema-within-database, so the schema slot comes back as ''; the
inline name-builder inserted it unconditionally, producing a
three-part identifier with an empty middle. Promote the composition
rule to a new `Dialect.qualified_name(database, schema, name)`
method. Base default skips empty segments, which yields the correct
result for every current adapter:
MySQL/MariaDB: `db`.`table`
PostgreSQL: "schema"."table"
SQL Server: [db].[schema].[table]
SQLite: "table"
Autocomplete's four inline builders (tables/views × sync/async
loader) now call `dialect.qualified_name(...)` directly.
2. Completions stuck on "Loading..." for cursor positions like
`SELECT * FROM shop.cu`. The completion engine classifies this as
an ALIAS_COLUMN with scope 'shop', which isn't a real table. The
loader skips unknown keys silently; the caller kept returning
Loading... forever because the guard assumed "not yet loaded" meant
"in flight". Guard the sentinel on the table key actually existing
in `_table_metadata`.
Covered by 8 new unit tests pinning `qualified_name` on MySQL,
MariaDB, PostgreSQL, SQL Server, empty-segment behavior, quote-char
escaping, and the stuck-Loading regression.
May fix #151.
b70acf4 to
a3a28dc
Compare
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 #151.
Surfaced two bugs by stress-testing autocomplete against a real MySQL 5.7 container with two user databases, across seven cursor positions per scenario.
Bug 1 — malformed qualified names in multi-db mode:
Tables rendered as
`inventory`..shipments`` — an empty-backticked schema slot between db and table. MySQL has no schema-within-database, so the schema string is""; the inline name-builder inserted it unconditionally. Factored a `_qualify_table_name` helper that skips empty segments; routed all four call sites (tables/views × sync/async loader) through it.Bug 2 — autocomplete wedged on
Loading...for schema-qualified partials:Typing
SELECT * FROM shop.cuparsesshopas an ALIAS_COLUMN scope. That key isn't in_table_metadata, so_load_columns_for_table('shop')skips silently — but the suggestion engine had already returned theLoading...sentinel, and kept returning it on every subsequent call. Guard the sentinel on the table key actually existing in metadata.Matrix results (before → after) for the worst scenario (no default database, two user DBs indexed):
FROM`inventory`..shipments``, …`inventory`.`shipments`, …FROM shop.['Loading...']forevercustomers,orders,productsFROM shop.cu['Loading...']forever`shop`.`customers`FROM inventory.wa['Loading...']forever`inventory`.`warehouses`FROM customers WHERE ememail, … (already ok)email, … (unchanged)7 new unit tests pin the name-builder across dialects (MySQL-style no schema, Postgres-style schema-only, SQL Server-style db+schema, both empty, embedded backticks) and the stuck-Loading regression. Full unit suite 823 tests green.