Batching of statements for SELECT query
Hi, The EF Core release has batch statements for insert update delete query for single roundtrip to DB in order to speed up app performance. Does it also apply for multiple SELECT or entities queries or combined query (e.g. INSERT, UPDATE and SELECT)?
Thank you.
This isn't something we would do, because it requires reading all the data from one result set before reading the next. With separate commands we can stream data from both results sets.
@rowanmiller, note that reading one result set after the other makes a lot of sense in many scenarios - sometimes you just want the results of 2 unrelated queries in one roundtrip. At the very least this is supported at the ADO.NET level. Also, in non-MARS providers (such as Npgsql) there's no other alternative (i.e. you can't read both result sets at the same time).
I'm not saying EFCore should support this - I don't think it makes much sense for an O/RM and I haven't the slightest idea as to what the API would look like - just that the capability itself does make sense to me.
As @roji mentions we already serialize and buffer query execution when a single source query translates into multiple SELECT statements (e.g. with collection includes) and when MARS isn't available.
@anpete and I have talked about the possibility of generalizing that to other cases, including:
- buffering when MARS would otherwise be needed for executing multiple queries
- in a similar fashion to the NHibernate Futures feature (which supposedly has performance benefits I would like us to understand better).
I am not sure what the priority should be or if there is any fundamental reason for it not to work but on the surface it seems executing multiple SELECT statements in a batch could be possible (and potentially be useful) for some of the cases above.