dotnet / dotnet/efcore

Automatic Query Short-Ciruiting

Open
#29,954 4 comments 3 reactions 0 assignees View on GitHub
area-perf area-query customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

# What problem are you trying to solve?
Sometimes a query can be guaranteed to always return no results. In situations like that, the query should short-circuit and never get sent to the database server.

For Example:
```csharp

var items = (
from x in DbContext.Records
where IdsToFetch.Contains(x.Id)
select x
).ToList();
```

If ```IdsToFetch``` is empty, the query is guaranteed to return no results so it doesnt need to be sent to SQL.

# Describe the solution you'd like
If, client side, a query can be guaranteed to return no results, it should not be sent to the server.

The current alternative that I'm implementing is to manually decorate my code with ```if```s.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.