Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 02A209FB96D for ; Sun, 25 Feb 2007 14:34:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 79754-07 for ; Sun, 25 Feb 2007 14:34:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id D560F9FB92B for ; Sun, 25 Feb 2007 14:34:47 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l1PIYiDx009474; Sun, 25 Feb 2007 13:34:44 -0500 (EST) To: Joe Conway cc: Richard Jones , pgsql-sql@postgresql.org Subject: Re: Very large IN-clause is slow, but how to rewrite it? In-reply-to: <45E1D4FC.4050901@joeconway.com> References: <20070225123913.GA17124@furbychan.cocan.org> <7794.1172422591@sss.pgh.pa.us> <45E1D4FC.4050901@joeconway.com> Comments: In-reply-to Joe Conway message dated "Sun, 25 Feb 2007 10:27:08 -0800" Date: Sun, 25 Feb 2007 13:34:44 -0500 Message-ID: <9473.1172428484@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.055 tagged_above=0 required=5 tests=AWL, BAYES_50, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200702/256 X-Sequence-Number: 27590 Joe Conway writes: > If 8.2, what about > ... WHERE foo IN (select x from (values (1$),(2$),...,(N$)) as t(x)) > ? Well, the OP wasn't using 8.2 --- judging from the selected plan, it had to be 8.0 or older. But yeah, a values-list is an interesting alternative on 8.2. I think actually you don't need all that much extra notation; this seems to work: WHERE foo IN (VALUES ($1),($2),($3),...) regards, tom lane