Replies: 2 comments 3 replies
-
First of all thanks for investing this in #4049 Not caching prepared statements for sql_query and sql DSL notes was a conscious decision. There is currently no way for the user to to control the statement cache so we fear that it might grow unreasonably large by allowing it to cache all queries. That is documented here: https://docs.diesel.rs/2.2.x/diesel/connection/statement_cache/index.html#a-primer-on-prepared-statement-caching-in-diesel That written: I can understand that this can lead to unexpected performance results and that someone might want a better way to fix this. I do not have a finished design ready for this but I would like to go for something that has a bit stronger guarantees about that the query string is actually statically known at compile time. There is currently a rather straightforward method to do that in your code:
That is a bit more code than just calling |
Beta Was this translation helpful? Give feedback.
-
Also I have some benchmark results. Axum http2 endpoint with select query (1500 chars) to postgres db with 50 connections pool: Dsl with I have 3 conclusions from these results:
|
Beta Was this translation helpful? Give feedback.
-
Currently diesel doesn't support prepared statements cache for any sql which contains at least one raw sql fragment.
This really negatively affects performance.
Often I want to write a custom sql fragment or a whole query and I know, that it will be static and can be safely added to a prepared statement cache.
Actually I even think that this should be the default behaviour because this is much more common case.
In my practice 99% of statements can be safely prepared.
I see two possible implementations:
prepared_sql
andprepared_sql_query
functions.Do you like the idea? Can I implement this?
Beta Was this translation helpful? Give feedback.
All reactions