Re: external query VS user function

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Joao Ferreira gmail <joao(dot)miguel(dot)c(dot)ferreira(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: external query VS user function
Date: 2008-09-11 10:38:17
Message-ID: 48C8F519.6000309@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joao Ferreira gmail wrote:
> I need to remove from 100.000 to 1.000.000 records from my table once a
> day, and I'dd like to make that removal as fast as possible. This is the
> idea:
>
> DELETE FROM tt WHERE time < $1;
>
>
> Would it be considerably faster if I declare that query inside a user
> function, let's say function_delete(integer), and invoque it instead
>
> SELECT function_delete($max_time);
>
>
> Would this second approach be faster ? I imagine there could be some
> internal mechanism that would allow pg to have that query pre-optimized
> somehow ?

No, the internal mechanisms will be pretty much the same (assuming you
write the function LANGUAGE SQL). The bottleneck in this command will
most likely be the disk, so the conceivable "pre-optimization"
mechanisms such as prepared statements or plan caching wouldn't really
matter here in practice. So just use whatever you like best.

> [[[ I've been looking at Partitioning, but it seems to be a quite
> intrusive setup if you already have your system up and running]]]

Partitioning is probably something you should look into if you can't get
the statement to run quickly enough otherwise. Or combine partitioning
and TRUNCATE to get superfast deletes.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Harald Fuchs 2008-09-11 11:13:51 Re: psql scripting tutorials
Previous Message Peter Eisentraut 2008-09-11 10:32:51 Re: xml queries & date format