dbTalk Databases Forums  

[Info-Ingres] Rules vs. table structure..who wins?

comp.databases.ingres comp.databases.ingres


Discuss [Info-Ingres] Rules vs. table structure..who wins? in the comp.databases.ingres forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Martin Bowes
 
Posts: n/a

Default [Info-Ingres] Rules vs. table structure..who wins? - 04-21-2010 , 06:17 AM






Hi All,



We all know that when a table has multiple rules acting on it that the
order of firing for the rules cannot be garunteed.

But what about this...



Consider a table with a rules fired procedure and a unique index. (There
is no unique constraint)



An action occurs that causes the rule to fire.



The RFP then performs an act that causes a uniqueness violation in the
index.



Whose error processing takes over?



At the moment it appears to me that the index wins...and generates an
appropriate error message, and the rule is stopped dead. The rules error
processing never gets to fire off.



Is this the correct action?



I would have thought the rfps error processing would have been triggered
with the error code being passed back and available from iierrornumber
as per usual.



Martin Bowes

Reply With Quote
  #2  
Old   
Ingres Forums
 
Posts: n/a

Default Re: [Info-Ingres] Rules vs. table structure..who wins? - 04-21-2010 , 09:05 AM






On first glance it certainly seems to me that the SQL statement in the
procedure should receive the error and be allowed to process it internal
to the rule. Stopping the entire rule/procedure process seem like it
would significant affect the flexibility of the procedure author to
handle problems.

How do other databases handle errors in rule(trigger) fired db
procedures?


--
daryl.monge (AT) ingres (DOT) com
------------------------------------------------------------------------
daryl.monge (AT) ingres (DOT) com's Profile: http://community.ingres.com/forum/member.php?userid=736
View this thread: http://community.ingres.com/forum/sh...ad.php?t=11922

Reply With Quote
  #3  
Old   
Paul Mason
 
Posts: n/a

Default Re: [Info-Ingres] Rules vs. table structure..who wins? - 04-21-2010 , 09:53 AM



Quote:
From the SQL Guide:


"When an error occurs in a database procedure, the behavior of the DBMS
Server depends on whether the procedure was invoked by a rule or
executed directly (using EXECUTE PROCEDURE).



If the procedure was invoked by a rule, an error has the following
effects:

.. The procedure is terminated.

.. Those statements in the procedure which have been executed are rolled
back.

.. The statement that fired the rule is rolled back.



If the procedure was executed directly, an error has the following
effects:

.. All statements in the procedure up to the point of the error are
rolled back.

.. The procedure continues execution with the statement following the
statement that caused the error.

.. Parameters passed by reference are not updated."



So the error behaviour you're seeing is the documented behaviour.



Regards

Paul





From: info-ingres-bounces (AT) kettleriver...ting (DOT) com
[mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com] On Behalf Of
Martin Bowes
Sent: 21 April 2010 12:17
To: Ingres and related product discussion forum
Subject: [Info-Ingres] Rules vs. table structure..who wins?



Hi All,



We all know that when a table has multiple rules acting on it that the
order of firing for the rules cannot be garunteed.

But what about this...



Consider a table with a rules fired procedure and a unique index. (There
is no unique constraint)



An action occurs that causes the rule to fire.



The RFP then performs an act that causes a uniqueness violation in the
index.



Whose error processing takes over?



At the moment it appears to me that the index wins...and generates an
appropriate error message, and the rule is stopped dead. The rules error
processing never gets to fire off.



Is this the correct action?



I would have thought the rfps error processing would have been triggered
with the error code being passed back and available from iierrornumber
as per usual.



Martin Bowes

Reply With Quote
  #4  
Old   
John Smedley
 
Posts: n/a

Default Re: [Info-Ingres] Rules vs. table structure..who wins? - 04-21-2010 , 09:56 AM



In the SQL Guide it states:

Effects of Errors in Database Procedures

When an error occurs in a database procedure, the behaviour of the DBMS
Server depends on whether the procedure was invoked by a rule or
executed directly (using EXECUTE PROCEDURE).
If the procedure was invoked by a rule, an error has the following
effects:
* The procedure is terminated.
* Those statements in the procedure which have been executed are rolled
back.
* The statement that fired the rule is rolled back.

If the procedure was executed directly, an error has the following
effects:
* All statements in the procedure up to the point of the error are
rolled back.
* The procedure continues execution with the statement following the
statement that caused the error.
* Parameters passed by reference are not updated.

In both instances, the error is returned to the application in SQLSTATE,
SQLCODE and ERRORNO. In the case of the directly executed procedure, an
error number is also returned to iierrornumber, a built-in variable
available only in database procedures for error handling.


Which means that if you include "error handling" in a database procedure
called by a rule it will not get executed as the procedure is terminated
by the error.


John Smedley



-----Original Message-----
From: info-ingres-bounces (AT) kettleriver...ting (DOT) com
[mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com] On Behalf Of
Ingres Forums
Sent: 21 April 2010 15:06
To: info-ingres (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] Rules vs. table structure..who wins?


