oracle - PreparedStatement is faster in Java, How db do it? -


I know that the space prepared in the speech in Java is fast.

I do not know how how Oracle DB server does this.

The prepared station gets pre-compiled in the database server -> less work it reduces the load on the database.

  string sql = "select * from users where u.id =?"; Prepared place PSTMT = connenction.prepareStatement (SQL); Pstmt.setLong (1, user id); Pstmt.executeQuery ();  

The query is cached in the database server, and only compile once?
If so, how does the database server know that this query was previously executed?
How long is it cached?

The query has been cached in the database, and only compiled once?

More accurate, the query scheme is cached on the server when you run a query, your RDBMS first creates a plan, then executes it Does. To prepare a plan it is necessary to parse the query, then analyze and optimize it, consider the collected data on available indexes and interactive tables.

If so, how does the database server know that this query was executed first?

By comparing the string of queries for other queries available in the cache. Since you use parametric queries, other query text will be the same. Caching is another main reason * to use the query parameter: If you want to create a statement like this

  // Incorrect! Do not do this! String SQL = "Select * User U to U.ID =" + User ID; Prepared place PSTMT = connenction.prepareStatement (SQL);  

All performance corrections will end, because providing a separate id should have a different query, which requires a new plan.

* The biggest reason for the parametering query is, of course, protection from injection attacks.


Comments