SQLite Forum

short circuiting subqueries with `IN`?
Login
An alternate (and very slightly more efficient) spelling would be:

```
SELECT EXISTS (
                 WITH found(id) AS NOT MATERIALIZED
                      (
                          SELECT self_hash_id
                            FROM causal
                           WHERE self_hash_id == ?2
                       UNION ALL
                          SELECT parent_id
                            FROM causal_parent
                            JOIN found
                              ON found.id == causal_id
                      )
               SELECT id
                 FROM found
                WHERE id == ?1
              )
;
```