Skip to content

Improve DISTINCT queries on PostgreSQL via recursive CTE#730

Open
bubiche wants to merge 1 commit intorails:mainfrom
bubiche:main
Open

Improve DISTINCT queries on PostgreSQL via recursive CTE#730
bubiche wants to merge 1 commit intorails:mainfrom
bubiche:main

Conversation

@bubiche
Copy link
Copy Markdown

@bubiche bubiche commented Apr 5, 2026

Attempt to improve performance issues with PostgreSQL as stated here. Follow up of #397

PostgreSQL lacks MySQL's Loose Index Scan, so DISTINCT queries on queue_name degrade to full index scans on large tables. The recursive CTE walks the B-tree index jumping between distinct values.

I have encapsulate the database specific logic in Record::LooseDistinct so the rest can just use distinct_values_of, which uses recursive CTE to emulate loose index scan on PostgreSQL and normal DISTINCT query for MySQL/SQLite.

This should help with:

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.

1 participant