Suppose I have two similar queries, with complex joins; query1query 1 returns rows and columns, and query2 returns just the Count of rows as per query 1;:
var mySearchSql = @"SELECTSELECT col1, col2, col3, ...etc
FROM MyBigTable
LEFT JOIN AnotherTable1 On ... etc
LEFT JOIN AnotherTable2 On ... etc
WHERE someCol1= val1
AND someCol2= val2
AND etc...
";
var myCountSql = @"SELECT
and query 2 returns just the count of rows as per query 1:
SELECT count(MyBigTable.PKcol)
FROM MyBigTable
LEFT JOIN AnotherTable1 On ... etc
LEFT JOIN AnotherTable2 On ... etc
WHERE someCol1= val1
AND someCol2= val2
AND etc...
";
Self-evident logic tells me the SqlSQL engine (of most databases, say SqlServerSQL Server, MySqlMySQL, IBM DB2, whatevs...) will RETURNreturn from the count query FASTERfaster than the resultset query; AT LEAST WHEN WE ARE TALKING BIG RESULT-SETSresult set query – at least when we are talking big result sets.
Obviously Obviously transferring lots of rows and columns across a network... will take longer. than just a single scalar value of count !
My questions are (a) does the DB-Engine have to do similar amount of work / effort for both queries, and (b) therefore, the bottleneck (or delay in receiving the results) is simply due to transferring bigger data across a network ?:
- Does the DB Engine have to do similar amount of work / effort for both queries?
- If so, is the bottleneck (or delay in receiving the results) simply due to transferring bigger data across a network?