X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 855F93A5EA2 for ; Thu, 27 Jan 2005 12:57:31 +0000 (GMT) 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 53789-08 for ; Thu, 27 Jan 2005 12:57:23 +0000 (GMT) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by svr1.postgresql.org (Postfix) with ESMTP id 181423A5ECE for ; Thu, 27 Jan 2005 12:57:24 +0000 (GMT) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1Cu9D1-0003U0-00; Thu, 27 Jan 2005 07:57:15 -0500 To: Oleg Bartunov Cc: PFC , alex@neteconomist.com, Greg Stark , Merlin Moncure , Andrei Bintintan , pgsql-performance@postgresql.org Subject: Re: [SQL] OFFSET impact on Performance??? References: <6EE64EF3AB31D5448D0007DD34EEB3412A75CB@Herge.rcsinc.local> <87brbiah0f.fsf@stark.xeocode.com> <33c6269f0501261035bc87695@mail.gmail.com> <33c6269f05012620427c1ccc40@mail.gmail.com> In-Reply-To: From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 27 Jan 2005 07:57:15 -0500 Message-ID: <87zmyvvxlg.fsf@stark.xeocode.com> Lines: 55 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.057 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200501/533 X-Sequence-Number: 10223 Oleg Bartunov writes: > On Thu, 27 Jan 2005, PFC wrote: > > > > > > > beware that SELECT * FROM table WHERE id =ANY( array ) won't use an index, > > > contrib/intarray provides index access to such queries. > > > > Can you provide an example of such a query ? I've looked at the operators > > for intarray without finding it. > > for example, > http://www.sai.msu.su/~megera/postgres/gist/code/7.3/README.intarray > see OPERATIONS and EXAMPLE USAGE: > > SELECT * FROM table WHERE id && int[] I don't think that helps him. He wants the join to the *other* table to use an index. It would be nice if the IN plan used an index for =ANY(array) just like it does for =ANY(subquery) but I'm not sure the statistics are there. It might not be a bad plan to just assume arrays are never going to be millions of elements long though. There is a way to achieve this using "int_array_enum" from another contrib module, "intagg". My current project uses something similar to this except the arrays are precomputed. When I went to 7.4 the new array support obsoleted everything else I was using from the "intagg" and "array" contrib moduels except for this one instance where intagg is still necessary. It is a bit awkward but it works: slo=> EXPLAIN SELECT * FROM foo JOIN (SELECT int_array_enum(foo_ids) AS foo_id FROM cache WHERE cache_id = 1) AS x USING (foo_id) ; QUERY PLAN -------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..6.40 rows=1 width=726) -> Subquery Scan x (cost=0.00..3.18 rows=1 width=4) -> Index Scan using idx_cache on cache (cost=0.00..3.17 rows=1 width=30) Index Cond: (cache_id = 1) -> Index Scan using foo_pkey on foo (cost=0.00..3.21 rows=1 width=726) Index Cond: (foo.foo_id = "outer".foo_id) (6 rows) (query and plan edited for clarity and for paranoia purposes) -- greg