From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Robert Klemme <shortcutter(at)googlemail(dot)com> |
Cc: | Li Jin <ljin(at)tripadvisor(dot)com>, pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Performance penalty when using WITH |
Date: | 2011-08-02 21:48:41 |
Message-ID: | CAHyXU0w+cZcFB+REAKbFcdB_YhU62_375cQdqT=VVE90v5MuRw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Sat, Jul 30, 2011 at 8:10 AM, Robert Klemme
<shortcutter(at)googlemail(dot)com> wrote:
> 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.
disagree. just one of the ways that could be stymied would to change
the function behind the '||' operator.
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Gavin Flower | 2011-08-02 23:01:58 | Re: Tsearch2 - bad performance with concatenated ts-vectors |
Previous Message | Kevin Grittner | 2011-08-02 17:41:33 | Re: Performance die when COPYing to table with bigint PK |