Why is LINQ JOIN so much faster than linking with WHERE?

  1. Your first approach (SQL query in the DB) is quite efficient because the DB knows how to perform a join. But it doesn’t really make sense to compare it with the other approaches, since they work directly in memory (Linq to DataSet)

  2. The query with multiple tables and a Where condition actually performs a cartesian product of all the tables, then filters the rows that satisfy the condition. This means the Where condition is evaluated for each combination of rows (n1 * n2 * n3 * n4)

  3. The Join operator takes the rows from the first tables, then takes only the rows with a matching key from the second table, then only the rows with a matching key from the third table, and so on. This is much more efficient, because it doesn’t need to perform as many operations

Leave a Comment