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