question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't select unnecessary columns

See original GitHub issue
bool b = false;
var q = from t in db.Tbl1
        select new
        {
            t.C1,
            Other = b ? new { t.C2, t.C3, t.C4 } : null
        };

The SQL executed is:

SELECT
        [t].[C1],
        [t].[C2],
        [t].[C3],
        [t].[C4]
FROM
        [Tbl1] [t]

The property Other in the results is null. But it loads the columns C2, C3 and C4 from the DB. Desired behavior: don’t load columns which aren’t needed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sdanylivcommented, Aug 30, 2021

This optimisation is not supported. Currently we do not optimise expression tree based on parameters. Will take a look, probably it makes sense to do that for conditional expression.

0reactions
sdanylivcommented, Sep 14, 2021

I see, forgot to check this cache variant. Here we cache plan by reference. Thanks for mentioned that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asking for unnecessary columns causes ...
It is not about the star, stupid: selecting unnecessary columns is bad.
Read more >
sql - Exclude a column using SELECT * [except columnA] ...
If you look at Red-Gate's SQL Prompt, you can type "SELECT * FROM MyTable", and then move the cursor back after the "*",...
Read more >
Why can't unused columns and tables be ignored in a ...
Yes, we can obviously see that in the end, the final SELECT list only consists of the CatalogNodeId column, and therefore the other...
Read more >
Excel. How to hide all unused cells in all columns ... - YouTube
This video will demonstrate the procedure to hide all unused cells in all columns and rows. Now updated to cover all Excel versions...
Read more >
Performance Improvement - Where to reduce number o...
You can delete unnecessary columns in Edit Queries: Ctrl + left mouse button to select multiple columns, then, Right-click and select ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found