-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Combine length/precision/scale/collation... from both operands in type inference #32333
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Note - this should include bubbling up the collation, once it's part of the type mapping (#29620). Note that in my early investigations, all databases fail once there are two explicit collations involved (since it's impossible to know which one to use), but it's a good idea to confirm this. |
I find the sp_describe_first_result_set procedure quite useful for this. Given an arbitrary statement, it shows the exact resulting type that sql server has inferred, including the max length, precision, scale and collation. This might be useful for some integration tests that compare the EF inferred type with the SQL inferred type. |
* Work on type mapping inference for string concatenation Fixes #32325, see also #32333 * Tweaks, update baselines add more tests and cleanup * Update baselines, add more tests, some cleanup. --------- Co-authored-by: Shay Rojansky <[email protected]>
* Work on type mapping inference for string concatenation Fixes #32325, see also #32333 * Tweaks, update baselines add more tests and cleanup * Update baselines, add more tests, some cleanup. --------- Co-authored-by: Shay Rojansky <[email protected]>
…ts (#32510) (#32520) * Infer type mapping suitable for concatenating two results (#32510) * Work on type mapping inference for string concatenation Fixes #32325, see also #32333 * Tweaks, update baselines add more tests and cleanup * Update baselines, add more tests, some cleanup. --------- Co-authored-by: Shay Rojansky <[email protected]> * Qwerk * Fix quirk. --------- Co-authored-by: Shay Rojansky <[email protected]>
When e.g. a concatenation operation happens over two string operands which have a type mapping (e.g. two columns), the left one is arbitrarily picked; this means that the inferred type mapping for
[p].[ThreeCharacterProperty] + ';' + [p].[FiveCharacterProperty]
will bechar(3)
. This is incorrect and can cause bugs such as #32325, where the inferred type mapping is applied to the result of OPENJSON, and therefore incorrectly truncates.We should improve our type mapping inference logic to take facets into account: in this case we'd add the MaxLength facets together for the resulting MaxLength (3 + 1 = 5 = 9). This requires some thinking since different logic applies e.g. for MaxLength and for Precision/Scale, etc. Also, we need to have logic handilng concatenation with constant/parameter - for the former we can just add the constant's length, but for the latter we'd need to switch to e.g.
nvarchar(max)
.Note the relationship with #15586, which is about a compatibility chart between different types; this issue is only about proper handling of facets on the same base type.
The text was updated successfully, but these errors were encountered: