X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 51B45D9C58 for ; Thu, 29 Sep 2005 16:55:54 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 34272-06 for ; Thu, 29 Sep 2005 19:55:51 +0000 (GMT) Received: from mailhub.doruk.net.tr (mailhub.doruk.net.tr [212.58.5.105]) by svr1.postgresql.org (Postfix) with ESMTP id 8EBDED9C47 for ; Thu, 29 Sep 2005 16:55:51 -0300 (ADT) Received: from mail3.doruk.net.tr ([212.58.5.9]) by mailhub.doruk.net.tr with smtp (Exim 4.24) id 1EL4Vb-0007yi-V6 for pgsql-performance@postgresql.org; Thu, 29 Sep 2005 22:55:59 +0300 Received: from [85.105.24.123] (account adnandursun@asrinbilisim.com.tr) by mail3.doruk.net.tr (CommuniGate Pro WebUser 4.2.5) with HTTP id 145786064 for pgsql-performance@postgresql.org; Thu, 29 Sep 2005 22:54:58 +0300 From: Subject: SQL Function performance To: pgsql-performance@postgresql.org X-Mailer: CommuniGate Pro WebUser Interface v.4.2.5 Date: Thu, 29 Sep 2005 22:54:58 +0300 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-9" Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.348 required=5 tests=[AWL=-0.037, NO_REAL_NAME=0.178, UPPERCASE_25_50=0.207] X-Spam-Level: X-Archive-Number: 200509/430 X-Sequence-Number: 14738 Hi All, I have a SQL function like : CREATE OR REPLACE FUNCTION fn_get_yetkili_inisyer_listesi(int4, int4) RETURNS SETOF kod_adi_liste_type AS $BODY$ SELECT Y.KOD,Y.ADI FROM T_YER Y WHERE EXISTS (SELECT 1 FROM T_GUZER G WHERE (G.BIN_YER_KOD = $1 OR COALESCE($1,0)=0) AND FN_FIRMA_ISVISIBLE(G.FIRMA_NO,$2) = 1 AND G.IN_YER_KOD = Y.KOD) AND Y.IPTAL = 'H'; $BODY$ LANGUAGE 'sql' VOLATILE; When i use like "SELECT * FROM fn_get_yetkili_inisyer_listesi(1, 3474)" and planner result is "Function Scan on fn_get_yetkili_inisyer_listesi (cost=0.00..12.50 rows=1000 width=36) (1 row) " and it runs very slow. But when i use like "SELECT Y.KOD,Y.ADI FROM T_YER Y WHERE EXISTS (SELECT 1 FROM T_GUZER G WHERE (G.BIN_YER_KOD = 1 OR COALESCE(1,0)=0) AND FN_FIRMA_ISVISIBLE(G.FIRMA_NO,3474) = 1 AND G.IN_YER_KOD = Y.KOD) AND Y.IPTAL = 'H';" planner result : " QUERY PLAN -------------------------------------------------------------------------------- ----------------------------- Seq Scan on t_yer y (cost=0.00..3307.79 rows=58 width=14) Filter: (((iptal)::text = 'H'::text) AND (subplan)) SubPlan -> Index Scan using t_guzer_ucret_giris_performans_idx on t_guzer g (cost =0.00..28.73 rows=1 width=0) Index Cond: ((bin_yer_kod = 1) AND (in_yer_kod = $0)) Filter: (fn_firma_isvisible(firma_no, 3474) = 1) (6 rows) " and it runs very fast. Any idea ? Adnan DURSUN ASRIN Biližim Hiz.Ltd.