External trouble spots
It's also possible to have a query run slowly for reasons that have nothing to do with the query plan itself.
One such situation is where you have triggers running against a table being referenced, particularly in cases where it's an UPDATE
or INSERT
running instead of just a regular query. The overhead of triggers can be high, particularly if there aren't any indexes on the underlying foreign keys.
Another issue you can run into is that dead rows can clog a query from executing as fast as expected. This is particularly true if you are frequently updating a popular set of rows without running VACUUM
often enough. Doing anything with those rows can then require large amounts of wasted time, reading the non visible data, even when doing an index scan.