From: Greg Stark <gsstark@mit.edu>
To: Oleg Bartunov <oleg@sai.msu.su>
Cc: PFC <lists@boutiquenumerique.com>
Cc: alex@neteconomist.com, Greg Stark <gsstark@mit.edu>
Cc: Merlin Moncure <merlin.moncure@rcsonline.com>
Cc: Andrei Bintintan <klodoma@ar-sd.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: [SQL] OFFSET impact on Performance???
Date: 27 Jan 2005 07:57:15 -0500
Message-ID: <87zmyvvxlg.fsf@stark.xeocode.com> (raw)
In-Reply-To: <Pine.GSO.4.62.0501271415370.6701@ra.sai.msu.su>
References: <6EE64EF3AB31D5448D0007DD34EEB3412A75CB@Herge.rcsinc.local>
<87brbiah0f.fsf@stark.xeocode.com>
<opsk7nngxwth1vuj@musicbox>
<33c6269f0501261035bc87695@mail.gmail.com>
<opsk8a28tcth1vuj@musicbox>
<33c6269f05012620427c1ccc40@mail.gmail.com>
<opsk89szusth1vuj@musicbox>
<Pine.GSO.4.62.0501271332200.6701@ra.sai.msu.su>
<opsk9cicntth1vuj@musicbox>
<Pine.GSO.4.62.0501271415370.6701@ra.sai.msu.su>
Oleg Bartunov <oleg@sai.msu.su> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: gsstark@mit.edu, oleg@sai.msu.su, lists@boutiquenumerique.com, merlin.moncure@rcsonline.com, klodoma@ar-sd.net
Subject: Re: [SQL] OFFSET impact on Performance???
In-Reply-To: <87zmyvvxlg.fsf@stark.xeocode.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox