"Andrus" <kobruleht2(at)hot(dot)ee> writes:
> My query takes 26 seconds to run.
The time seems entirely spent in fetching rows from table "rid".
Perhaps that table is bloated by lack of vacuuming --- can you
show the output from "vacuum verbose rid"?
regards, tom lane