On first glance it certainly seems to me that the SQL statement in the
procedure should receive the error and be allowed to process it internal
to the rule. Stopping the entire rule/procedure process seem like it
would significant affect the flexibility of the procedure author to
handle problems.

How do other databases handle errors in rule(trigger) fired db
procedures?


--
daryl.monge (AT) ingres (DOT) com
------------------------------------------------------------------------
daryl.monge (AT) ingres (DOT) com's Profile:
http://community.ingres.com/forum/member.php?userid=736
View this thread:
http://community.ingres.com/forum/sh...ad.php?t=11922

_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://ext-cando.kettleriverconsulti...fo/info-ingres

Reply With Quote
  #5  
Old   
Ingres Forums
 
Posts: n/a

Default Re: [Info-Ingres] Rules vs. table structure..who wins? - 04-21-2010 , 12:44 PM



Of course we can postulate that being documented doesn't make it
"correct". I can easily imagine a procedure that wants to test for
duplicates and perform some other action, even in a rule. We need to
distinguish between real DBMS errors (out of disk space, log full) and
application semantic errors such as "duplicate key". Consider I want to
do this:
insert into table values ()
if (duplicate) then do something else.

With the current error handling system, I have to write needlessly more
complex code
select count(*) from ... where somecriteria
if thecount == 0 then
insert into table values ()
else
do something else

(I have not tested this. Does the procedure >>really<< fail in this
case?)


--
daryl.monge (AT) ingres (DOT) com
------------------------------------------------------------------------
daryl.monge (AT) ingres (DOT) com's Profile: http://community.ingres.com/forum/member.php?userid=736
View this thread: http://community.ingres.com/forum/sh...ad.php?t=11923

Reply With Quote
  #6  
Old   
Jeremy peel
 
Posts: n/a

Default Re: [Info-Ingres] Rules vs. table structure..who wins? - 04-22-2010 , 02:38 AM



Hello All,

I would hardly describe "duplicate key" as an *application semantic* error,
surely
this is a table constraint violation?

Some other DBMSen allow you to prioritize rules but I do not know how they
deal
with constraint violations vs. rule invocation.

Jo

On Wed, Apr 21, 2010 at 7:44 PM, Ingres Forums <
info-ingres (AT) kettleriverconsulting (DOT) com> wrote:

Quote:
Of course we can postulate that being documented doesn't make it
"correct". I can easily imagine a procedure that wants to test for
duplicates and perform some other action, even in a rule. We need to
distinguish between real DBMS errors (out of disk space, log full) and
application semantic errors such as "duplicate key". Consider I want to
do this:
insert into table values ()
if (duplicate) then do something else.

With the current error handling system, I have to write needlessly more
complex code
select count(*) from ... where somecriteria
if thecount == 0 then
insert into table values ()
else
do something else

(I have not tested this. Does the procedure >>really<< fail in this
case?)


--
daryl.monge (AT) ingres (DOT) com
------------------------------------------------------------------------
daryl.monge (AT) ingres (DOT) com's Profile:
http://community.ingres.com/forum/member.php?userid=736
View this thread: http://community.ingres.com/forum/sh...ad.php?t=11923

_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://ext-cando.kettleriverconsulti...fo/info-ingres



--
Jeremy Peel

Reply With Quote
  #7  
Old   
Martin Bowes
 
Posts: n/a

Default Re: [Info-Ingres] Rules vs. table structure..who wins? - 04-22-2010 , 03:58 AM



Hi John et al,

Thanks for that reminder ... I'd forgotten.

Marty

-----Original Message-----
From: John Smedley [mailto:John.Smedley (AT) ingres (DOT) com]
Sent: 21 April 2010 15:57
To: Ingres and related product discussion forum
Subject: Re: [Info-Ingres] Rules vs. table structure..who wins?

In the SQL Guide it states:

Effects of Errors in Database Procedures

When an error occurs in a database procedure, the behaviour of the DBMS
Server depends on whether the procedure was invoked by a rule or
executed directly (using EXECUTE PROCEDURE).
If the procedure was invoked by a rule, an error has the following
effects:
* The procedure is terminated.
* Those statements in the procedure which have been executed are rolled
back.
* The statement that fired the rule is rolled back.

If the procedure was executed directly, an error has the following
effects:
* All statements in the procedure up to the point of the error are
rolled back.
* The procedure continues execution with the statement following the
statement that caused the error.
* Parameters passed by reference are not updated.

In both instances, the error is returned to the application in SQLSTATE,
SQLCODE and ERRORNO. In the case of the directly executed procedure, an
error number is also returned to iierrornumber, a built-in variable
available only in database procedures for error handling.


Which means that if you include "error handling" in a database procedure
called by a rule it will not get executed as the procedure is terminated
by the error.


John Smedley



-----Original Message-----
From: info-ingres-bounces (AT) kettleriver...ting (DOT) com
[mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com] On Behalf Of
Ingres Forums
Sent: 21 April 2010 15:06
To: info-ingres (AT) kettleriverconsulting (DOT) com
Subject: Re: [Info-Ingres] Rules vs. table structure..who wins?


