Ken Williams <ken(at)mathforum(dot)org> writes:
> When I run the query, it takes a really long time (10 seconds)
> the first time I execute it, and then returns instantly the
> second time.
That sounds like a caching issue. How much RAM do you have,
what have you got shared_buffers set to, etc?
regards, tom lane