Skip to content

fix: resolve NOTUNIQUE index issue with equals operator in large data…#2859

Merged
robfrank merged 2 commits intomainfrom
fix/2757-notunique-index-equals-operator
Dec 4, 2025
Merged

fix: resolve NOTUNIQUE index issue with equals operator in large data…#2859
robfrank merged 2 commits intomainfrom
fix/2757-notunique-index-equals-operator

Conversation

@robfrank
Copy link
Collaborator

@robfrank robfrank commented Dec 3, 2025

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:

  • Changed the equality operator logic in FetchFromIndexStep.java to use index.get(values) instead of index.range(...), ensuring correct results for exact matches on NOTUNIQUE indexes after compaction.

Testing Improvements:

  • Added a new regression test Issue2757NotUniqueIndexEqualsOperatorTest.java that:
    • Reproduces the bug by creating a large dataset and adding a NOTUNIQUE index after data insertion.
    • Verifies that the = operator correctly finds records before and after index creation and compaction.
    • Confirms that the LIKE operator is unaffected.
    • Waits for index compaction to ensure the test covers the problematic scenario.

@robfrank robfrank added this to the 25.11.1 milestone Dec 3, 2025
@robfrank robfrank added the bug label Dec 3, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Bug Fix: NOTUNIQUE Index Equality Operator: The core issue where the = operator on NOTUNIQUE string indexes failed to return correct results on large datasets after index creation and compaction has been resolved. The fix involves changing the index query logic from index.range(...) to index.get(values) for equality comparisons in FetchFromIndexStep.java.
  • New Regression Test: A comprehensive regression test, Issue2757NotUniqueIndexEqualsOperatorTest.java, has been added. This test specifically reproduces the bug by creating a large dataset, adding a NOTUNIQUE index, and verifying that the = operator now correctly finds records both before and after index creation and compaction. It also confirms that the LIKE operator remains unaffected.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@robfrank robfrank linked an issue Dec 3, 2025 that may be closed by this pull request
@mergify
Copy link
Contributor

mergify bot commented Dec 3, 2025

🧪 CI Insights

Here's what we observed from your CI run for b5de1d4.

🟢 All jobs passed!

But CI Insights is watching 👀

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +171 to +188
.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;
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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;
          }
        });

@codacy-production
Copy link

codacy-production bot commented Dec 3, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.55% 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (1c12f84) 70174 46273 65.94%
Head commit (b5de1d4) 70174 (+0) 45884 (-389) 65.39% (-0.55%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#2859) 1 1 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@robfrank robfrank merged commit 9c66952 into main Dec 4, 2025
19 of 22 checks passed
@robfrank robfrank deleted the fix/2757-notunique-index-equals-operator branch December 4, 2025 09:10
robfrank added a commit that referenced this pull request Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating NOTUNIQUE String Index on Large Dataset Breaks = Operator

1 participant