> > EXPLAIN QUERY PLAN SELECT * FROM vals2d WHERE x = 1 OR y = 1; > > select * from vals2d where x=1 > union all > select * from vals2d where y=1
Super! You've greatly helped me yet again. My query really looked like this: SELECT x,y,val FROM vals2d WHERE x = 1 OR y = 1 ORDER BY val DESC LIMIT 1; I don't care if there are duplicates in the data; I'm only returning one row anyway. Modifying it to use the UNION ALL has significantly increased the speed. I would think this would be a valuable optimization for Sqlite to perform automatically. When it finds an OR operation, it should look to see if duplicating the query and using the UNION ALL compounder would allow it to use additional indexes and if so then duplicate it.