Fixed by backing out the EXISTS-to-IN optimization. The EXISTS-to-IN optimization attempts to convert EXISTS operators into IN operators. It was described by bullet 8b of the [change log][1]. We may come back and revisit that optimization opportunity later. But as it was causing other problems besides this bug, it seems best to just back it out for now. [1]: https://www.sqlite.org/releaselog/3_35_5.html