I have just finished a port from a database which was 6.5 to 7.0. Performance is great, apart from one query which is working with a view. Here is the SQL.
SELECT ProductCount.OrderID,
CASE WHEN ProductCount.ProductCount = 1
THEN (
SELECT DISTINCT Product.Name FROM Segment, Product
WHERE Segment.OrderID = ProductCount.Orderid
AND Segment.ProductID = Product.ProductID
AND Segment.Deleted = 0
)
WHEN ProductCount.ProductCount > 1
THEN 'Multi-Product'
ELSE 'No Segments'
END AS Product
FROM ProductCount
ProductCount is a view with 6577 rows. a straight select comes back in less than a second. Product is a reference table with 22 rows, and Segment has 38923 rows.
If I run this query on 6.5 it comes back in about 20 seconds. If I run it on 7.0 it seems to take so long, that I have yet waited for it to finish.
Does anybody have any ideas why this is the case ?
Thanks
SELECT ProductCount.OrderID,
CASE WHEN ProductCount.ProductCount = 1
THEN (
SELECT DISTINCT Product.Name FROM Segment, Product
WHERE Segment.OrderID = ProductCount.Orderid
AND Segment.ProductID = Product.ProductID
AND Segment.Deleted = 0
)
WHEN ProductCount.ProductCount > 1
THEN 'Multi-Product'
ELSE 'No Segments'
END AS Product
FROM ProductCount
ProductCount is a view with 6577 rows. a straight select comes back in less than a second. Product is a reference table with 22 rows, and Segment has 38923 rows.
If I run this query on 6.5 it comes back in about 20 seconds. If I run it on 7.0 it seems to take so long, that I have yet waited for it to finish.
Does anybody have any ideas why this is the case ?
Thanks