Skip site navigation (1) Skip section navigation (2)

Re: ...WHERE TRUE" condition in union results in bad query pla

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Claus Stadler <cstadler(at)informatik(dot)uni-leipzig(dot)de>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: ...WHERE TRUE" condition in union results in bad query pla
Date: 2012-03-04 03:03:29
Message-ID: 1857.1330830209@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-performance
Claus Stadler <cstadler(at)informatik(dot)uni-leipzig(dot)de> writes:
> Query optimizer glitch: "...WHERE TRUE" condition in union results in 
> bad query plan ...

Yeah, this is because a nonempty WHERE clause defeats simplifying the
UNION ALL into a simple "append relation" (cf is_safe_append_member()).
The planner will eventually figure out that WHERE TRUE is a no-op,
but that doesn't happen till later (and there are good reasons to do
things in that order).

Sooner or later I'd like to relax the restriction that appendrel members
can't have extra WHERE clauses, but don't hold your breath waiting...

			regards, tom lane

In response to

Responses

pgsql-performance by date

Next:From: Rory Campbell-LangeDate: 2012-03-04 09:58:38
Subject: Advice sought : new database server
Previous:From: Claus StadlerDate: 2012-03-03 22:43:17
Subject: ...WHERE TRUE" condition in union results in bad query pla

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group