fix: resolve NOTUNIQUE index issue with equals operator in large data…#2859
fix: resolve NOTUNIQUE index issue with equals operator in large data…#2859
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 addresses a critical bug affecting the equality operator on NOTUNIQUE string indexes within large datasets. The fix ensures that exact matches are correctly retrieved after index creation and compaction by using the appropriate index lookup method. A new, robust regression test has been introduced to validate the solution and prevent future regressions, particularly in scenarios involving hierarchical compaction. 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
|
🧪 CI InsightsHere's what we observed from your CI run for b5de1d4. 🟢 All jobs passed!But CI Insights is watching 👀 |
There was a problem hiding this comment.
Code Review
This pull request addresses a critical bug where the = operator on NOTUNIQUE string indexes fails on large datasets. The fix in FetchFromIndexStep.java, which replaces index.range(...) with the more appropriate index.get(...) for equality checks, is correct and directly solves the issue. The addition of a comprehensive regression test in Issue2757NotUniqueIndexEqualsOperatorTest.java is excellent for ensuring this bug does not recur. However, I've found an issue in the test's waitForIndexCompaction method that prevents it from waiting as intended, potentially making the test less reliable. My review includes a suggestion to fix this.
| .until(() -> { | ||
| try { | ||
| database.transaction(() -> { | ||
| // Try to query to see if index is usable | ||
| final Index[] indexes = database.getSchema().getIndexes(); | ||
| for (final Index index : indexes) { | ||
| if (index instanceof TypeIndex) | ||
| continue; | ||
| // Just verify the index exists and is accessible | ||
| assertThat(index).isNotNull(); | ||
| } | ||
| }); | ||
| return true; | ||
| } catch (Exception e) { | ||
| // Retry on any exception - index may still be compacting | ||
| return false; | ||
| } | ||
| }); |
There was a problem hiding this comment.
The current implementation of waitForIndexCompaction doesn't seem to work as intended. The loop over indexes explicitly skips TypeIndex instances. Since this test creates a TypeIndex, the loop body is never executed, and the method returns immediately without waiting. This means the test might not be correctly verifying the behavior after index compaction.
To reliably wait for the index to be ready, I suggest replacing the current logic with a periodic query attempt. An exception during the query would indicate the index is still being compacted.
.until(() -> {
try {
database.transaction(() -> {
// Try to execute a query that uses the index. If it throws an exception,
// it means the index is not ready yet (e.g. compacting).
try (ResultSet rs = database.query("sql", "SELECT FROM " + TYPE_NAME + " WHERE title = ?", TEST_TITLES[0])) {
rs.hasNext(); // Force execution
}
});
return true;
} catch (Exception e) {
// Retry on any exception - index may still be compacting
return false;
}
});
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 |
This pull request addresses a critical bug where the
=operator on NOTUNIQUE string indexes fails to return correct results on large datasets after index creation and compaction. The main fix changes how the index is queried for equality, and a comprehensive regression test is added to ensure the issue is resolved and does not recur.Bug Fixes:
FetchFromIndexStep.javato useindex.get(values)instead ofindex.range(...), ensuring correct results for exact matches on NOTUNIQUE indexes after compaction.Testing Improvements:
Issue2757NotUniqueIndexEqualsOperatorTest.javathat:=operator correctly finds records before and after index creation and compaction.LIKEoperator is unaffected.