Re: Stored Procedures and querries.
Posted in 1997
sane man wrote: > > Hi, > I was under the impression that when we put a > sql statement in a SP. the sql's query plan is > decided when we create the procedure. This seems > not to be the case. Can some explain to me when > in SP does the query plan for the Query is > decided in SP. Hopefully not when he query is > executed. Query plans for Stored Procedures are developed at compile, ie create, time or when you UPDATE STATISTICS FOR PROCEDURE... The caveat is that if the table structure has changed it will invalidate the query plan and the first user to run the SP will reoptimize it (as if UPDATE STAT.... had been run). There are some esoteric circumstances that seem to defy this logic and cause an error rather than an automatic recompile (I think deleting a referenced table and recreating it does this for example). In this case you will have to explicitely UPDATE STATISTICS FOR PROCEDURE... Art S. Kagel