feat(tidb): scope qualified column completion to the matching table#161
Merged
Conversation
resolveColumnRefScoped added columns from every in-scope table regardless of the qualifier typed before the dot, so in a multi-table query a.<caret> (or t1.<caret>) suggested columns from all joined tables. Extract the qualifier preceding the dot and restrict resolution to the ref whose alias or table name matches it; unqualified references still use every in-scope table. Found via the bytebase TiDB completion parity audit (bytebase/bytebase#20435, BYT-9599). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… names The qualifier match only considered the table/alias before the dot, so a fully-qualified db1.t. matched any in-scope table named t — including db2.t — when the same table name existed in multiple databases. Capture the optional database part of the qualifier (db1.t. -> db=db1, name=t) and require the ref's database (or the current database, for unqualified table refs) to match it. Adds a regression test for the db1.t. vs db2.t ambiguity. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
vsai12
added a commit
that referenced
this pull request
May 29, 2026
) * fix(tidb): an unknown column qualifier returns no columns, not all resolveColumnRefScoped fell back to all in-scope columns whenever no table matched, so a qualified reference with an unknown qualifier (x., t3., or ghost.t.) broadened to every column instead of narrowing to none. Compute the qualifier first and only fall back to all columns for unqualified references; a qualified reference that matches no table returns no column candidates. Adds unknown-alias / unknown-table / unknown-database negative tests. Follow-up to #161; found via bytebase/bytebase#20435 review (BYT-9599). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(tidb): correct resolveColumnRefScoped fallback comment Reflect that only unqualified references fall back to all columns; a qualified reference with no matching table returns none. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Scope qualified column completion to the table named by the qualifier.
resolveColumnRefScopedpreviously added columns from every in-scope table regardless of the qualifier the user typed before the dot, so in a multi-table query:SELECT a.| FROM t1 AS a JOIN t2 AS bsuggestedt2's columns undera.SELECT t1.| FROM t1 JOIN t2suggestedt2's columns undert1.The fix extracts the qualifier immediately before the dot (
columnQualifier, handling whitespace around the dot and backtick-quoted names) and restricts resolution to the ref whoseAliasorTablematches it (case-insensitive). Unqualified column references still use every in-scope table.Why
Found during the bytebase TiDB auto-completion parity audit (bytebase/bytebase#20435, BYT-9599). The previous mysql ANTLR completer restricted the table set via alias mapping; the omni completer didn't, so qualified column completion in JOINs regressed.
Testing
TestComplete_QualifiedColumnScopedToQualifiercovers alias and table-name qualifiers in a JOIN (only the matching table's columns), plus the unqualified case (all in-scope columns).go test -short ./tidb/...andgo vet ./tidb/...pass.