I know, from whatever I've read, prepared statements are faster since pre-compiled cached version is used for recurring queries. My doubt is : Exactly where time is saved? I see, only the time taken in preparing a query could be saved. Even prepared statements have to do database search and so no time is saved there. Am I wrong?
+2
A:
That's correct. The time saved by using prepared statements is generally in the database engine planning/compiling the query.
Mark Peters
2010-07-15 20:43:39
+2
A:
The part of a "prepared query" that is prepared is the execution plan. The plan tells the database how to execute the query; which indexes to use, in which order. The execution plan also resolves any access rights.
Time is saved by building the execution plan once instead of for every query.
Andomar
2010-07-15 20:43:45