pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Claus Stadler <cstadler@informatik.uni-leipzig.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: ...WHERE TRUE" condition in union results in bad query pla
Date: Sat, 03 Mar 2012 22:03:29 -0500
Message-ID: <1857.1330830209@sss.pgh.pa.us> (raw)
In-Reply-To: <4F529E85.8010506@informatik.uni-leipzig.de>
References: <4F529E85.8010506@informatik.uni-leipzig.de>

Claus Stadler <cstadler@informatik.uni-leipzig.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



view thread (4+ messages)  latest in thread

Message-ID: <1857.1330830209@sss.pgh.pa.us>
Permalink:  ../1857.1330830209@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1857.1330830209@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, cstadler@informatik.uni-leipzig.de
  Subject: Re: ...WHERE TRUE" condition in union results in bad query pla
  In-Reply-To: <1857.1330830209@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox