"Andrus" <kobruleht2@hot.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