SQLite Forum

bad plan for a query with an OR condition
Login
But you made x different for each record. Make it the same and see what happens:

psql (12.0)
Type "help" for help.

testing=> create temp table t (x int, c1 boolean, c2 boolean);
CREATE TABLE
Time: 115.133 ms
testing=> insert into t values (1, false, false), (1, false, true), (1, true, false), (1, true, true);
INSERT 0 4
Time: 0.954 ms
testing=> select x from t where c1 or c2 order by 1;
 x
---
 1
 1
 1
(3 rows)

Time: 59.461 ms
testing=> select x from t where c1 union all select x from t where c2 order by 1;
 x
---
 1
 1
 1
 1
(4 rows)

Time: 0.443 ms
testing=> select x from t where c1 union select x from t where c2 order by 1;
 x
---
 1
(1 row)

Time: 11.495 ms
testing=>