473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Rules and locking within a transaction?...

Hello,

If I have a rule like this:
CREATE OR REPLACE RULE sometable_update AS ON UPDATE TO table2 DO UPDATE
cache SET updated_dt=NULL WHERE tablename='sometable';
CREATE OR REPLACE RULE sometable_insert AS ON INSERT TO table2 DO UPDATE
cache SET updated_dt=NULL WHERE tablename='sometable';
CREATE OR REPLACE RULE sometable_delete AS ON DELETE TO table2 DO UPDATE
cache SET updated_dt=NULL WHERE tablename='sometable';
Then I begin inserting a bunch of records within a transaction into
table2, like this:
BEGIN;
INSERT INTO table2 (val1, val2) VALUES ('hello','world');
....(etc)
COMMIT;

.... It appears that there is a row lock in cache table for the duration
of the transaction....

First of all, is my premise correct or is there some hidden problem I'm
not seeing?...

Secondly, if there is no hidden problem, is there some way (short of
dropping and recreating the rule) to make it not perform the row lock and
execute the rule at the end of the transaction (if the transaction
succeeds of course)?...

Thanks!

- Greg


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #1
2 3306
Hello,

I have a table that uses tsearch2 and, of course, and index and trigger
to keep everything updated..... Something like:

CREATE TABLE sometable (
id SERIAL,
someinteger INTEGER
sometext TEXT,
sometext2 TEXT,
sometext3 TEXT,
sometext_fti TSVECTOR
);

UPDATE sometable SET sometext_fti=to_tsvector('default',
COALESCE(sometext, ''));
CREATE INDEX sometext_fti_idx ON sometable USING gist(sometext_fti);
CREATE TRIGGER text_update BEFORE UPDATE OR INSERT ON sometable FOR EACH
ROW EXECUTE PROCEDURE tsearch2(sometext_fti, sometable);
There are two issues:

#1. I need a way to be able to do a full-text search any combination of
sometext, sometext2, and sometext3... So far the only way I've been able
to figure out to do this is to actually create additional fields and
indexes for all combinations (a total of 7), like the following:

CREATE TABLE sometable (
id SERIAL,
someinteger INTEGER,
sometext_fti TSVECTOR,
sometext TEXT,
sometext_fti TSVECTOR,
sometext2 TEXT,
sometext2_fti TSVECTOR,
sometext3 TEXT,
sometext3_fti TSVECTOR

sometext1_2_fti TSVECTOR
sometext1_3_fti TSVECTOR
sometext2_3_fti TSVECTOR

sometext1_2_3_fti TSVECTOR

);

UPDATE sometable SET sometext_fti=to_tsvector('default',
COALESCE(sometext, ''));
CREATE INDEX sometext_fti_idx ON sometable USING gist(sometext_fti);
CREATE TRIGGER sometext_update BEFORE UPDATE OR INSERT ON sometable FOR
EACH ROW EXECUTE PROCEDURE tsearch2(sometext_fti, sometable);

UPDATE sometable SET sometext2_fti=to_tsvector('default',
COALESCE(sometext2, ''));
CREATE INDEX sometext2_fti_idx ON sometable USING gist(sometext2_fti);
CREATE TRIGGER sometext2_update BEFORE UPDATE OR INSERT ON sometable FOR
EACH ROW EXECUTE PROCEDURE tsearch2(sometext2_fti, sometable);

UPDATE sometable SET sometext3_fti=to_tsvector('default',
COALESCE(sometext3, ''));
CREATE INDEX sometext3_fti_idx ON sometable USING gist(sometext3_fti);
CREATE TRIGGER sometext3_update BEFORE UPDATE OR INSERT ON sometable FOR
EACH ROW EXECUTE PROCEDURE tsearch2(sometext3_fti, sometable);

UPDATE sometable SET sometext1_2_fti=to_tsvector('default',
COALESCE(sometext1, '')||' '||COALESC(sometext2, ''));
CREATE INDEX sometext1_2_fti_idx ON sometable USING gist(sometext1_2_fti);
CREATE TRIGGER sometext1_2_update BEFORE UPDATE OR INSERT ON sometable
FOR EACH ROW EXECUTE PROCEDURE tsearch2(sometext_1_2_fti, sometable);

UPDATE sometable SET sometext1_3_fti=to_tsvector('default',
COALESCE(sometext1, '')||' '||COALESC(sometext3, ''));
CREATE INDEX sometext1_3_fti_idx ON sometable USING gist(sometext1_3_fti);
CREATE TRIGGER sometext1_3_update BEFORE UPDATE OR INSERT ON sometable
FOR EACH ROW EXECUTE PROCEDURE tsearch2(sometext1_3_fti, sometable);

