Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > HOWTO caching d...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 12 Topic 15118 of 17637
Post > Topic >>

HOWTO caching data across function calls: tem****ary tables, cursor?

by mail@[EMAIL PROTECTED] (Ivan Sergio Borgonovo) Apr 1, 2008 at 10:57 AM

I made a similar question but maybe it was not that clear.

I've a large table (items) linked with other tables (attributes).

Some product ends into a basket.

create table items(
  item_id serial primary key,
  attributes...
);

create table item_attributes(
  item_id int references items (item_id)
  attributes...
);

create table baskets(
  basket_id serial primary key,
  ...other stuff
);
create table basket_items(
  item_id int references items (item_id),
  basket_id int references baskets (basket_id),
  ...
);


I've a bunch of functions that operates on the basket (a smaller list
of products with their attributes).

So many functions ends up in repeating over and over a select similar
to:

select [list of columns] from baskets b
join basket_items bi on b.basket_=bi.basket_id
join items i on i.item_id=bi.item_id
join item_attributes a a.item_id=i.item_id
where b.basket_id=$1

It would be nice if I could avoid to execute this query over and over.
I'd have to find a way to pass this data across functions.

One way would be to put this data in a tem****ary table, but many
things are unclear to me.
I still have to find a way to reference these tables across functions
(there will be different basket_id, and each transaction should see
the same temp table and not "steal" the one of other transactions).
I've to take care of name clash and visibility.
I need to take care of garbage collection at the right time.
I've no idea of the performance gain.
Caching of queries in function (relation with OID ##### does not
exist) and all the above make the use of temp tables a bit
overwhelming.

It seems that another way would be to use cursors... but I haven't
been able to find any example.

I think this is a common problem but I can't find general guidelines.

I'm on 8.1

thanks

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it


-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 12 Posts in Topic:
HOWTO caching data across function calls: temporary tables, curs
mail@[EMAIL PROTECTED] (  2008-04-01 10:57:17 
Re: HOWTO caching data across function calls: temporary tables,
laurenz.albe@[EMAIL PROTE  2008-04-01 12:01:21 
Re: HOWTO caching data across function calls: temporary
mail@[EMAIL PROTECTED] (  2008-04-01 13:32:04 
Re: HOWTO caching data across function calls: temporary tables,
laurenz.albe@[EMAIL PROTE  2008-04-01 14:00:39 
Re: HOWTO caching data across function calls: temporary
mail@[EMAIL PROTECTED] (  2008-04-01 15:00:41 
Re: HOWTO caching data across function calls: temporary tables,
laurenz.albe@[EMAIL PROTE  2008-04-01 16:08:45 
optimiser STABLE vs. temp table was: HOWTO caching data across
mail@[EMAIL PROTECTED] (  2008-04-01 16:54:12 
Re: optimiser STABLE vs. temp table was: HOWTO caching data acro
tgl@[EMAIL PROTECTED] (T  2008-04-01 11:22:20 
Re: optimiser STABLE vs. temp table was: HOWTO caching
mail@[EMAIL PROTECTED] (  2008-04-01 18:06:35 
Re: optimiser STABLE vs. temp table was: HOWTO caching data acro
kleptog@[EMAIL PROTECTED]  2008-04-01 18:32:25 
Re: optimiser STABLE vs. temp table was: HOWTO caching data acro
laurenz.albe@[EMAIL PROTE  2008-04-02 10:11:52 
still on techniques to cache table slices was: optimiser STABLE
mail@[EMAIL PROTECTED] (  2008-04-01 19:34:10 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 7:23:50 CST 2008.