From: | "Mike" <mike(at)mrhost(dot)ca> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Caching/Indexing Function Output |
Date: | 2004-12-23 21:22:42 |
Message-ID: | 1bbe01c4e935$8a54ac80$0201000a@ehj9vn81i9b95wa |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
I've written several functions using the SPI_ interface, some of them are to
simply ease inserting into a few tables-
ie- I wrote a function sp_host('10.0.0.1'); which returns the id of the
given
ip address from a ip_addresses table if it exists, otherwise, it inserts it,
and
returns that id. We use this to keep the logic simple when inserting new
entries
into a weblogs table-
insert into weblogs (..., host) values (..., sp_host('10.0.0.1'));
We also use this for a dozen or so other similar tables-
My question is- is there anyway, since a call to sp_host('10.0.0.1') will
always
return the same value (the primary key/sequence value from the ip_addresses
table), to cache/index that value somehow, so anytime I ever call that same
function, with the same argument, it returns a cached/indexed value?
ie- I make an initial call to sp_host('10.0.0.1'), which returns the id
1000; the
system caches this, and stores:
function=sp_host, arg='10.0.0.1', return=1000
or
key=sp_host('10.0.0.1'), value=1000
the next time I call sp_host, with the same arg, it simply returns 1000,
instead
of actually calling the function?
clearly I don't want to do this for *all* the functions I've written, but it
would
probably speed these functions up considerably?
Thanks!
Mike Pultz
mike(at)mrhost(dot)ca
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2004-12-23 22:07:58 | Re: BTree max row size? |
Previous Message | Együd Csaba (Freemail) | 2004-12-23 20:48:56 | Re: Very slow stored proc |