-
Notifications
You must be signed in to change notification settings - Fork 5k
[API Proposal]: DbDataReader - span based column name APIs #113741
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
Comments
/cc @roji |
Tagging subscribers to this area: @roji, @ajcvickers |
@mgravell thanks for the suggestion. In general, we've viewed DbDataReader's name-based APIs as "low-perf" convenience APIs. In other words, a very-high-perf conscious consumer would be expected to just always use ordinals everywhere, and not deal with column names at all; after all, that user is also setting the SQL on the command which produced the reader, so they should be able to know the ordinals for reading out the results. Is there a reason/scenario that a (high-perf) consumer of DbDataReader would have to deal with column names? |
@roji imagine the context of Dapper. Right now, in current versions of Dapper, it doesn't attempt to pre-process the SQL to understand context and check whether it can use pure ordinal fetch - it checks the column names (not least, because the query could involve Now, if we parse the query fully, we can check that - and indeed that is planned for TSQL in AOT mode because we have a build-time TSQL parser already, that we can use. However:
So: having the ability to efficiently query the column names could save a considerable number of allocations. |
…ance, so let's use the ordinal positions of columns instead of their names to improve performance, even though it reduces the readability of the code. (dotnet/runtime#113741 (comment))
Executing Stored Procedures would also benefit from this optimisation as the column orders are not directly controllable and must be looked up before reading the result. |
Background and motivation
Column names are an inherent part of DB reads. Currently,
DbDataReader
exposes multiple APIs for discussing column names, the most obvious being:While it is possible to ignore the column names and rely purely on ordinals, a lot of code - especially ORM code - uses the column names to assert the intent (think
"select * from orders where region=@region"
- what is the column order?)API Proposal
Suggestion:
This would allow implementations to use pooled
char[]
data for the names, only lazily materializing astring
if theGetName
API is used. Callers such as ORMs could update to use span-based testing, completely avoiding thestring
usage.I would happily update Dapper as a prototype.
API Usage
This is an existing Dapper (ORM) usage, taken from AOT generator output:
The complete change here would be to the line:
et voila, zero strings; if the provider supports the usage! obviously this also requires
If in doubt over the
.ToString()
in the base method: I'll loseGetOrdinal
in a heartbeat to getGetNameSpan
!Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: