Received: from acheron.rime.com.au (root@albatr.lnk.telstra.net [139.130.54.222]) by hub.org (8.10.1/8.10.1) with ESMTP id e749ZDG55574; Fri, 4 Aug 2000 05:35:14 -0400 (EDT) Received: from oberon (Oberon.rime.com.au [203.8.195.100]) by acheron.rime.com.au (8.9.3/8.9.3) with SMTP id TAA27228; Fri, 4 Aug 2000 19:28:34 +1000 Message-Id: <3.0.5.32.20000804193540.0226ad90@mail.rhyme.com.au> X-Sender: pjw@mail.rhyme.com.au X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.5 (32) Date: Fri, 04 Aug 2000 19:35:40 +1000 To: pgsql-sql@postgresql.org, pgsql-general@postgresql.org From: Philip Warner Subject: Strange strategy with COALESCE? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Archive-Number: 200008/81 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 |/