Optimizing a query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I'm new to PostgreSQL and trying to run this query:

SELECT *
FROM "Log"
LEFT JOIN "NewsArticle" ON "NewsArticle".id = "Log"."targetId" AND "Log"."targetType" = 'NewsArticle'
ORDER BY "Log"."createdAt" DESC
LIMIT 10

Basically I'm finding the last 10 log entries, which point (targetType) to news articles.

The explain analyze is this:

http://d.pr/i/mZhl (I didn't know how to copy from the pgAdmin, without having a huge mess)

I have this index on Log:

CREATE INDEX "Log_targetId_targetType_idx"
  ON "Log"
  USING btree
  ("targetId", "targetType" COLLATE pg_catalog."default");

I have ran Vacuum and Analyze on both tables.

What am I missing here?


--
Yours sincerely,
Kai Sellgren

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux