<s>I don't see that that really helps. Because I still need to deal with (omit the optimization from) this case:</s> > <s>SELECT count(*) FROM (SELECT sideeffectfunc(x) FROM table ORDER BY x);</s> Edit: I now believe my reasoning was incorrect. See [4a76777e6d7aa126](/forumpost/4a76777e6d7aa126) above. Ignore this post.