![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
I found this post http://groups.google.ca/group/comp.d...5694324f276587 which sounds very promising, but I'd like a more explicit example. That is, I don't follow how to encapsulate the update within the select. Could someone flesh it out somewhat? |
#4
| |||
| |||
|
|
Did that help? I'm not sure what it is you would like to have explained, so perhaps you can post an example of what it is you would like to solve? |
#5
| |||
| |||
|
|
On Nov 20, 6:58 pm, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com wrote: Did that help? I'm not sure what it is you would like to have explained, so perhaps you can post an example of what it is you would like to solve? Many thanks for the prompt and illuminating reply. What I want is something analogous to this: (It is part of a trigger, so the table aliased as O in the example below is the Old value). update pb set sts = 'new status' -- and some other values where exists ( select 1 from umx X, par A where X . hashkey = O . hashkey and X . repnbr = PB . rpnr and X . rrrn = PB . RRRN and x.repnbr = a.repnbr and a.repsts = '12' and reptpe = '34' ) ; Some of these tables contains A LOT of rows so the above works technically, but not sufficiently efficient (particularly since triggers are synchronous). The subquery above performs horribly but in a normal select situation with a CTE it would be very efficient. What I would like is that the subquery is evaluated first and only those rows are searched (i.e. materialization instead of composition). But the WHERE EXISTS is not that smart and the performance is infinitely worse. So basically, and update with a similar syntax and performance like this: with p(a, b) as ( select repnbr, rownbr from pa join umx x on rpnr=repnbr where reptpe = '34' and repsts = '12' and x.hashkey=o.hashkey) select * -- should be a searched update based on a and b columns from p join pb using(a, b); Thank you again. |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
Thanks a lot, again. I managed to find a decent performing solution still using the WHERE EXISTS method (an additional WHERE repnbr IN subquery), but I will look evaluate your proposal too. It's looks more neat. |
![]() |
| Thread Tools | |
| Display Modes | |
| |