pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Morten Minde Neergaard <m@8d.no>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #7651: Superfluous calls to functions used for indexing
Date: Fri, 16 Nov 2012 15:48:23 +0100
Message-ID: <20121116144823.GG610@8d.no> (raw)
In-Reply-To: <CADmi=6MoMaiOP7zu0pWghAaNe4nONJwzGJUgnwXzeLdDru_43w@mail.gmail.com> <1353019478.14335.23.camel@sussancws0025>

At 14:44, Thu 2012-11-15, Jeff Davis wrote:
[…]
> It's possible that the function call may be unnecessary, but that is
> more of a performance enhancement, not a bug.

For me it's a matter of orders of size of performance, so it feels like
a bug ;p

> Also, the example function has side effects. If you declare functions
> with side effects to be IMMUTABLE, you can get all kinds of problems.
> You should certainly not rely on an IMMUTABLE function to be called a
> specific number of times.

The function was only a minimal example, not what I'm running in my
production code =)

At 11:40, Fri 2012-11-16, Stuart Bishop wrote:
> I think this is the same issue as was discussed here, dating from
> PostgreSQL 8.1:
> 
> http://postgresql.1045698.n5.nabble.com/Slow-functional-indexes-td2059587.html

Yup, looks like the same thing. Would be nice to have this fixed.

Did, however, find two workarounds possible from PostgreSQL 9.2:

1. Create an index over all the columns you want. The index-only scan
   eliminates recalculation

2. Create an index over (my_complex_function(whatever_columns),
   table_primary_key) and wrap the query as such:
   SELECT a_lot_of_columns FROM my_table WHERE table_primary_key IN
       (SELECT table_primary_key FROM my_table ORDER BY
           my_complex_function(whatever_columns));

Did stumble across a situation where the function was rerun for *all*
rows at some point *despite* having such an index. Will see if I can
reproduce that if I have the time!


Smiles,
-- 
Morten Minde Neergaard




view thread (4+ messages)

Message-ID: <20121116144823.GG610@8d.no>
Permalink:  ../20121116144823.GG610@8d.no/
Also on:    postgresql.org/message-id/20121116144823.GG610@8d.no

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: m@8d.no
  Subject: Re: BUG #7651: Superfluous calls to functions used for indexing
  In-Reply-To: <20121116144823.GG610@8d.no>
  References: <20121116144823.GG610@8d.no>

* 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