Planner decisions

From: "Wappler, Robert" <rwappler(at)ophardt(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Planner decisions
Date: 2010-07-16 14:34:22
Message-ID: C8E2DAF0E663A948840B04023E0DE32A02A22C91@w2k3server02.de.ophardt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Attached is a query and its corresponding plan, where sorting of the CTE
acts seems to be the bottle neck. It is a real execution plan captured
with the auto_explain module.

The query is recursive. In each iteration CTE acts is sorted again,
which is obviously quite expensive for about 24000 rows and the same
number of iterations.

So I tried to put the ordering over the keys (d_id, activation_count)
into the CTE definition itself. This is honoured, when evaluating the
CTE but not for the iteration, where the CTE acts is still sorted again.
I cannot see a reason for this. A simple CTE scan with filter condition
should be enough.

Removing the order by from the definition of the CTE has absolutely no
impact on the performance, which is quite obvious regarding the number
of iterations. Further it has no impact on the query plan at all. It
only removes the sort node from the CTE acts node.

Do I miss something which would make the plan incorrect or is the
planner just not intelligent enough to recognize that a table is sorted
by the desired keys?

I hope the attachments prevent outlook from destroying any text
formatting.

Thanks in advance
--
Regards,
Robert

Attachment Content-Type Size
execution-plan-pg.txt text/plain 5.3 KB
query-pg.txt text/plain 1.5 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Grey 2010-07-16 15:02:27 Re: Full Text Search dictionary issues
Previous Message Vincenzo Romano 2010-07-16 13:31:45 [WISHLIST] EXECUTE SPRINTF