Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 763E42E003A for ; Mon, 14 Apr 2008 14:46:12 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 80860-04 for ; Mon, 14 Apr 2008 14:46:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by developer.postgresql.org (Postfix) with ESMTP id 83A7B2E0039 for ; Mon, 14 Apr 2008 14:46:08 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m3EHk6wq011230; Mon, 14 Apr 2008 13:46:06 -0400 (EDT) To: Adam Gundy cc: Richard Huxton , pgsql-performance@postgresql.org Subject: Re: varchar index joins not working? In-reply-to: <48038E21.50606@starsilk.net> References: <6f55f1270804092013n73ee1f81t2c6d72cee49655a3@mail.gmail.com> <47FDD3D1.9070208@archonet.com> <47FE29AF.6010906@starsilk.net> <6f55f1270804101154t3d4a01eco2b7bff7a0053af38@mail.gmail.com> <48030439.9040309@archonet.com> <48038E21.50606@starsilk.net> Comments: In-reply-to Adam Gundy message dated "Mon, 14 Apr 2008 11:02:25 -0600" Date: Mon, 14 Apr 2008 13:46:06 -0400 Message-ID: <11229.1208195166@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/180 X-Sequence-Number: 29673 Adam Gundy writes: > hmm. unfortunately it did turn out to be (part) of the issue. I've > discovered that mixing char and varchar in a stored procedure does not > coerce the types, and ends up doing seq scans all the time. Oh, it coerces the type all right, just not in the direction you'd like. regression=# create table v (f1 varchar(32) primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "v_pkey" for table "v" CREATE TABLE regression=# explain select * from v where f1 = 'abc'::varchar; QUERY PLAN ----------------------------------------------------------------- Index Scan using v_pkey on v (cost=0.00..8.27 rows=1 width=34) Index Cond: ((f1)::text = 'abc'::text) (2 rows) regression=# explain select * from v where f1 = 'abc'::char(3); QUERY PLAN --------------------------------------------------- Seq Scan on v (cost=0.00..25.88 rows=1 width=34) Filter: ((f1)::bpchar = 'abc'::character(3)) (2 rows) regards, tom lane