Optimizing a query - Mailing list pgsql-performance

From Kai Sellgren
Subject Optimizing a query
Date
Msg-id CANyR-3cRezeFXaE6udHh=SEkO0BfAP2Aq5B=eo90n=WrqXnj_A@mail.gmail.com
Whole thread Raw
Responses Re: Optimizing a query
List pgsql-performance
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

pgsql-performance by date:

Previous
From: Drew Jetter
Date:
Subject: Help with cursor query that is intermittently slow
Next
From: "kolszew73@gmail.com"
Date:
Subject: Re: Problem with slow query with WHERE conditions with OR clause on primary keys