Why should you prepare queries? I'm confused.
Posted: Mon 06 Aug 2007 10:56
MyDac help says the following about Prepare.
Call Prepare to allocate, open and parse cursor for the query. Calling Prepare before executing a query improves application performance.
When a query will be executed a number of times, an application should always explicitly prepare the query to avoid multiple and unnecessary prepares and unprepares.
Help also says that if an unprepared query is executed it is automatically prepared. If that's the case, what's the benefit of preparing it in the first place? I can see the point that I could be prepare it while the system was idle and it would save it having to be automatically prepared when it was executed (I can't say I saw any significant gain when I tried it though), but where's the benefit when there is no idle time before execution. For example the help for Options.AutoPrepare states
Set this property to execute automatic preparing on a query execution. Make sense for cases when a query will be executed several times, for example in Master/Detail relationships.
Suppose I've got a master-detail query setup where the detail query text doesn't change but does contain Parameters whose values are taken from the master query. Let's say my application user moves the master record. If I haven't set the detail query's AutoPrepare property to true, the query is automatically prepared and executed. What happens differently if I do have AutoPrepare set to true?
Call Prepare to allocate, open and parse cursor for the query. Calling Prepare before executing a query improves application performance.
When a query will be executed a number of times, an application should always explicitly prepare the query to avoid multiple and unnecessary prepares and unprepares.
Help also says that if an unprepared query is executed it is automatically prepared. If that's the case, what's the benefit of preparing it in the first place? I can see the point that I could be prepare it while the system was idle and it would save it having to be automatically prepared when it was executed (I can't say I saw any significant gain when I tried it though), but where's the benefit when there is no idle time before execution. For example the help for Options.AutoPrepare states
Set this property to execute automatic preparing on a query execution. Make sense for cases when a query will be executed several times, for example in Master/Detail relationships.
Suppose I've got a master-detail query setup where the detail query text doesn't change but does contain Parameters whose values are taken from the master query. Let's say my application user moves the master record. If I haven't set the detail query's AutoPrepare property to true, the query is automatically prepared and executed. What happens differently if I do have AutoPrepare set to true?