LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 10 Jun 2004 14:05:57 +0300
Reply-To:   arjen.raateland@ymparisto.fi
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Arjen Raateland <arjen.raateland@YMPARISTO.FI>
Organization:   Suomen ympäristökeskus
Subject:   Re: SQL Update & index use?
Content-Type:   text/plain; charset=us-ascii

Sigurd Hermansen wrote:

> In SAS SQL, the EXISTS query in general, and specifically the second > subquery in the UPDATE query, take relatively a long time to execute. I > prefer an UPDATE query that does not require an EXISTS subquery: > > proc sql UNDO_POLICY=NONE; > update test r > set val=coalesce(( > select k.val from > transUpd k > where r.ID=k.ID > ),r.val) > ; > quit; > > The EXISTS clause tends to work much faster in Oracle. I believe that the > COALESCE() accomplishes the same purpose and will work much faster.

It looks elegant, but it takes a lot more time to execute than the update with double subquery and as one can see the coalesce-version updates each and every row. (Table A and its index table are copies of the original Rakennus & its index table.)

Updating all rows instead of just the 7 that have changes to be applied didn't take terribly long, though. I ran both versions with the STIMER option. See log below. Not a great difference in execution time. In fact updating 7 rows took more cpu time than updating all rows. How about that?

Still no use of the index on rakennustunnus that both tables have. Is the index useless here? Why?

NOTE: Statement transforms to:

update LOCAL.A R set kerrosala = COALESCE( ( select K.kerrosala from LOCAL.RAKENNUS_KERROSALAN_KORJAUKSET K where R.rakennustunnus=K.rakennustunnus ), R.kerrosala);

WARNING: The SQL option UNDO_POLICY=REQUIRED is not in effect. If an error is detected when processing this UPDATE statement, that error will not cause the entire statement to fail. NOTE: 2788285 rows were updated in LOCAL.A.

NOTE: SQL Statement used: real time 3:54.14 cpu time 2:07.37

Statement lines removed, because the feedback option prints a second, transformed version of the statement ....

WARNING: A value expression of the SET clause references the data set being updated. NOTE: Statement transforms to:

update LOCAL.RAKENNUS R set kerrosala = ( select K.kerrosala from LOCAL.RAKENNUS_KERROSALAN_KORJAUKSET K where R.rakennustunnus=K.rakennustunnus ) where exists ( select * from LOCAL.RAKENNUS_KERROSALAN_KORJAUKSET K where R.rakennustunnus=K.rakennustunnus );

WARNING: The SQL option UNDO_POLICY=REQUIRED is not in effect. If an error is detected when processing this UPDATE statement, that error will not cause the entire statement to fail. NOTE: 7 rows were updated in LOCAL.RAKENNUS.

NOTE: SQL Statement used: real time 3:46.03 cpu time 3:46.03

-- Mr. Arjen Raateland Finnish Environment Institute SYKE Research Dept. SAS Support phone +358 9 4030 0350


Back to: Top of message | Previous page | Main SAS-L page