pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Galbavy <peter.galbavy@knowledge.com>
To: pgsql-sql@postgresql.org
Subject: performance of functions - or rather lack of it
Date: Wed, 4 Apr 2001 11:12:34 +0100
Message-ID: <00bc01c0bcef$c527cf20$6601a8c0@knowledge.com> (raw)

We are building a postgresql based backend database for our 'hosting
provisioning' system. In a vain attempt to add some, what I thought, simple
performance tweaks, I thought I would try putting some of the larger and
more straighforward queries into functions. For everything else the same,
the functions are on the whole slower. Should they be ?

The whole thing is being driver through perl DBI. This may be contributory.

Anyhow, the original query:

SELECT COUNT(mb.instance) FROM domain dm, mail ms, mailbox mb WHERE
        dm.enabled = true and dm.existent = true and dm.available = true AND
        ms.enabled = true and ms.existent = true and ms.available = true AND
        mb.enabled = true and mb.existent = true and mb.available = true AND
        dm.parent = ms.parent AND
        mb.parent = ms.serviceid AND
        dm.instance = $q_domain AND
        mb.instance = $q_local_part;

where $q_XXX are quoted perl scalars. The function is then:

CREATE FUNCTION mail_is_mailbox(text, text) RETURNS int4 AS '
SELECT COUNT(mb.instance) FROM domain dm, mail ms, mailbox mb WHERE
        dm.enabled = true and dm.existent = true and dm.available = true AND
        ms.enabled = true and ms.existent = true and ms.available = true AND
        mb.enabled = true and mb.existent = true and mb.available = true AND
        dm.parent = ms.parent AND
        mb.parent = ms.serviceid AND
        dm.instance = $2 AND
        mb.instance = $1;'
LANGUAGE 'sql';

SELECT mail_is_mailbox($q_local_part, $q_domain);

Running both these 1000 times from a remote (same subnet 100BaseTX) client
with the same query results in time for the function typically 20 - 25% more
than the bare query. 22 vs 16 seconds for example.

I would have thought that not sending the long SQL across the wire 1000
times would have saved some time even without any potential query
optimisations by pre-parsing the SQL ?

rgds,
--
Peter Galbavy
Knowledge Matters Ltd.
http://www.knowledge.com/




view thread (4+ messages)  latest in thread

Message-ID: <00bc01c0bcef$c527cf20$6601a8c0@knowledge.com>
Permalink:  ../00bc01c0bcef$c527cf20$6601a8c0@knowledge.com/
Also on:    postgresql.org/message-id/00bc01c0bcef$c527cf20$6601a8c0@knowledge.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 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-sql@postgresql.org
  Cc: peter.galbavy@knowledge.com
  Subject: Re: performance of functions - or rather lack of it
  In-Reply-To: <00bc01c0bcef$c527cf20$6601a8c0@knowledge.com>
  References: <00bc01c0bcef$c527cf20$6601a8c0@knowledge.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