You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Correctness regression: FK ON suggestions can produce invalid SQL for quoted/reserved column names
In sqlcompleter.py, table names are escaped, but FK column names are stored raw and later interpolated directly in _fk_join_conditions.
Impact: for FK columns like order, user-id, or names requiring backticks, completion returns invalid expressions (e.g. o.order = u.id instead of o.`order` = u.id).
Action: escape col/ref_col when persisting FK metadata (or when building condition strings), consistent with extend_columns() behavior.
Correctness edge case: JOIN prioritization can use FK metadata from the wrong schema
In sqlcompleter.py, FK-priority lookup ignores parsed table schema and keys only by table name.
Impact: for queries joining schema-qualified tables (e.g. other_db.orders), suggestions may be incorrectly prioritized using current-db FK metadata if table names overlap across DBs.
Action: include schema in FK-priority matching, or explicitly skip FK-priority when parsed tables are from a non-current schema.
Missing tests for the above edge cases
New FK tests in test_smart_completion_public_schema_only.py cover happy paths but not identifier escaping or cross-schema JOINs.
Action: add tests for:
FK columns requiring escaping/backticks in ON condition suggestions.
JOIN prioritization when query uses schema-qualified tables outside current DB.
No direct security issues stood out in this PR diff.
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
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.
Description
This PR adds foreign key relationship logic for completions:
Example tables:

Note tables with foreign keys (orders and rosters) showing up first

Foreign key columns showing up after ON to join persons with orders

Same for rosters

Works with aliases as well

No foreign keys, just show the tables as expected

Resolves #975
Checklist
changelog.mdfile.AUTHORSfile (or it's already there).