-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dapper doesn't use prepared statements #474
Comments
I could kinda get behind that, but the big problem is concurrency. It
|
I guess some simple contended lock or MRE will still be cheaper than recreating a statement every time? E.g. ConcurrentDictionarysql:string,PreparedCommand:IDbCommand with MRE inside... I just cannot sleep well when there are 20% of free performance not gained yet :) |
It isn't quite as simple as an MRE, though; we don't usually want to queue
Lots to consider, is my point. I fully take on board that we should look into this. Simply; there are some On 29 February 2016 at 08:04, Victor Baybekov [email protected]
Regards, Marc |
I was definitely thinking about a very explicit opt-in, so that any On Mon, Feb 29, 2016 at 12:46 PM, Marc Gravell [email protected]
|
just to note some implementation details - any lease-based mechanism here would most-likely be implemented using interlocked mechanisms, since we don't want to queue impact on existing codebase is non-trivial; would require quite some rework (rewrite?) to how the parameter preparation code currently works, Fortunately, |
global? or per command? and if per-command: how specified? (that's an open question; you don't need to have the answer, but any thoughts are welcome) |
In the linked test, I would very much like just an additional parameter:
It should be documented that such a command lives for the lifetime of connection, because it makes sense to reuse only those statements that are called repeatedly. Of there could be some explicit logic for disposing it. Another option is just to add the
The second option looks simpler and better to me. |
adding yet another optional parameter is slightly problematic, due to backwards compatibility and overload requirements; adding an additional parameter to an existing method is not compatible, so we'd need to duplicate all the existing overloads. Frankly, what we perhaps should do at some point is a "major bump" (2.0 release) that kills a lot of overloads that have been added for binary compatibility reasons. I'd be unlikely to support adding a parameter without a major bump, but it could perhaps be done via the Re "Dapper just does mapping work" - note that this can already be done via |
Actually, this could be specified in the existing CommandFlags enum with no On 29 Feb 2016 10:13, "Victor Baybekov" [email protected] wrote:
|
Note that PostgreSQL is one example where prepared statements can have a pretty dramatic effect on performance (don't have figures available but can benchmark if needed). Also, the upcoming version 3.2 of the Npgsql provider will have automatic preparation of statements inside the driver, based on an LRU cache. The advantage of implementing this in the driver unlocks the performance benefits for all layers above it which don't use prepare (Dapper, Entity Framework..). This would also be an opt-in feature. |
Planning the |
So, is support for prepared statements in the process of being added? It looks like I can just enable automatic prepared statements use for my PostgreSQL projects... It would be nice to have it for MySQL and SQL Server though. Not sure if either of those have something similar to what's provided in the Npgsql provider. |
@jemiller0 if you're interested in prepared statements with Dapper - take a look at my branch which adds a global hook. I tried it on a couple of projects and it works |
In most RDBMS that could be replaced by stored procedures, but SQLite doesn't have them. If I need to insert many rows, but cannot do so in a single transaction, I cannot reuse prepared statements. Please see this issue for additional details. In this test using Dapper is now c.25% slower than the manual call.
One idea is to cache queries by sql string, make them prepared, and just populate parameters on every subsequent call. That could be done with some additional overload with an optional parameter
prepared = false
. Are you interested in supporting this?Dapper is awesome for automatic mapping, it will be even more awesome and faster with support of prepared statements!
The text was updated successfully, but these errors were encountered: