Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message receive query for SQL Server forces all data pages to be read, even if the table has no rows #1517

Open
SzymonPobiega opened this issue Feb 4, 2025 · 0 comments

Comments

@SzymonPobiega
Copy link
Member

SzymonPobiega commented Feb 4, 2025

Describe the suggested improvement

Is your improvement related to a problem? Please describe.

SQL Server transport uses heap tables in order to optimize the inserts and deletes. The consequence of that design is the fact that the queue table contains much more pages then currently used -- the number reflects the maximum size of the queue table since it has been created (or shrank).

All these pages are part of the table but not actively used. The actively used pages are a subset that forms a linked list.

The assumption was that in this structure the receive query that deletes the record with lowest rowversion value first walks the index on rowversion up to a leaf that points to a page where the row exists and then that page is read. It appears that this is not the actual behavior of the SQL Server as documented below:

Given an empty table with lots of unused pages (Reserved space = 2416KB / 30000 pages) when selecting the oldest row

WITH message AS (
    SELECT TOP(1) *
    FROM {0} WITH (UPDLOCK, READPAST, ROWLOCK)
    ORDER BY RowVersion)
SELECT * FROM message

the entire table is logically read (logical reads = 3078)

Describe the suggested solution

Investigate why the Index_RowVersion is not used

Describe alternatives you've considered

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant