Table order at FROM clause affects performance? - Mailing list pgsql-performance

From Eduard Català
Subject Table order at FROM clause affects performance?
Date
Msg-id CAL54xNYE38bzJGKWbhAe3g_36yc8HNLhxwPJRqs85qdKGAxEmQ@mail.gmail.com
Whole thread Raw
Responses Re: Table order at FROM clause affects performance?
List pgsql-performance
I have a strange performance issue, i think that is not possible:

Given this statement:

SELECT several_fields  FROM A, B, C WHERE  conditions
A, B are tables with several LEFT JOINS but they act as one subquery.

If I execute the select above:

SELECT several_fields  FROM A, B, C WHERE  conditions
Time: 30 secs
Cost: 1M


If I execute the same select (same parameters) but swapping A and B in the from clause:

SELECT several_fields  FROM B, A, C WHERE  conditions
Time: 19ms

Cost: 10k

The plan changes dramatically: I can't see why the order of FROM clause impacts directly on the query cost and plan. If this is possible, where i can read about it? I need to know how the order of FROM clause modifies the query plan.

Thanks in advance. This is my first post.

Eduard Català






pgsql-performance by date:

Previous
From: Mark Kirkwood
Date:
Subject: Re: Latest advice on SSD?
Next
From: Tom Lane
Date:
Subject: Re: Table order at FROM clause affects performance?