Having this WHERE clause:
WHERE detail.element_id IN (4, 5, 6, 7, 8) AND
(
detail.additionalelement_id IS NULL OR
detail.additionalelement_id IN (4, 5, 6, 7, 8)
)
What kind of index/object can we create to optimize the query’s performance?
How would you rewrite this clause in a more efficient way?
And create an index on both
detail(element_id)anddetail(additionalelement_id)and let postgres decide which to use.(Edited to remove using
coalesce(detail.additionalelement_id, -1))