Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 11212

Re: Hana JDBC PreparedStatements are SLOW

$
0
0

Hi Kris,

 

in fact there are several things wrong with your example:

 

You have the prepareStatement() call right inside of your loop.

That's a bug.

It's your bug and a serious one.

Prepare Statement is meant to be used as prepare once - execute often.

Run it only once, before you enter the loop and you'll get the speed up of a prepared statement.

 

The other thing is that you never change the actual value ('test') of your where condition.

That's where you would gain from prepared statements.

In fact, prepared statements don't make processing faster because they speed up the prepare phase.

They do it by eliminating the need to perform preparing at all for every but the very first call.

 

The much improved average prepare time you measured in your "regular" statement is due to the SQL plan cache. HANA recognizes that the *exact* same statement should be executed and provides you with the already prepared and optimized statement from the SQL plan cache.

 

Replace the test with different values for every execution (just concatenate the loop counter to the value) and re-run your code and you'll see that every new statement gets the costs for the preparation.

 

The SQL plan cache however is not used when you specifically ask for a re-preparing in every loop in your first example - that's why you have such a high share of time for dealing with the prepared statement.

 

- Lars


Viewing all articles
Browse latest Browse all 11212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>