X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9E6D8D1BB30 for ; Thu, 21 Aug 2003 18:07:39 -0300 (ADT) 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 54202-03 for ; Thu, 21 Aug 2003 18:07:08 -0300 (ADT) Received: from megazone.bigpanda.com (45.mufb.snfc.sffca01r18.dsl.att.net [12.103.249.45]) by svr1.postgresql.org (Postfix) with ESMTP id 49CE9D1B927 for ; Thu, 21 Aug 2003 18:07:06 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 3F8D1D6E0; Thu, 21 Aug 2003 14:07:08 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 351C75C0B; Thu, 21 Aug 2003 14:07:08 -0700 (PDT) Date: Thu, 21 Aug 2003 14:07:08 -0700 (PDT) From: Stephan Szabo To: Tom Lane Cc: Dani Oderbolz , Subject: Re: [SQL] "SELECT IN" Still Broken in 7.4b In-Reply-To: <25062.1061498540@sss.pgh.pa.us> Message-ID: <20030821140139.C57728-100000@megazone.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/966 X-Sequence-Number: 42623 On Thu, 21 Aug 2003, Tom Lane wrote: > Stephan Szabo writes: > > Within the scope of the new hashed IN stuff I believe so in at least some > > cases. I have a few million row table of integers where searching for > > values IN (~10000 values) takes longer than creating the temp table, > > copying into it and doing the in subquery. > > I did some profiling and soon realized that the main problem is the > executor's trick for not returning the same row multiple times in a > multiple-indexscan plan node. The point is that given > WHERE a = 1 OR b = 1 > you could create a plan that first indexscans on a, then indexscans on > b --- but you mustn't return any tuples in the second scan that you > already returned in the first. IndexNext solves this by evaluating the > prior-scan index conditions to see if they are true. Which is okay if > there aren't too many of them. But when you have an N-element IN list > this means you are going to do O(N^2) index expression evaluations. > In the 10000-element IN-list test case, ExecQual gets called almost > 50 million times :-( > > I'm toying with the notion of ripping out that logic and instead > building an in-memory hashtable of already-returned TIDs. This could > theoretically run out of memory if the multiple indexscan returns enough > tuples, but I think in practice that wouldn't happen because the planner > wouldn't choose an indexscan when very large numbers of tuples are being > selected. Well, if you want to be safer, I guess you could (at runtime) decide that the table's gotten too big and fall back to the old method if you didn't entirely rip it out. I'm not sure if that'd be too ugly though, but it would mean that you wouldn't have to worry about it returning too many tuples.