On first glance it certainly seems to me that the SQL statement in the
procedure should receive the error and be allowed to process it internal
to the rule. Stopping the entire rule/procedure process seem like it
would significant affect the flexibility of the procedure author to
handle problems.

How do other databases handle errors in rule(trigger) fired db
procedures?


--
daryl.monge (AT) ingres (DOT) com
------------------------------------------------------------------------
daryl.monge (AT) ingres (DOT) com's Profile:
http://community.ingres.com/forum/member.php?userid=736
View this thread:
http://community.ingres.com/forum/sh...ad.php?t=11922

_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://ext-cando.kettleriverconsulti...fo/info-ingres


_______________________________________________
Info-Ingres mailing list
Info-Ingres (AT) kettleriverconsulting (DOT) com
http://ext-cando.kettleriverconsulti...fo/info-ingres

Reply With Quote
  #8  
Old   
Martin Bowes
 
Posts: n/a

Default Re: [Info-Ingres] Rules vs. table structure..who wins? - 04-22-2010 , 04:23 AM



Quote:
On first glance it certainly seems to me that the SQL statement in the

procedure should receive the error and be allowed to process it
internal

Quote:
to the rule. Stopping the entire rule/procedure process seem like it
would

Quote:
significant affect the flexibility of the procedure author to handle
problems.



You probably want to be careful there. The RFP failed on a significant
constraint error. If it was allowed to continue and do its own error
processing....what would happen if I didn't process the error and then
run more queries which worked, what then would be the error status of
the RFP?



BTW. I just tried an experiment in 9.2.0 where I got the RFP to directly
execute a sub procedure.

I hoped that the DEP would get to do the error processing ... but it was
smarter than me and the RFP rule on error processing was still applied.
The DEP never got to do the error code stuff. Whis is probably for the
best.



In this particular case, I could rewrite my RFP to check before its
attempt at the update to see if the coast is clear.



An alternative would be to consider a BEFORE trigger.



Marty

Reply With Quote
  #9  
Old   
David Stephens
 
Posts: n/a

Default Re: [Info-Ingres] Rules vs. table structure..who wins? - 04-22-2010 , 05:17 AM



Hi all,

"duplicate key" errors tend to be dealt with quite brutally by ingres - they blow out cursors quite nicely unless you have the
trace point switched on. :-)

Dave.

-----Original Message-----
From: info-ingres-bounces (AT) kettleriver...ting (DOT) com [mailto:info-ingres-bounces (AT) kettleriverconsulting (DOT) com]On Behalf Of Martin Bowes
Sent: 22 April 2010 10:23
To: daryl.monge (AT) ingres (DOT) com
Cc: Ingres and related product discussion forum
Subject: Re: [Info-Ingres] Rules vs. table structure..who wins?



Quote:
On first glance it certainly seems to me that the SQL statement in the

procedure should receive the error and be allowed to process it internal

to the rule. Stopping the entire rule/procedure process seem like it would

significant affect the flexibility of the procedure author to handle problems.


You probably want to be careful there. The RFP failed on a significant constraint error. If it was allowed to continue and do its own error processing....what would happen if I didn't process the error and then run more queries which worked, what then would be the error status of the RFP?



BTW. I just tried an experiment in 9.2.0 where I got the RFP to directly execute a sub procedure.

I hoped that the DEP would get to do the error processing ... but it was smarter than me and the RFP rule on error processing was still applied. TheDEP never got to do the error code stuff. Whis is probably for the best.



In this particular case, I could rewrite my RFP to check before its attempt at the update to see if the coast is clear.



An alternative would be to consider a BEFORE trigger.



Marty






__________________________________________________ ____________
This message has been scanned for all viruses by BTnet VirusScreen.
The service is delivered in partnership with MessageLabs.

This service does not scan any password protected or encrypted
attachments.



__________________________________________________ ____________

This message has been checked for all viruses by BTnet VirusScreen.
The service is delivered in partnership with MessageLabs and does not scan any password protected or encrypted attachments.

Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of the company. The contents of this email are confidential to the addressee and may also be privileged. If you are not the addressee of this email, you must not copy, forward, disclose or otherwise use it, or any part of it, for anypurpose, nor disclose its contents to any other person. If you have received this email in error please notify the sender. Please be aware that any email sent to, or received from, this address may be monitored for quality control, staff training or security purposes. Although the company scans all outgoing email and attachments for viruses, neither the sender nor the company accepts any responsibility for viruses and it remains the responsibility of the recipient to scan email and attachments (if any) for viruses.

Reply With Quote
  #10  
Old   
James K. Lowden
 
Posts: n/a

Default Re: [Info-Ingres] Rules vs. table structure..who wins? - 04-28-2010 , 07:47 PM



Ingres Forums wrote:
Quote:
How do other databases handle errors in rule(trigger) fired db
procedures?
The ones I know roll back the transaction and cancel the command batch.

It must be so, else user code could subvert the atomic guarantees made by
the RDBMS. If the procedure code could catch and "deal with" RI errors,
how could the server continue to ensure said RI? At some point, it's not
up to the code.

The only right way to prevent RI errors in procedural code is to verify
preconditions *before* affecting the data.

--jkl

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.