hard20 pts · first answer countsindexingquery-tuning
Optional filters in one query
A search API uses the query below so that any filter can be skipped by passing NULL. With prepared statements, it is slow even when only city is given. Why?
SELECT * FROM shops WHERE ($1::text IS NULL OR city = $1) AND ($2::text IS NULL OR category = $2) AND ($3::int IS NULL OR rating >= $3);
Discussion 0
Join free to post in the discussion.
Related questions
- When a B-tree index helpsDatabase Administrator
- Finding slow MySQL queriesDatabase Administrator
- Index on a yes/no columnDatabase Administrator
- How InnoDB stores table rowsDatabase Administrator
- What an InnoDB secondary index points toDatabase Administrator
- LIKE with a leading %Database Administrator
- What a hash index supportsDatabase Administrator
- Cost of extra indexes on insertsDatabase Administrator