Re: Very specialised query

From: Matthew Wakeling <matthew(at)flymine(dot)org>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Very specialised query
Date: 2009-04-01 17:33:16
Message-ID: alpine.DEB.2.00.0904011811360.21772@aragorn.flymine.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Mon, 30 Mar 2009, Віталій Тимчишин wrote:
> What is the bad plan? Is it like the first plan from your first message?

It's the plan a few messages back. The UNION ALL query I showed
effectively got the database to do it both ways round.

It's the case that a "between" index scan will return much fewer rows than
an open-ended index scan.

> BTW: About aggregates: they can return arrays, but I can't imagine what you can group by on... May be windowing functions from 8.4
> could help.

A normal function seems the best way to go about this - they can return
multiple rows.

So, I have written a plpgsql function to calculate overlaps. It works
reasonably quickly where there aren't that many overlaps. However, it
seems to go very slowly when there are a large number of rows to return. I
am considering recoding it as a C function instead.

1. The docs say that returning multiple rows from plpgsql waits until the
whole lot are done before returning any. Does this happen with the C
functions too?
2. What sort of speedup would I be likely to see?
3. How do I RAISE NOTICE in a C function?

> Also, if your maximum length (select max(end-start) from location) is low enough, you can try adding some more constraints to make
> optimizer happy (have it more precise row count to select correct plan).

Alas:

select min(start), max(start), min(end), max(end), max(end - start) from location;

min | max | min | max | max
-----+----------+-----+----------+----------
1 | 61544858 | 1 | 61545105 | 21512431
(1 row)

Matthew

--
I suppose some of you have done a Continuous Maths course. Yes? Continuous
Maths? <menacing stares from audience> Whoah, it was like that, was it!
-- Computer Science Lecturer

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Greg Smith 2009-04-01 17:49:46 Re: Raid 10 chunksize
Previous Message Tom Lane 2009-04-01 17:19:10 Re: self join revisited