UPDATE sometable SET sometext2_3_fti=to_tsvector('default',
COALESCE(sometext2, '')||' '||COALESC(sometext3, ''));
CREATE INDEX sometext2_3_fti_idx ON sometable USING gist(sometext2_3_fti);
CREATE TRIGGER sometext2_3_update BEFORE UPDATE OR INSERT ON sometable
FOR EACH ROW EXECUTE PROCEDURE tsearch2(sometext2_3_fti, sometable);

UPDATE sometable SET sometext1_2_3_fti=to_tsvector('default',
COALESCE(sometext1, '')||' '||COALESCE(sometext2, '')||'
'||COALESC(sometext3, ''));
CREATE INDEX sometext1_2_3_fti_idx ON sometable USING gist(sometext1_2_3_fti);
CREATE TRIGGER sometext1_2_3_update BEFORE UPDATE OR INSERT ON sometable
FOR EACH ROW EXECUTE PROCEDURE tsearch2(sometext1_2_3_fti, sometable);

.... of course, this creates an enormous load on the server for any
update/delete operation... I tried just creating 3 indexes (one for each
field) and doing a query like:

SELECT * FROM sometable WHERE sometext1 @@ to_tsquery('default',
'postgres') OR sometext2 @@ to_tsquery('default', 'postgres') OR
sometext3 @@ to_tsquery('default', 'postgres') -- but found this to be
enormously expensive for queries....

... with the arrangement above, I make some decision as to which field to
query, for example:

SELECT * FROM sometable WHERE sometext1_2_3 @@ to_tsquery('default',
'postgres'); -- this executes MUCH faster
... is there some way to get the best of both worlds here or am I trying
to jam a square peg into a round hole?...

#2. When doing an update on the above table, such as: "UPDATE sometable
SET someinteger=0", it ends up firing off the triggers which of course
takes a long time to update... Is there someway to make the trigger only
fire if a the field it is tied to is updated?.... This is not a

Thanks as always!
- Greg

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #2
On Fri, 15 Oct 2004, Net Virtual Mailing Lists wrote:
Hello,

I have a table that uses tsearch2 and, of course, and index and trigger
to keep everything updated..... Something like:

CREATE TABLE sometable (
id SERIAL,
someinteger INTEGER
sometext TEXT,
sometext2 TEXT,
sometext3 TEXT,
sometext_fti TSVECTOR
);

There are two issues:

#1. I need a way to be able to do a full-text search any combination of
sometext, sometext2, and sometext3... So far the only way I've been able
.. is there some way to get the best of both worlds here or am I trying
to jam a square peg into a round hole?...
Hmm, probably :)
There is a hint on http://www.sai.msu.su/~megera/oddmus...earch_V2_Notes
under section "Restricted search".


#2. When doing an update on the above table, such as: "UPDATE sometable
SET someinteger=0", it ends up firing off the triggers which of course
takes a long time to update... Is there someway to make the trigger only
fire if a the field it is tied to is updated?.... This is not a

no idea, sorry
Thanks as always!
- Greg

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Regards,
Oleg
__________________________________________________ ___________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: ol**@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Alban Hertroys | last post by:
Good day, I have a number of threads doing inserts in a table, after which I want to do a select. This means that it will occur that the row that I want to select is locked (by the DB). In these...
0
by: Wayne Smallman | last post by:
OK, anyone have some advice on implementing the likes of SELECT ... FOR UPDATE / SELECT ... LOCK IN SHARE MODE? I'm trying to get it working in conjunction with the transaction facilities built...
9
by: john smile | last post by:
Hi All, I want to lock 2 tables on 2 servers using TABLOCKX hint. These tables function as semaphores in my application. It means when the tables are locked then other users will not be able to...
3
by: heynothanks | last post by:
(MSSQL2000) I have read the transaction/locking sections in the MS-help, online and several books. What I want to understand is the transaction behavior in single statements . If I have a...
16
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
3
by: mahajan.sanjeev | last post by:
Hi All, I am using a SQLTransaction to insert records into a table. At one time, there are 5000 or more records to be inserted one by one. It takes some 20-25 mins for the entire process to run....
2
by: Matt | last post by:
I run SQL Server 2000 and use thier database maintenance plans to backup my databases. My questions is what happens if a change is being made to a database table while a backup is running? Should I...
8
by: dan.c.roth | last post by:
Hi I am having a debate with one of the Postgres developers (Tom Lane) according to him ms-sql does not implement predicate locking(SERIALIZABLE). Where predicate locking is defined as (from...
6
by: shaanxxx | last post by:
I have global variable which is being shared between threads (problem is not connected with thread). Without using any mutex i have do some operation global variable in *consistent* way. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.