Skip to content
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

Fix to #29513 - Json: improve projection deduplication for scenarios containing collection indexers #29808

Merged
merged 1 commit into from
Dec 23, 2022

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Dec 9, 2022

Reworking shaper to properly track key values for JSON entities that are accessed via array element. Every array access needs to be recorded and incorporated into the key later. Constants can be stored directly by value, non-constants are added to projection, and we keep track of the projection index instead.

  • added JsonProjectionInfo in place of a value tuple to store shaping info needed for JSON, so that it's more readable,
  • reworked JsonShapingPreProcess to generate and cache key values as well as JsonElement.
  • moved dangling (i.e. not coming from include on the owner entity) JSON entity processing after Include processing, so that we guarantee to have all the entities in state manager by the time we get to processing the dangling JSON stuff.

Fixes #29513

@maumar maumar requested a review from roji December 9, 2022 01:34
{
if (!_jsonCollectionNonConstantElementAccessMap.TryGetValue(index, out var collectionElementAccessParameter))
{
collectionElementAccessParameter = Expression.Parameter(typeof(int?));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could store these values as int, rather than int? - this way we only need to perform convert to int once (i.e. here). If the value we get for the array is null, things break anyway later.

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and I think I'm even half-understanding it :)

See especially the comments about how to represent stuff inside JsonProjectionInfo, plus various nits.

@maumar maumar force-pushed the fix29513 branch 3 times, most recently from a4c718e to 6ffd3e1 Compare December 14, 2022 09:24
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </remarks>
public (int? ConstantArrayIndex, int? NonConstantArrayIndex)[] ArrayElementAccessInfo { get; }
public List<(IProperty? KeyProperty, int? ConstantKeyValue, int? KeyProjectionIndex)> KeyAccessInfo { get; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe different order? (Constant, KeyProperty, KeyProjectionIndex) or (KeyProperty, KeyProjectionIndex, Constant) ?

@maumar
Copy link
Contributor Author

maumar commented Dec 14, 2022

@roji new version up - JsonProjectionInfo refactoring in separate commit, all other feedback addressed in the initial one

@maumar
Copy link
Contributor Author

maumar commented Dec 21, 2022

ping @roji

…containing collection indexers

Reworking shaper to properly track key values for JSON entities that are accessed via array element. Every array access needs to be recorded and incorporated into the key later. Constants can be stored directly by value, non-constants are added to projection, and we keep track of the projection index instead.

- added JsonProjectionInfo in place of a value tuple to store shaping info needed for JSON, so that it's more readable,
- reworked JsonShapingPreProcess to generate and cache key values as well as JsonElement.
- moved dangling (i.e. not coming from include on the owner entity) JSON entity processing after Include processing, so that we guarantee to have all the entities in state manager by the time we get to processing the dangling JSON stuff.

Fixes #29513
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Json: improve projection deduplication for scenarios containing collection indexers
2 participants