pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philip Warner <pjw@rhyme.com.au>
To: pgsql-sql@postgresql.org
To: pgsql-general@postgresql.org
Subject: Strange strategy with COALESCE?
Date: Fri, 04 Aug 2000 19:35:40 +1000
Message-ID: <3.0.5.32.20000804193540.0226ad90@mail.rhyme.com.au> (raw)


I get unexpected query strategy when using coalesce.

Good:
-----

explain update zzz set 
        b = (select x.newVal from zzz_xref x where x.oldVal = zzz.b);
NOTICE:  QUERY PLAN:

Seq Scan on zzz  (cost=0.00..20.00 rows=1000 width=10)
  SubPlan
    ->  Index Scan using zzz_xref_ix2 on zzz_xref x  (cost=0.00..726.82
rows=983 width=4)

Bad (just by adding a COALESCE call):
-------------------------------------

explain update zzz set 
        b = coalesce((select x.newVal from zzz_xref x where x.oldVal =
zzz.b),b);
NOTICE:  QUERY PLAN:

Seq Scan on zzz  (cost=0.00..20.00 rows=1000 width=10)
  SubPlan
    ->  Index Scan using zzz_xref_ix2 on zzz_xref x  (cost=0.00..726.82
rows=983 width=4)
    ->  Seq Scan on zzz_xref x  (cost=0.00..1757.80 rows=98304 width=4)


Does this make sense?

P.S. There are indexes on both oldVal and newVal in zzz_xref, and table zzz
has one column (b).



----------------------------------------------------------------
Philip Warner                    |     __---_____
Albatross Consulting Pty. Ltd.   |----/       -  \
(A.C.N. 008 659 498)             |          /(@)   ______---_
Tel: (+61) 0500 83 82 81         |                 _________  \
Fax: (+61) 0500 83 82 82         |                 ___________ |
Http://www.rhyme.com.au          |                /           \|
                                 |    --________--
PGP key available upon request,  |  /
and from pgp5.ai.mit.edu:11371   |/



Message-ID: <3.0.5.32.20000804193540.0226ad90@mail.rhyme.com.au>
Permalink:  ../3.0.5.32.20000804193540.0226ad90@mail.rhyme.com.au/
Also on:    postgresql.org/message-id/3.0.5.32.20000804193540.0226ad90@mail.rhyme.com.au

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: pjw@rhyme.com.au, pgsql-general@postgresql.org
  Subject: Re: Strange strategy with COALESCE?
  In-Reply-To: <3.0.5.32.20000804193540.0226ad90@mail.rhyme.com.au>
  References: <3.0.5.32.20000804193540.0226ad90@mail.rhyme.com.au>

* 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