Re: [h2] Question about JDBC prepared statements in H2

2022-11-07 Thread Noel Grandin




On 11/7/2022 4:59 PM, Silvio wrote:


I was hoping for perhaps some speedup if the query planner could make a more optimal query plan based on known values in 
the SQL string as opposed to a more generic query plan that would have to take all possible values for one or more 
parameters into account. If that would never be the case in H2 then there is little to no advantage for us in changing 
anything.




There are very few opportunities to do this (that I am aware of), so I don't 
expect it to make any real difference.

But if you do find any potential optimisations that we are missing, please feel 
free to log a feature request :-)

--
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/18f9c69b-ff51-adc4-459f-b2f33b8179fb%40gmail.com.


Re: [h2] Question about JDBC prepared statements in H2

2022-11-07 Thread Silvio
Thanks Noel. String values are exactly what we where planning to keep as 
parameters.

So in many cases one or more parameters will remain (for string values) but 
most will be replaced by literals since in our case by far most column 
types are numeric, timestamp or UUID.

I was hoping for perhaps some speedup if the query planner could make a 
more optimal query plan based on known values in the SQL string as opposed 
to a more generic query plan that would have to take all possible values 
for one or more parameters into account. If that would never be the case in 
H2 then there is little to no advantage for us in changing anything.

On Monday, 7 November 2022 at 13:28:07 UTC+1 Noel Grandin wrote:

> I prefer PreparedStatement purely so I can avoid thinking about escaping 
> string values.
>
> But if that doesn't worry you, then there is no down side to using 
> Statement for execute only once.
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/1bc0addc-df72-42be-bef4-125a817c20d8n%40googlegroups.com.


Re: [h2] Question about JDBC prepared statements in H2

2022-11-07 Thread Noel Grandin

I prefer PreparedStatement purely so I can avoid thinking about escaping string 
values.

But if that doesn't worry you, then there is no down side to using Statement 
for execute only once.

--
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/21a13bbb-15d6-1b14-d089-9abcc0301472%40gmail.com.


[h2] Question about JDBC prepared statements in H2

2022-11-07 Thread Silvio
Apart from SQL-injection considerations Is there any advantage or 
disadvantage in using PreparedStatement parameters versus literal values 
when the statement will only be executed once?

Our generic database handling code currently uses statement parameters for 
all situations and column types. We are considering changing this to 
literal values in the SQL string for numerical types, timestamp types etc. 
and only use parameters for string values when the statement will be 
executed only once (which we know upfront).

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/f428ad36-1bc4-4e8b-8f2b-c73ac77af742n%40googlegroups.com.