Subject | Non-correlated subquery is really slow |
---|---|
Author | kokok_kokok |
Post date | 2011-02-18T09:33:39Z |
How can I rewrite a non-correlated subquery to improve the performance?
For example:
SELECT
(SELECT COUNT(*) FROM Orders) AS TotalOrders,
Name
FROM Customers
Firebird reevaluates the subquery for each customer record. Note that the subquery is not correlated, so there is not point to read all records of subquery again. It could be executed only once for all Customer records.
How can I improve the performance?
Thank you
For example:
SELECT
(SELECT COUNT(*) FROM Orders) AS TotalOrders,
Name
FROM Customers
Firebird reevaluates the subquery for each customer record. Note that the subquery is not correlated, so there is not point to read all records of subquery again. It could be executed only once for all Customer records.
How can I improve the performance?
Thank you