Optimizing a query

Поиск
Список
Период
Сортировка
От Kai Sellgren
Тема Optimizing a query
Дата
Msg-id CANyR-3cRezeFXaE6udHh=SEkO0BfAP2Aq5B=eo90n=WrqXnj_A@mail.gmail.com
обсуждение исходный текст
Ответы Re: Optimizing a query
Список 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 по дате отправления:

Предыдущее
От: Drew Jetter
Дата:
Сообщение: Help with cursor query that is intermittently slow
Следующее
От: "kolszew73@gmail.com"
Дата:
Сообщение: Re: Problem with slow query with WHERE conditions with OR clause on primary keys