feat: Add @join:unique and @join:required hints for safe join removal#91
feat: Add @join:unique and @join:required hints for safe join removal#91stevehansen merged 3 commits intomainfrom
Conversation
Introduce SQL comment-based join cardinality hints that let view authors declare whether a join follows a foreign key (unique match) and whether that FK is required (NOT NULL). The tool uses these hints combined with the join type to determine if removal is safe: - LEFT JOIN + @join:unique → safe (at most 1 match, all rows preserved) - INNER JOIN + @join:unique + @join:required → safe (exactly 1 match) - INNER JOIN + @join:unique (no @required) → not safe (may filter rows) - No hint → backward-compatible existing behavior Hints are placed as SQL comments near the JOIN clause: LEFT JOIN /* @join:unique */ dbo.B b ON a.BId = b.Id INNER JOIN /* @join:unique @join:required */ dbo.Status s ON s.Id = p.StatusId https://claude.ai/code/session_01QmAhVuiQRDaotn1cAXBbrJ
Summary of ChangesHello @stevehansen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the SQL inliner tool by providing a mechanism for view authors to explicitly guide the safe removal of unused joins. By embedding specific hints within SQL comments, the inliner can now make more informed decisions about which joins can be stripped without affecting the query's row count or semantics, leading to potentially more optimized SQL output. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request introduces a valuable feature by allowing SQL comment-based join cardinality hints (@join:unique and @join:required). This enables the inliner to make more intelligent decisions about safely stripping unused joins, preventing potential data changes. The implementation includes comprehensive test cases covering various scenarios, and the logic for parsing hints and determining join removal safety appears robust and well-considered. The JoinHint enum is appropriately defined as a [Flags] enum with clear documentation. Overall, this is a well-executed enhancement that improves the utility and safety of the SQL inliner.
Move "@join:unique" and "@join:required" strings to JoinHintMarkers static class so they're defined once and referenceable. https://claude.ai/code/session_01QmAhVuiQRDaotn1cAXBbrJ
Cover additional scenarios: - @required without @unique (fan-out possible, kept) - RIGHT JOIN + @unique (not handled as safe, kept) - Single-line comment syntax (-- @join:unique) - AggressiveJoinStripping respects hints (INNER+@unique kept) - AggressiveJoinStripping strips when hint allows (INNER+@unique+@required) https://claude.ai/code/session_01QmAhVuiQRDaotn1cAXBbrJ
Introduce SQL comment-based join cardinality hints that let view authors
declare whether a join follows a foreign key (unique match) and whether
that FK is required (NOT NULL). The tool uses these hints combined with
the join type to determine if removal is safe:
Hints are placed as SQL comments near the JOIN clause:
LEFT JOIN /* @join:unique / dbo.B b ON a.BId = b.Id
INNER JOIN / @join:unique @join:required */ dbo.Status s ON s.Id = p.StatusId
https://claude.ai/code/session_01QmAhVuiQRDaotn1cAXBbrJ