phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

PHOENIX-7524: Fix IndexOutOfBoundsException in queries with OFFSET when rows are exhausted

Open TheNamesRai opened this issue 2 months ago • 2 comments

PHOENIX-7524: Fix IndexOutOfBoundsException in queries with OFFSET when rows are exhausted

Design doc - link

When executing queries with OFFSET where the available rows are exhausted:

  • OFFSET exceeds the total number of rows in the table, OR
  • OFFSET exceeds rows returned by WHERE clause (even when WHERE matches some rows), OR
  • WHERE clause filters all rows, OR
  • Table/region is empty

The server-side scanner would encounter an empty tuple after exhausting all available rows and attempt to call getOffsetKvWithLastScannedRowKey(), which internally calls tuple.getKey(). This caused IndexOutOfBoundsException in MultiKeyValueTuple.getKey() when accessing an empty tuple.

Solution - Added a check in NonAggregateRegionScannerFactory.java to detect empty tuples before calling getOffsetKvWithLastScannedRowKey()

Modified Files:

  • NonAggregateRegionScannerFactory.java
    • Added empty tuple check before accessing tuple.getKey()
    • Implemented fallback logic to derive appropriate row key from scan boundaries

Test Files:

  • QueryWithOffsetIT.java
    • Added 5 comprehensive integration tests covering various scenarios where OFFSET exceeds available rows
  • CDCQueryIT.java
    • Added CDC-specific test for OFFSET exceeding available rows

TheNamesRai avatar Oct 22 '25 16:10 TheNamesRai

Some test failures seem relevant to new test? https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-2307/1/testReport/junit/org.apache.phoenix.end2end/CDCQueryIT/testCDCQueryWithOffsetExceedingRows_forView_false__encodingScheme_NON_ENCODED_QUALIFIERS__multitenant_true__tableSaltBuckets_2__withSchemaName_true__caseSensitiveNames_false_/

virajjasani avatar Oct 23 '25 04:10 virajjasani

Some test failures seem relevant to new test? https://ci-hadoop.apache.org/job/Phoenix/job/Phoenix-PreCommit-GitHub-PR/job/PR-2307/1/testReport/junit/org.apache.phoenix.end2end/CDCQueryIT/testCDCQueryWithOffsetExceedingRows_forView_false__encodingScheme_NON_ENCODED_QUALIFIERS__multitenant_true__tableSaltBuckets_2__withSchemaName_true__caseSensitiveNames_false_/

@virajjasani , Updated the test in CDCQueryIT

TheNamesRai avatar Oct 23 '25 10:10 TheNamesRai