in reply to MySQL Parameterized Query with Functions
When you “prepare” an SQL statement (which the server will always do, whether you ask for it or not), the server “sort-of compiles it.” This step creates what’s called an “execution plan,” which is a breakdown of the actual steps that the guts of the database server will actually carry out in order to get the results that you wanted. (The plan considers not only the SQL statement, but various statistics about the current state of the tables themselves.)
Well, the server can happily execute the same prepared query many times, substituting parameter-values into it each time (these are merely inputs ...), but it can’t handle changes to the statement itself. You have to present a new SQL statement, which will be prepared according to its content. &nbp; A statement that needs to call a different server-side function is, by definition, a new statement.
Now, if you are doing a lot of this sort of thing, you might wish to minimize the number of prepares (if that makes sense in this case) by preparing each variation of the SQL statement in turn, and running all the data that needs to go through that particular variation, before moving on to the next variation and its set of input data.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: MySQL Parameterized Query with Functions
by hoyt (Acolyte) on Sep 15, 2014 at 23:10 UTC |