Re: strange view performance

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: strange view performance
Date: 2011-05-01 22:30:34
Message-ID: 26554.1304289034@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Patrick Earl 2011-05-02 00:14:48 Re: Select For Update and Left Outer Join
Previous Message Tom Lane 2011-05-01 22:05:20 Re: Select For Update and Left Outer Join