Re: strange view performance - Mailing list pgsql-hackers

From Tom Lane
Subject Re: strange view performance
Date
Msg-id 26554.1304289034@sss.pgh.pa.us
Whole thread Raw
In response to strange view performance  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
Pavel Stehule <pavel.stehule@gmail.com> writes:
> I am solving  a strange situation, where using a view is slower than
> using same tables directly.

> The view is defined as

> CREATE VIEW v1 AS
>   SELECT *
>     FROM A
>                LEFT JOIN B
>                LEFT JOIN C
>                LEFT JOIN D

> and query is
>    SELECT *
>       FROM T
>                  LEFT JOIN v

> this query is slower than:

> SELECT *
>    FROM T
>               LEFT JOIN A
>               LEFT JOIN B
>               LEFT JOIN C
>               LEFT JOIN D

> Is there a some reason for this behave?

Well, they don't necessarily mean the same thing --- these are only
logically equivalent if the left joins all commute, which would depend
on the ON conditions.

> [ EXPLAIN outputs ]

But I also notice that you are using collapse/geqo limits of 12 for
queries that involve 13 base relations, so that'd mean that syntactic
differences could lead to plan differences too.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Select For Update and Left Outer Join
Next
From: Patrick Earl
Date:
Subject: Re: Select For Update and Left Outer Join