Repository navigation
fix(gosqlx): don't report SELECT aliases used in ORDER BY/HAVING as columns (#849) - #865
Conversation
…olumns (#849) ExtractColumns and ExtractColumnsQualified listed a SELECT-list alias as a column whenever ORDER BY or HAVING referenced it. The collector now builds the alias set of each SELECT (lazily, only when it has ORDER BY/HAVING and aliases) and skips unqualified matches in that SELECT's ORDER BY and HAVING. Every SELECT starts a fresh scope, so aliases never cross subquery, CTE or UNION boundaries; qualified references always remain columns. Example_analyzeQuery now reports 7 columns: total_spent is an alias. Implemented with Codex (gpt-6.1-sol), reviewed and benchmarked here: no allocation change without aliases; ExtractTables/ExtractColumns timing unchanged within noise (benchstat p>0.7, n=12). Fixes #849 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RkzVu3JY9Y6BRWfjesWts9
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
Claude finished @ajitpratap0's task in 26s —— View job Review of PR #865: SELECT aliases in ORDER BY/HAVINGI read the diff only. I did not run the tests or the linter, and the PR description says Summary: The fix is correct and well scoped. Scoping is per What looks good
Suggestions (non-blocking)
The Verdict: Approve once you've considered suggestion 1. The rest is optional. |
|
Claude finished @ajitpratap0's task in 18s —— View job Review of PR #865: SELECT aliases in ORDER BY/HAVINGI read the diff of Verdict: The fix is correct and well scoped. I found no blocking issues. What looks good
Suggestions (non-blocking)
The |
Summary
ExtractColumns/ExtractColumnsQualifiedlisted a SELECT-list alias as a column wheneverORDER BYorHAVINGreferenced it (e.g.COUNT(o.id) AS orders ... ORDER BY ordersreportedorders). This also affected the MCPextract_metadata/analyze_sqltools and the ChatGPT widget.The collector now builds each SELECT's alias set (lazily, only when the SELECT has
ORDER BY/HAVINGand aliases) and skips unqualified matches in that SELECT'sORDER BYandHAVING. EverySelectStatementstarts a fresh scope, so aliases never cross subquery, CTE or UNION boundaries; qualified references (t.total) always stay columns. Names match case-insensitively, like unquoted identifiers.Example_analyzeQuerynow reports 7 columns instead of 8 (total_spentis an alias).Implemented with Codex (gpt-6.1-sol) in an isolated worktree; reviewed, gated and benchmarked here.
Test Plan
extract_alias_test.go: 19 cases for both extractors (the issue's table, qualified refs, subquery/CTE/UNION scoping both directions, aliases inside ORDER BY expressions, HAVING mixing aliases and real columns), race-cleantask check: EXIT=0 (fmt, vet, golangci-lint 0 issues, full race suite incl. MCP)Breaking Changes
None to the API. Callers of
ExtractColumns/ExtractMetadatano longer see aliases listed as columns.Fixes #849
🤖 Generated with Claude Code
https://claude.ai/code/session_01RkzVu3JY9Y6BRWfjesWts9