Say I have:
- very wide table A where I need all columns
- that I need to join with a small table B that has a LOT of rows.
Of course when I join these two tables I get returned all the content of A for every row of B.
Is this internally being optimized away or does all this data being sent over the wire?
Because if it's the last thing it takes me very little effort to the join manually in memory in this very specific case.
Example:
SELECT ColumnA1, ColumnA2, ColumnA3, ColumnB1
FROM TableA
JOIN TableB ON TableB.Id = TableA.TableBId
Resulting in data:
ColumnA1 ColumnA2 ColumnA3 ColumnB1
------------------------------------------------
LargeTextA LargeTextB LargeTextC 1
LargeTextA LargeTextB LargeTextC 2
LargeTextA LargeTextB LargeTextC 3
LargeTextA LargeTextB LargeTextC [1.000.000 times more]
Will LargeTextA, LargeTextB and LargeTextC being transmitted 1.000.000 times over the line or will it only be sent once because it will know it will just be repeated data?
TableB (id)is the primary key of tableB, I don't see how the data from A will be repeated. The result should be all the rows from A, or less. The data from ColumnB1 may be repeated yes, as a row in B can be associated with many rows from A. – ypercubeᵀᴹ Nov 01 '23 at 17:32db.TableAs.Include(a => a.TableBs).ById(1)– Dirk Boer Nov 01 '23 at 18:23ON TableB.Id = TableA.TableBId. If the join was the other way around yes, it would make sense (ON TableB.TableAId = TableA.Id) – ypercubeᵀᴹ Nov 03 '23 at 17:10