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

Query: Optimize usage of GetViewOrTableMappings #23572

Closed
smitpatel opened this issue Dec 3, 2020 · 1 comment · Fixed by #28019
Closed

Query: Optimize usage of GetViewOrTableMappings #23572

smitpatel opened this issue Dec 3, 2020 · 1 comment · Fixed by #28019
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@smitpatel
Copy link
Contributor

  • RelationalEntityShaper - where we figure out if this entity is optional dependent., We need table from entity type
  • WeakentityexpandingEV - to find table for weak entity being expanded so we know if it is table sharing or different.
  • SqlExpressionFactory - to find table to see if it is optional dependent so we can add additional conditions in select expression
  • SelectExpression - Creating basic select for entity type when not mapped to a function.
  • RelationalSqlTranslatingEV - Rewriting entity == null, we get table to see if it is optional dependent so that we can have larger condition rather than condition on PK.

We also have TableExpression.ITableBase available so some of above can be optimized by just looking at it.

Filed from discussions with @AndriySvyryd

@ajcvickers
Copy link
Member

This is needed for TPC: #3170

@ajcvickers ajcvickers modified the milestones: 7.0.0, Backlog Apr 23, 2022
@ajcvickers ajcvickers added punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. and removed propose-punt labels Apr 23, 2022
@smitpatel smitpatel modified the milestones: Backlog, 7.0.0 May 12, 2022
@smitpatel smitpatel added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. labels May 12, 2022
smitpatel added a commit that referenced this issue May 13, 2022
Resolves #23572

Following rules define if given entity type is a potential candidate for optional dependent in table sharing case
- A keyless entity cannot be in table sharing
- Only root type of hierarchy can be dependent
- The dependent can be TPH/TPT (or no hierarchy) but no TPC
- Principal can be any type except non-leaf type in TPC (this is only applied in model validation, no impact on query)

If above conditions indicate it is optional dependent then we need to find the ITableBase it is mapped to find if it is optional dependent
We find ITableBase for IEntityType (which is also root type)
- For new generated SelectExpression, first table's ITableBase is the mapping table (regardless of type of TableExpressionBase, if no mapping then we use default)
- For other scenario the single mapped view/table mapping for the entity type (because of root type, there will only be one mapping) or default mapping in case entity type is not mapped to any view/table

Once we get table and verify it is optional dependent,
We use required non-PK columns which are not shared with principal entity types to add check for existence. This is necessary and sufficient condition for existence
smitpatel added a commit that referenced this issue May 13, 2022
Resolves #23572

Following rules define if given entity type is a potential candidate for optional dependent in table sharing case
- A keyless entity cannot be in table sharing
- Only root type of hierarchy can be dependent
- The dependent can be TPH/TPT (or no hierarchy) but no TPC
- Principal can be any type except non-leaf type in TPC (this is only applied in model validation, no impact on query)

If above conditions indicate it is optional dependent then we need to find the ITableBase it is mapped to find if it is optional dependent
We find ITableBase for IEntityType (which is also root type)
- For new generated SelectExpression, first table's ITableBase is the mapping table (regardless of type of TableExpressionBase, if no mapping then we use default)
- For other scenario the single mapped view/table mapping for the entity type (because of root type, there will only be one mapping) or default mapping in case entity type is not mapped to any view/table

Once we get table and verify it is optional dependent,
We use required non-PK columns which are not shared with principal entity types to add check for existence. This is necessary and sufficient condition for existence
smitpatel added a commit that referenced this issue May 13, 2022
Resolves #23572

Following rules define if given entity type is a potential candidate for optional dependent in table sharing case
- A keyless entity cannot be in table sharing
- Only root type of hierarchy can be dependent
- The dependent can be TPH/TPT (or no hierarchy) but no TPC
- Principal can be any type except non-leaf type in TPC (this is only applied in model validation, no impact on query)

If above conditions indicate it is optional dependent then we need to find the ITableBase it is mapped to find if it is optional dependent
We find ITableBase for IEntityType (which is also root type)
- For new generated SelectExpression, first table's ITableBase is the mapping table (regardless of type of TableExpressionBase, if no mapping then we use default)
- For other scenario the single mapped view/table mapping for the entity type (because of root type, there will only be one mapping) or default mapping in case entity type is not mapped to any view/table

Once we get table and verify it is optional dependent,
We use required non-PK columns which are not shared with principal entity types to add check for existence. This is necessary and sufficient condition for existence
@ghost ghost closed this as completed in #28019 May 13, 2022
ghost pushed a commit that referenced this issue May 13, 2022
Resolves #23572

Following rules define if given entity type is a potential candidate for optional dependent in table sharing case
- A keyless entity cannot be in table sharing
- Only root type of hierarchy can be dependent
- The dependent can be TPH/TPT (or no hierarchy) but no TPC
- Principal can be any type except non-leaf type in TPC (this is only applied in model validation, no impact on query)

If above conditions indicate it is optional dependent then we need to find the ITableBase it is mapped to find if it is optional dependent
We find ITableBase for IEntityType (which is also root type)
- For new generated SelectExpression, first table's ITableBase is the mapping table (regardless of type of TableExpressionBase, if no mapping then we use default)
- For other scenario the single mapped view/table mapping for the entity type (because of root type, there will only be one mapping) or default mapping in case entity type is not mapped to any view/table

Once we get table and verify it is optional dependent,
We use required non-PK columns which are not shared with principal entity types to add check for existence. This is necessary and sufficient condition for existence
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview5 May 25, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview5, 7.0.0 Nov 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants