Skip to content

feat(tidb): scope qualified column completion to the matching table#161

Merged
vsai12 merged 2 commits into
mainfrom
feat/tidb-completion-qualifier-scope
May 29, 2026
Merged

feat(tidb): scope qualified column completion to the matching table#161
vsai12 merged 2 commits into
mainfrom
feat/tidb-completion-qualifier-scope

Conversation

@vsai12
Copy link
Copy Markdown
Contributor

@vsai12 vsai12 commented May 29, 2026

What

Scope qualified column completion to the table named by the qualifier. resolveColumnRefScoped previously 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 b suggested t2's columns under a.
  • SELECT t1.| FROM t1 JOIN t2 suggested t2's columns under t1.

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 whose Alias or Table matches 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_QualifiedColumnScopedToQualifier covers 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/... and go vet ./tidb/... pass.

vsai12 and others added 2 commits May 28, 2026 21:38
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 vsai12 merged commit 6531f7b into main May 29, 2026
2 checks passed
@vsai12 vsai12 deleted the feat/tidb-completion-qualifier-scope branch May 29, 2026 04:50
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant