From: | Robert Klemme <shortcutter(at)googlemail(dot)com> |
---|---|
To: | Li Jin <ljin(at)tripadvisor(dot)com> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Performance penalty when using WITH |
Date: | 2011-07-30 13:10:25 |
Message-ID: | CAM9pMnNN6t5NhFvnrDuheJUFrj5+-HfW4TE3ggguZN2B8==CBA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Thu, Jul 28, 2011 at 11:00 PM, Li Jin <ljin(at)tripadvisor(dot)com> wrote:
> I met with the problem that when I was using WITH clause to reuse a
> subquery, I got a huge performance penalty because of query planner.
> Here are the details, the original query is
> EXPLAIN ANALYZE WITH latest_identities AS
> (
> SELECT DISTINCT ON (memberid) memberid, username, changedate
> FROM t_username_history
> WHERE memberid IN (SELECT memberid FROM t_member WHERE firstname || ' '
> || substring(lastname,1,1) = 'Eddie T')
> ORDER BY memberid, changedate DESC
> )
Another observation: That criterion looks suspicious to me. I would
expect any RDBMS to be better able to optimize this:
WHERE firstname = 'Eddie' AND lastname like 'T%'
I know it's semantically not the same but I would assume this is good
enough for the common usecase. Plus, if there is an index on
(firstname, lastname) then that could be used.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Filippos | 2011-07-30 20:02:11 | Re: heavy load-high cpu itilization |
Previous Message | Gavin Flower | 2011-07-30 05:24:21 | Re: insert |