Skip to content

Conversation

@LimarDeWills
Copy link

Fixes #66
Problem description:

When executing a query with ORDER BY col1, col2 using a RUM index, and the WHERE clause matches only a subset of the index, the query may enter an infinite loop in scanGetItemFast().

This occurs because entry->curItem is set via entry->curItem = collected.item;, but the corresponding entry->offset does not point to that item in entry->list. As a result, entryFindItem() may prematurely exit without correcting curItem, leading to repeated processing of the same item.
Fix:

Added an extra check in entryFindItem() that ensures:

curItem >= item

offset is within valid range

entry->curItem.iptr == entry->list[offset].iptr

If the last condition fails, the function continues scanning the list to realign curItem and offset.

This ensures scanGetItemFast() progresses correctly and prevents infinite looping.

@LimarDeWills LimarDeWills force-pushed the PGPRO-11557-fix-orderby-loop branch from b548636 to 74b4070 Compare April 28, 2025 10:08
@LimarDeWills LimarDeWills force-pushed the PGPRO-11557-fix-orderby-loop branch from 74b4070 to 337b60e Compare April 28, 2025 11:46
@sokolcati sokolcati merged commit 6c954ab into postgrespro:master May 30, 2025
1 check passed
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.

SQL statement runs infinitely

2 participants