Filip
Filip

Reputation: 394

Select LIMIT 1 takes long time on postgresql

I'm running a simple query on localhost PostgreSQL database and it runs too long:

SELECT * FROM features LIMIT 1;

I expect such query to be finished in a fraction of a second as it basically says "peek anywhere in the database and pick one row". Or it doesn't?

Upvotes: 3

Views: 6136

Answers (1)

Mabu Kloesen
Mabu Kloesen

Reputation: 1358

I totally agree with @larwa1n with the content he comment on your post. The reason here, I guess, is the performance of SELECT is too slow. With my experience maybe there are another reasons. I list as below:

  • The table is too big, so let add some WHERE CLAUSE and INDEX
  • The performance of your server/disk drive is too slow.
  • Other process take most resource.
  • Another reason maybe come from maintenance task, let check again does the autovacuum is running? If not, check is this table is vacuum already? If not, let do a vacuum full on that table. Sometimes, when you do a lot of insert/update/delete on a large table without vacuum will make the table save in fragmented disk block, which will take longer time in query.

Hopefully, this answer will help you find out the final reason.

Upvotes: 2

Related Questions