Review and plan solution for GitHub issue#2756
Conversation
Summary of ChangesHello @robfrank, 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 resolves a critical bug in DELETE statement execution where queries containing multiple OR conditions could lead to incomplete data deletion. Previously, the query planner would silently drop OR branches that couldn't be optimized by an index, resulting in only a subset of matching records being deleted. The fix ensures that if any OR condition cannot leverage an index, the system correctly falls back to a full table scan, guaranteeing that all specified conditions are evaluated and all intended records are deleted. Comprehensive test cases have been added to verify the correctness of this behavior. Highlights
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
This is an excellent pull request that addresses a critical bug where parts of a DELETE statement with OR conditions were silently ignored. The root cause analysis is spot-on, and the fix is correct and clean. I particularly appreciate the detailed problem description and the inclusion of two comprehensive test cases that cover scenarios both with and without indexes, ensuring the fix is robust. I have one minor suggestion for a code cleanup.
engine/src/main/java/com/arcadedb/query/sql/executor/SelectExecutionPlanner.java
Outdated
Show resolved
Hide resolved
🧪 CI InsightsHere's what we observed from your CI run for 61fb84a. 🟢 All jobs passed!But CI Insights is watching 👀 |
623f366 to
b5fe173
Compare
…st match
Problem:
When executing a DELETE statement with multiple OR conditions (e.g.,
(A AND B) OR (C AND D) OR (E AND F)), only records matching the FIRST
OR branch were deleted. The remaining OR branches were silently ignored.
Root Cause:
In SelectExecutionPlanner.handleTypeAsTargetWithIndex(), when processing
flattened WHERE clauses (one AndBlock per OR branch), the code attempted
to optimize each branch using indexes via findBestIndexFor(). However,
it used .filter(Objects::nonNull) to remove branches that couldn't be
optimized, causing those branches to be silently dropped from execution.
This meant:
- If branch 1 could use an index → executed
- If branches 2-6 couldn't use indexes → silently dropped
- Result: only 1 record deleted instead of 6
Fix:
Changed the logic to check if ANY OR branch cannot be optimized with
an index. If so, fall back to a full table scan with WHERE clause
filtering instead of silently dropping branches. This ensures ALL
OR conditions are evaluated.
The fix changes:
.filter(Objects::nonNull) // REMOVES null entries
.collect(Collectors.toList());
to:
.collect(Collectors.toList());
if (indexSearchDescriptors.contains(null)) // CHECK for nulls
return null; // Fall back to full scan
Testing:
Added two comprehensive test cases:
1. testDeleteWithMultipleOrConditions - tests without indexes
2. testDeleteWithMultipleOrConditionsAndIndex - tests with indexes
Both verify that all 6 records matching different OR branches are
deleted, not just the first one.
b5fe173 to
6ddc42d
Compare
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
…ctExecutionPlanner
…st match
Problem:
When executing a DELETE statement with multiple OR conditions (e.g., (A AND B) OR (C AND D) OR (E AND F)), only records matching the FIRST OR branch were deleted. The remaining OR branches were silently ignored.
Root Cause:
In SelectExecutionPlanner.handleTypeAsTargetWithIndex(), when processing flattened WHERE clauses (one AndBlock per OR branch), the code attempted to optimize each branch using indexes via findBestIndexFor(). However, it used .filter(Objects::nonNull) to remove branches that couldn't be optimized, causing those branches to be silently dropped from execution.
This meant:
Fix:
Changed the logic to check if ANY OR branch cannot be optimized with an index. If so, fall back to a full table scan with WHERE clause filtering instead of silently dropping branches. This ensures ALL OR conditions are evaluated.
The fix changes:
.filter(Objects::nonNull) // REMOVES null entries
.collect(Collectors.toList());
to:
.collect(Collectors.toList());
if (indexSearchDescriptors.contains(null)) // CHECK for nulls
return null; // Fall back to full scan
Testing:
Added two comprehensive test cases:
Both verify that all 6 records matching different OR branches are deleted, not just the first one.
What does this PR do?
A brief description of the change being made with this pull request.
Motivation
What inspired you to submit this pull request?
Related issues
A list of issues either fixed, containing architectural discussions, otherwise relevant
for this Pull Request.
Additional Notes
Anything else we should know when reviewing?
Checklist
mvn clean packagecommand