X-Original-To: pgsql-hackers-win32-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 967F832A23E for ; Wed, 29 Sep 2004 06:11:24 +0100 (BST) 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 83989-07 for ; Wed, 29 Sep 2004 05:11:13 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 46ECF32A232 for ; Wed, 29 Sep 2004 06:11:04 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i8T5AliS022683; Wed, 29 Sep 2004 01:10:48 -0400 (EDT) To: John Meinel Cc: pgsql-hackers-win32 Subject: Re: Poor Performance for large queries in functions In-reply-to: <415A288F.2030002@johnmeinel.com> References: <4155C955.40808@dunslane.net> <415A288F.2030002@johnmeinel.com> Comments: In-reply-to John Meinel message dated "Tue, 28 Sep 2004 22:14:23 -0500" Date: Wed, 29 Sep 2004 01:10:47 -0400 Message-ID: <22682.1096434647@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/156 X-Sequence-Number: 2286 John Meinel writes: > ... However, if I try to > bundle this query up into a server side function, it runs very slow (10 > seconds). I'm trying to figure out why, but since I can't run EXPLAIN > ANALYZE inside a function, I don't really know what else to do. A parameterized query inside a function is basically the same as a PREPARE'd query with parameters at the SQL level. So you can investigate what's happening here with PREPARE foo(int) AS SELECT * FROM object WHERE id in ( SELECT id FROM data_t WHERE project_id = $1 UNION SELECT ... ; EXPLAIN ANALYZE EXECUTE foo(48542); I'm not sure where the problem is either, so please do send along the results. regards, tom lane PS: pgsql-performance would be a more appropriate venue for this discussion.