X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id B8B47D1B915 for ; Fri, 29 Aug 2003 16:18:47 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 35872-07 for ; Fri, 29 Aug 2003 13:18:37 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 7FF92D1B8CD for ; Fri, 29 Aug 2003 13:18:36 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h7TGIZjX028310; Fri, 29 Aug 2003 12:18:36 -0400 (EDT) To: Andrew Sullivan Cc: pgsql-performance@postgresql.org, Oliver Siegmar , Bill Moran Subject: Re: PL/pgSQL functions - text / varchar - havy performance In-reply-to: <20030829155401.GM19388@libertyrms.info> References: <200308291554.46748.o.siegmar@vitrado.de> <3F4F6754.8050900@potentialtech.com> <20030829150151.GI19388@libertyrms.info> <3F4F7275.5030203@potentialtech.com> <20030829155401.GM19388@libertyrms.info> Comments: In-reply-to Andrew Sullivan message dated "Fri, 29 Aug 2003 11:54:01 -0400" Date: Fri, 29 Aug 2003 12:18:35 -0400 Message-ID: <28309.1062173915@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/502 X-Sequence-Number: 3318 Andrew Sullivan writes: > On Fri, Aug 29, 2003 at 11:34:13AM -0400, Bill Moran wrote: >> Have any explanation as to why that function is so slow? > Sorry, no. It might have to do with the planning, though. Specifically, I'll bet he's getting an indexscan plan with one and not with the other. It's just ye olde cross-datatype-comparisons-aren't- indexable problem. "varchar = varchar" matches the index on the varchar column, but "text = text" is a different operator that doesn't match. Guess which one gets selected when the initial input is "varchar = text". 7.4 has fixed this particular problem by essentially eliminating the separate operators for varchar, but in prior releases the behavior Oliver describes is entirely to be expected. A workaround is to cast inside the function: ... where varcharcolumn = textarg::varchar; so that "=" gets interpreted as "varchar = varchar". regards, tom lane