dbTalk Databases Forums  

Temporarily disable rule, is this possible?

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss Temporarily disable rule, is this possible? in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Net Virtual Mailing Lists
 
Posts: n/a

Default Temporarily disable rule, is this possible? - 11-06-2004 , 10:48 AM






Hello,

I have a table with a rule that goes something like this:

CREATE OR REPLACE RULE sometable_delete ON DELETE DO delete FROM cache
WHERE tablename='sometable';
CREATE OR REPLACE RULE sometable_insert ON INSERT DO delete FROM cache
WHERE tablename='sometable';
CREATE OR REPLACE RULE sometable_update ON UPDATE DO delete FROM cache
WHERE tablename='sometable';

And what I have is set of objects which for certain queries will populate
a serialized variable into the cache table, like this:

INSERT INTO cache (tablename, cache_key, datavalue) VALUES ('sometable',
'some_md5_hash', 'serialized_data');


Using this method it is possible for me to just do a:

SELECT datavalue FROM cache WHERE tablename='sometable' AND
cache_key='some_md5_hash';

... and if I get an empty value for datavalue then execute the query
normally, process it, then store the serialized data back into the cache...

This all works very well for this situation, it has sped up my
application about 20 times for 95% of the requests....

The problem I have is there are frequently times I need to update
sometable and not have the rule execute, specifically when I am updating
something in the table which does not affect aggregate results.

Is there a way to cause the rules to be temporarily disabled for these
types of queries?

Thanks!

- Greg


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
  #2  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: Temporarily disable rule, is this possible? - 11-07-2004 , 12:47 PM






mailinglists (AT) net-virtual (DOT) com ("Net Virtual Mailing Lists") wrote:

Quote:
CREATE OR REPLACE RULE sometable_delete ON DELETE DO delete FROM cache
WHERE tablename='sometable';
CREATE OR REPLACE RULE sometable_insert ON INSERT DO delete FROM cache
WHERE tablename='sometable';
CREATE OR REPLACE RULE sometable_update ON UPDATE DO delete FROM cache
WHERE tablename='sometable';

And what I have is set of objects which for certain queries will populate
a serialized variable into the cache table, like this:

INSERT INTO cache (tablename, cache_key, datavalue) VALUES ('sometable',
'some_md5_hash', 'serialized_data');


Using this method it is possible for me to just do a:

SELECT datavalue FROM cache WHERE tablename='sometable' AND
cache_key='some_md5_hash';

.. and if I get an empty value for datavalue then execute the query
normally, process it, then store the serialized data back into the cache...

This all works very well for this situation, it has sped up my
application about 20 times for 95% of the requests....

The problem I have is there are frequently times I need to update
sometable and not have the rule execute, specifically when I am updating
something in the table which does not affect aggregate results.

Is there a way to cause the rules to be temporarily disabled for these
types of queries?
Not that I know of (apart from doing a remove/add). However, possibly
if you were to add a view which had update rules to do the update on the
real table as well as the cache changes you could then update the real table
manually and not affect the cache (although you could then not guarantee
that someone wouldn't do something that would affect the cache directly).




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.