Dzoukr / Dapper.FSharp

Lightweight F# extension for StackOverflow Dapper with support for MSSQL, MySQL, PostgreSQL, and SQLite
MIT License
365 stars 35 forks source link

Adding `option(recompile)` to a select query #70

Closed outamaa closed 1 year ago

outamaa commented 1 year ago

Some time ago I had an issue with cached execution plan resulting in order-of-magnitude slowdown of queries. One solution to this was to force SQL Server to recalculate the plan by adding option(recompile) to the query. I managed to add it by extracting the query string using Deconstructor.select, but this meant I had to stop using SelectAsyncOption and instead reimplement the function in terms of the lower level QueryAsync.

I was wondering if 1) there's an easier way to "just add this to the end of the query", and if not, 2) would you be open to adding something along the lines of justAddThisToTheEndOfTheQuery "option(recompile)" as an escape hatch for these kinds of needs. If this is something you'd be willing to merge (with better naming of course), I can try and create a PR.

Dzoukr commented 1 year ago

Hi @outamaa,

I think, in general, it would be possible to add it as a special optional parameter for select query (MSSQL only). Feel free to open PR and we can have a look.

Dzoukr commented 1 year ago

FYI, putting this into v4

Dzoukr commented 1 year ago

Now available in version 4