-
Notifications
You must be signed in to change notification settings - Fork 678
Fix BETWEEN expression rewriting in partial index WHERE clauses #4487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…failing Changed Index::bind_where_expr to return Result<Option<ast::Expr>> instead of Option<ast::Expr> to properly propagate BETWEEN rewriting errors. Updated all call sites to handle the Result. Also fixed typo in error message (optmizer -> optimizer). Co-authored-by: LeMikaelF <22927506+LeMikaelF@users.noreply.github.com>
Added rewrite_between_expr helper function to rewrite BETWEEN expressions without binding columns. Updated emit_partial_index_check to rewrite BETWEEN before rewriting column references to registers. Threaded connection parameter through emit_preflight_constraint_checks and related functions. Co-authored-by: LeMikaelF <22927506+LeMikaelF@users.noreply.github.com>
Added test case to partial_idx.test to verify that BETWEEN expressions in CREATE INDEX WHERE clauses are properly rewritten during both index creation and INSERT operations. This test case is based on the SQLancer-found issue. Co-authored-by: LeMikaelF <22927506+LeMikaelF@users.noreply.github.com>
|
@claude review this PR |
|
Claude finished @LeMikaelF's task in 1m 51s —— View job Reviewing PR
Code Review SummaryOverall Assessment: This PR correctly identifies and fixes the root cause of the BETWEEN expression rewriting issue in partial indexes. The fix is well-structured, but there are a few issues that need attention. Issues Found1. CI Failure: Formatting Check Failed
|
| Category | Status |
|---|---|
| Bug Fix | ✅ Correctly addresses root cause |
| Error Handling | ✅ Improved with proper Result propagation |
| Tests | |
| CI | ❌ Formatting check failing |
| Code Quality | _connection parameter |
Recommendation: Fix the formatting issue and add the original SQLancer test case before merging.
Description
BETWEEN expressions in CREATE INDEX WHERE clauses were not being rewritten during INSERT operations, causing "expression should have been rewritten in optimizer" errors. The issue manifested when inserting into tables with partial indexes like:
Motivation and context
Found by SQLancer fuzzing. The bug occurred because
emit_partial_index_checkconverted column references to registers before rewriting BETWEEN expressions, leaving malformed BETWEEN nodes with Register children that translation couldn't handle.Changes:
rewrite_between_exprhelper (core/translate/expr.rs): Standalone BETWEEN→Binary rewriter that doesn't require table bindingsemit_partial_index_check(core/translate/insert.rs): Now callsrewrite_between_exprbeforerewrite_partial_index_whereIndex::bind_where_exprfromOption<Expr>toResult<Option<Expr>>to propagate errors instead of silently failing with.ok()?bind_where_exprDescription of AI Usage
AI agent (GitHub Copilot) implemented the full fix:
rewrite_between_exprto decouple BETWEEN rewriting from column bindingbind_where_exprto prevent silent failuresCode review and testing validated correctness.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.