I implemented a function to suggest movies from the example PostgreSQL database given in Seven Databases in Seven weeks.
The first attempt was correct but slow. The function could take more than 2000ms to return a result.
My second attempt was correct and much faster. I rewrote the query to make up for missed optimizations, and saw a much more efficient plan as a result. The function now takes about 10ms to return the same result.
I'd like to understand why PostgreSQL produces very different plans for these two logically equivalent queries.
Is this a good question for the dba.se format?
What should I put in a question to make the question answerable, and generally useful?