Databases · Senior · Question 53 of 75

Why might a query using OR across different columns be slow, and what can help?

SELECT * FROM users WHERE email = $1 OR phone = $2;

Explanation

With indexes on both columns, a BitmapOr combines them. Without one of them, the planner falls back to scanning the table.

Further reading

Problem with a question

Databases · Senior · question 53

Test yourself

Take the Databases · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz