feat(autocomplete): rank columns of nearest table first (closes #507) - #679
feat(autocomplete): rank columns of nearest table first (closes #507)#679adisusilayasa wants to merge 2 commits into
Conversation
| case 'SELECT': | ||
| frame.clause = 'select'; | ||
| frame.isStatement = true; | ||
| frame.awaitingAlias = false; |
There was a problem hiding this comment.
WARNING: Subquery statement scopes leak the outer frame's table refs.
When a subquery is opened by IN ( or a bare (, createFrame builds the frame with isStatement: false and inherits the parent's fromTableRef/currentJoinTableRef/lastTableRef. When SELECT then flips isStatement to true, those inherited refs are not cleared. If the subquery's FROM table has no alias, recordIdentifier's from branch only updates lastTableRef (the else arm), leaving fromTableRef pointing at the outer table. The final resolution fromTableRef ?? lastTableRef then returns the outer ref instead of the subquery's own table.
Repro: analyzeSqlContext('SELECT * FROM orders o WHERE o.id IN (SELECT id FROM users WHERE ').lastTableRef returns 'o' rather than 'users'.
Consider nulling fromTableRef, currentJoinTableRef, and lastTableRef here (and in the other statement-keyword cases: INSERT/UPDATE/DELETE/REPLACE) when the frame newly becomes a statement scope.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Previous Review Summary (commit 1c90484)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 1c90484)Status: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (4 files)
Reviewed by glm-5.2 · Input: 39.3K · Output: 13.2K · Cached: 385.5K |
|
Fixed in 46f288a: cleared |
Problem
Follow-up to #505 / closes #507. When multiple tables are in scope, all their columns were given the same
0_<name>sortText prefix. In anONclause or afterWHERE, columns from the table being joined or the primary FROM table were mixed in alphabetical order with all other in-scope tables.Solution
lastTableRefinanalyzeSqlContext:ON/USINGclauses: captures the table/alias being joined right now.WHERE/SELECT/SETclauses: defaults to the primaryFROMtable.sortText: "0_0_<col>", while columns from other tables receivesortText: "0_1_<col>".sortText: "0_<col>".Tests
tests/utils/sqlContext.test.tsforlastTableRefexposure across single/multi-table FROMs, aliases, schema-qualified tables, JOIN chains, subqueries, UPDATE, and INSERT INTO.tests/utils/autocomplete.test.tsverifying that nearest table columns sort before other tables inONandWHEREclauses.