I think my original question may have been unclear.
What is actually being done when a SQL statement is being 'compiled'?
Query plan? Parsing of SQL statement? Something else?
Thanks
Taras
> I think my original question may have been unclear.
>
[quoted text clipped - 4 lines]
>
> Taras
The driver sends the SQL string to the DBMS. The DBMS parses it, and
compiles/creates a plan for executing what the SQL wants. This
includes
verifying the names of tables and columns etc, choosing what index to
use etc. This plan may include place-holders for data values passed in
as parameters. This is very similar to a session-scoped stored
procedure.
Then, when the driver sends the needed parameter values, and says
'go',
the DBMS executes the plan. A plain statement does the same, all in
one call,
except the DBMS doesn't retain the plan, so even an immediate repeat
of
the exact same query requires the DBMS to re-parse, re-check, and re-
plan,
and re-execute.
Joe Weinstein at BEA Systems
Taras_96 - 23 Apr 2008 15:58 GMT
On Apr 23, 10:33 pm, "joeNOS...@BEA.com" <joe.weinst...@gmail.com>
wrote:
> > I think my original question may have been unclear.
>
[quoted text clipped - 22 lines]
> and re-execute.
> Joe Weinstein at BEA Systems
Excellent response - thanks Joe!
Arne Vajhøj - 24 Apr 2008 02:58 GMT
> The driver sends the SQL string to the DBMS. The DBMS parses it, and
> compiles/creates a plan for executing what the SQL wants. This
[quoted text clipped - 6 lines]
> 'go',
> the DBMS executes the plan.
That is what a good database and a good JDBC driver does.
And what the name PreparedStatement clearly indicates is the
intention.
But there are AFAIK no guarantee that this is actually happening.
So one should check what the specific database does before
claiming that prepared statement improves performance.
No need to check before choosing prepared statement, because
there are so many other advantages of using it.
Some years ago I tested Oracle and MySQL. Oracle obviously did
the right thing and prepared statement improved performance
significantly. On MySQL prepared statement reduced performance
(MySQL first introduced PREPARE in version 5.0).
Arne