pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dbichko@genpathpharma.com
To: pgsql-sql@postgresql.org
Subject: OFFSET and subselects
Date: 21 Nov 2003 08:38:16 -0800
Message-ID: <cf1d5239.0311210838.3865363e@posting.google.com> (raw)

I recently noticed a behaviour which seems quite suboptimal - I am
working on a "mart" type application, which in practice means I end up
with queries which have a few filters on several central tables, and
then a few dozen subselects for other info (which seems to perform
better than several dozen equivalent LEFT JOINs do). I am running in
trouble with pagination here, somehow (rather naively) I assumed that
when doing a LIMIT and OFFSET, the subselects on the records before
the OFFSET would not be performed, which quite apparently is not the
case. So, LIMIT 50 OFFSET 0 takes 100ms to run, LIMIT 50 OFFSET 50
takes 200ms, LIMIT 50 OFFSET 100 takes 300ms; and so forth, this
really becomes unacceptable after a few pages.

I was wondering how I migh improve the situation? Two possibilities
come to mind: a) run the query without the subselects and store the
LIMIT 50 in a temp table, doing a select all from that with the
subselects as a separate query or b) similar, but run the queries from
the subselects as separate queries, assembling everything in the app.

Is one better than the other in any way? Are there better ways to deal
with this?

Thanks



view thread (2+ messages)  latest in thread

Message-ID: <cf1d5239.0311210838.3865363e@posting.google.com>
Permalink:  ../cf1d5239.0311210838.3865363e@posting.google.com/
Also on:    postgresql.org/message-id/cf1d5239.0311210838.3865363e@posting.google.com

 · 

reply

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-sql@postgresql.org
  Cc: dbichko@genpathpharma.com
  Subject: Re: OFFSET and subselects
  In-Reply-To: <cf1d5239.0311210838.3865363e@posting.google.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