 |
|
 |
|
Next: Call for Papers: The Alberto Mendelzon Workshop o..
|
| Author |
Message |
External

Since: Feb 07, 2008 Posts: 126
|
(Msg. 16) Posted: Tue Aug 05, 2008 12:16 pm
Post subject: Re: SQL BEFORE puzzle [Login to view extended thread Info.] Archived from groups: comp>databases>theory (more info?)
|
|
|
On 5 août, 14:35, kschendel wrote:
> On Aug 4, 4:32 pm, Bob Badour wrote:
>
> > I would expect both the BEFORE and AFTER triggers to have a view of both
> > the before and after images of the data. I don't really see the need for
> > before and after triggers. Perhaps I am just missing it.
> I think it's largely for practical reasons.
> An AFTER trigger operates on a row that has already been
> physically placed somewhere in the table/index. If the trigger
> wants to alter a key value, the row probably has to move,
> and you end up with physical storage issues. BEFORE
> triggers avoid this, so they are preferred if part of the
> action is to calculate or update primary or secondary
> key columns.
>
> Of course this is all implementation dependent, but
> I suspect most implementations would work that way.
The AFTER trigger is a mechanism that can allow non database related
operations to be performed independently from the context of a db
engine. One may for instance add a line in order table and trigger
the transfer of a file to an FTP server. In the absolute they should
not be needed but dbms's support for workflow operations is very poor.
Hope this helps. >> Stay informed about: SQL BEFORE puzzle |
|
| Back to top |
|
 |  |
External

Since: Jan 22, 2008 Posts: 177
|
(Msg. 17) Posted: Wed Aug 06, 2008 7:21 pm
Post subject: Re: SQL BEFORE puzzle [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Aug 6, 3:16 am, Cimode wrote:
> On 5 août, 14:35, kschendel wrote:
>
>
>
>
>
> > On Aug 4, 4:32 pm, Bob Badour wrote:
>
> > > I would expect both the BEFORE and AFTER triggers to have a view of both
> > > the before and after images of the data. I don't really see the need for
> > > before and after triggers. Perhaps I am just missing it.
> > I think it's largely for practical reasons.
> > An AFTER trigger operates on a row that has already been
> > physically placed somewhere in the table/index. If the trigger
> > wants to alter a key value, the row probably has to move,
> > and you end up with physical storage issues. BEFORE
> > triggers avoid this, so they are preferred if part of the
> > action is to calculate or update primary or secondary
> > key columns.
>
> > Of course this is all implementation dependent, but
> > I suspect most implementations would work that way.
>
> The AFTER trigger is a mechanism that can allow non database related
> operations to be performed independently from the context of a db
> engine. One may for instance add a line in order table and trigger
> the transfer of a file to an FTP server. In the absolute they should
> not be needed but dbms's support for workflow operations is very poor.
AFAIK an AFTER trigger is normally called synchronously by the thread
doing the transaction and before it commits or rolls back. There are
two reasons to be wary of interacting with an external system in the
way you describe: Firstly because most generally the transaction can
actually roll back it may create some inconsistency (ie telling a
remote system that something happened when it actually did not).
Secondly, the original transaction will be made to block while these
additional time consuming activities (like FTP) are being performed –
therefore locks won’t be released quickly and concurrency will be
badly affected. Note as well that sending a file using FTP would
normally only need read access to the local DB so doing this within a
mutative transaction (ie from an AFTER trigger) would lose the
benefits of MVCC.
It is generally better to use a separate (and therefore asynchronous
thread) that uses read only transactions to send changes to another
system. Often sequence numbers or time stamps can be used to ensure
it only sends new content. This can often be made resilient to
inconsistency problems if the receiver records where it is up to and
this information is sent to the sender as part of their initial
handshake in the communication protocol. This actually avoids the
need for distributed transactions (ie multiphase commit).
A very useful technique is for an AFTER trigger to signal an
asynchronous thread that is sleeping on a waitable object such as a
semaphore. >> Stay informed about: SQL BEFORE puzzle |
|
| Back to top |
|
 |  |
External

Since: Aug 11, 2008 Posts: 2
|
(Msg. 18) Posted: Mon Aug 11, 2008 11:29 am
Post subject: Re: SQL BEFORE puzzle [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
This was the reason given in,
Cochrane, R., Pirahesh, H. and Mattos, N. M. Integrating Triggers and
Declarative Constraints in SQL Database Sytems. In: Proceedings of the 22nd
VLDB Conference. Mumbai, India. Morgan Kaufmann, 1996.
which I believe heavily influenced the SQL Standard on triggers.
"Brian Selzer" wrote in message
.....
>
> I would think that the restriction is supposed to prevent something like:
>
> update T ....
> beforeT: update T ....
> beforeT: update T ....
> beforeT: update T ....
> ...and so on....
> ...and so on....
> ...and so on....
>
> where the pending updates would pile up. Note that:
>
> update T ....
> afterT: update T ....
> afterT: update T ....
> afterT: update T ....
> ...and so on....
> ...and so on....
> ...and so on....
>
> wouldn't cause the updates to pile up (even though the transaction
> controlling them would remain outstanding) because instead of being held
> waiting to be applied to the table as in the case of before triggers, they
> would have already been applied before each subsequent afterT is executed,
> making the recursive afterT more like just an iteration of updates within
> a transaction. >> Stay informed about: SQL BEFORE puzzle |
|
| Back to top |
|
 |  |
| Related Topics: | Problem with Nested Sets - Hello, I have a table which represents a tree of forums using nested sets. Here are the fields: id, root_id, left, right, level, label. I have a string which is like a path. For example, Forum/Sub-forum/Sub-sub-forum I want to get the id of the forum..
space filling curves - I recently started reading about various ways of making various functions of a DB faster...and I keep running into space filling curves. Unfortunately, I just can't grasp the concept. Following is what I understand so far, I'll appreciate it if someone...
can two stored procedures in same transaction cause deadlock - Hi, We are experiencing a deadlock issue using MS SQL 2000 that's generating some debate in our office. We have two stored procedures SP1 and SP2 running in the same transaction along with couple other stored procedures, SP1 does a deletion on one..
Relation Definition - I'll try this another way (persistence is my middle name?). I use a precise definition of "relation" from mathematics. It is in the glossary mAsterdam collected that I sent out a few days ago. However, it seems that most folks here use so...
grouping in tuple relational calculus - Does anybody know how to represent grouping queries in tuple relational calculus? either that or an extension that allows such operations ? (avg, sum, etc) any pointers will be very wellcome! Thanks in advance! antonio |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|