I have a sqlite database with around 12,000 rows, the relevant columns are width1, height1, width2 and height2
My dynamic input is an arbitrary width and height, and I want to find all rows where the difference between the width and height are smaller than a x
To make it more compleicated, I'm never sure if the width and height of the input are reversed, so I also have to flip the values and test input width against stored height, etc.
Here's the ugly query:
SELECT id, width1, height1, width2, height2
FROM mytable
WHERE ((ABS(width - width1) < 10 AND ABS(height - height1) < 10) OR
(ABS(height - width1) < 10 AND ABS(width - height1) < 10)) OR
((ABS(width - width2) < 10 AND ABS(height - height2) < 10) OR
(ABS(height - width2) < 10 AND ABS(width - height2) < 10));
I have created combined indexes for width1, width2, height1, height2 as well as each column individually, but the query is missing the indexes.