Re: Planner matching constants across tables in a

From: Richard Huxton <dev(at)archonet(dot)com>
To: "Josh Berkus" <josh(at)agliodbs(dot)com>, Greg Stark <gsstark(at)mit(dot)edu>
Cc: Greg Stark <gsstark(at)mit(dot)edu>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Planner matching constants across tables in a
Date: 2003-03-05 19:25:43
Message-ID: 200303051925.43178.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Wednesday 05 Mar 2003 7:00 pm, Josh Berkus wrote:
> Richard,
>
> > A domain defined as varchar() actually - which is why it's not using
> > an index,
> > but that's neither here nor there regarding the constant issue.
>
> You might improve your performance overall if you cast the constant to
> tel_num before doing the comparison in the query. Right now, the
> parser is casting the whole column to text instead, because it can't
> tell that the constant you supply is a valid tel_num.

That's what I thought, but...

rms=> EXPLAIN ANALYSE SELECT * FROM line WHERE telno='0912345 0004'::tel_num;
QUERY PLAN
----------------------------------------------------------------------------------------------
Seq Scan on line (cost=0.00..20.50 rows=1 width=28) (actual time=0.10..5.28
rows=1 loops=1)
Filter: ((telno)::text = ('0912345 0004'::character varying)::text)
Total runtime: 5.43 msec

rms=> EXPLAIN ANALYSE SELECT * FROM line WHERE telno='0912345 0004'::varchar;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
Index Scan using line_pkey on line (cost=0.00..5.78 rows=1 width=28) (actual
time=14.03..14.03 rows=1 loops=1)
Index Cond: ((telno)::character varying = '0912345 0004'::character
varying)
Total runtime: 14.28 msec

Ignoring the times (fake data on my test box) it seems like there's an issue
in comparing against DOMAIN defined types. Or maybe it's in the index
definition, although I don't know how to find out the type of an index.
--
Richard Huxton

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Richard Huxton 2003-03-05 19:31:44 Re: Planner matching constants across tables in a
Previous Message Josh Berkus 2003-03-05 19:00:23 Re: Planner matching constants across tables in a