How Is Query Folding Implemented? RRS feed

  • Question

  • Hello,

    I'm trying to get a better grasp on how query folding works at the technical level—for example, how I might go about explaining it to a programmer who is familiar with .Net's LINQ/IQueryable.

    Behind the scenes, is Power Querys query folding implemented by building up an expression tree which the data provider then converts (as its able) into a native query (e.g. in the case of a SQL Server data source, into a SQL query)? Maybe something like each transform function captures the expression tree of its source argument which somehow includes a reference to the data provider? Then, when the transform expression thats logically closest to the let statements in expression is executed, that transform expression calls the provider, passing it the assembled expression tree?

    Thank you,

    Monday, February 26, 2018 7:14 PM


  • That's right -- LINQ IQueryable is not a bad way to think about this; they're very similar. I sometimes describe M as "dynamically-typed LINQ".
    • Proposed as answer by Colin Banfield Tuesday, February 27, 2018 3:08 AM
    • Marked as answer by Ben Programmer Tuesday, February 27, 2018 6:11 PM
    Tuesday, February 27, 2018 12:09 AM

All replies