Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cO5cd-0000H2-Mm for pgsql-performance@arkaria.postgresql.org; Mon, 02 Jan 2017 16:38:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cO5cd-00072h-8E for pgsql-performance@arkaria.postgresql.org; Mon, 02 Jan 2017 16:38:07 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cO5ay-0005Ai-4U for pgsql-performance@postgresql.org; Mon, 02 Jan 2017 16:36:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cO5av-0007QJ-Qq for pgsql-performance@postgresql.org; Mon, 02 Jan 2017 16:36:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v02GaKxk018072; Mon, 2 Jan 2017 11:36:20 -0500 From: Tom Lane To: =?UTF-8?B?0JDQvdC00YDQtdC5INCl0L7Qt9C+0LI=?= cc: pgsql-performance@postgresql.org Subject: Re: Performance issue with castings args of the function In-reply-to: References: Comments: In-reply-to =?UTF-8?B?0JDQvdC00YDQtdC5INCl0L7Qt9C+0LI=?= message dated "Mon, 02 Jan 2017 19:34:49 +0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18070.1483374980.1@sss.pgh.pa.us> Date: Mon, 02 Jan 2017 11:36:20 -0500 Message-ID: <18071.1483374980@sss.pgh.pa.us> X-Pg-Spam-Score: -5.1 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org =?UTF-8?B?0JDQvdC00YDQtdC5INCl0L7Qt9C+0LI=?= writes: > create table t1 (id serial, str char(32)); > create function f1(line text) returns void as $$ > begin > perform * from t1 where str = line; > end; > $$ language plpgsql; This query is specifying a text comparison (text = text operator). Since the table column isn't text, a char-to-text conversion must happen at each line. > create function f2(line char) returns void as $$ > begin > perform * from t1 where str = line; > end; > $$ language plpgsql; This query is specifying a char(n) comparison (char = char operator). No type conversion step needed, so it's faster. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance