One of the ways to speed up an SQL query is putting the smallest table first in the FROM clause and so on. How is Crystal Reports dealing with this?
For the examples I used the NorthWind database.
SELECT `Customers`.`CompanyName`, `Order_Details`.`Quantity`
For the examples I used the NorthWind database.
- I picked the tables Order_Details, Orders and Customers.
- I linked the table manually by dragging a line from Order_Details->OrderID to Orders->OrderID and from Orders->CustomerID to Customers->CustomerID.
- When we would now drag the fields Customers->CompanyName and Order_Details->Quantity to our report our SQL Query would look like this:
FROM (`Order Details` `Order_Details` INNER JOIN `Orders` `Orders` ON `Order_Details`.`OrderID`=`Orders`.`OrderID`) INNER JOIN `Customers` `Customers` ON `Orders`.`CustomerID`=`Customers`.`CustomerID`
Now back to the Links window of the Database Expert.
- Remove the links.
- Link the table again manually by dragging a line from Order->OrderID to Orders_Details->OrderID and from Customers->CustomerID to Order->CustomerID.
Now are SQL Query will look like this:
SELECT `Customers`.`CompanyName`, `Order_Details`.`Quantity`
FROM (`Customers` `Customers` INNER JOIN `Orders` `Orders` ON `Customers`.`CustomerID`=`Orders`.`CustomerID`) INNER JOIN `Order Details` `Order_Details` ON `Orders`.`OrderID`=`Order_Details`.`OrderID`
Back to our first example. We could also have changed the linking order by pressing the Order links button in the Links window of the Database Expert:
- Just change the order.
Then our SQL Query would have looked like this:
SELECT `Customers`.`CompanyName`, `Order_Details`.`Quantity`
FROM `Order Details` `Order_Details` INNER JOIN (`Orders` `Orders` INNER JOIN `Customers` `Customers` ON `Orders`.`CustomerID`=`Customers`.`CustomerID`) ON `Order_Details`.`OrderID`=`Orders`.`OrderID`
So, actually we can change the order of the tables in the FROM clause. What does it mean for the performance of our report?. The Northwind database is not a very large Access database. I was not able to notice a significant difference between the three scenario's.
So I tried it with the AdventureWorks SQL Server database.
The Largest table first: SalesOrderDetail->SalesOrderHeader->Customer. Performance information:
The smallest table first: Customer->SalesOrderHeader->SalesOrderDetail. Performance information:
Does not look very significant to me. The problem is also, that the performance can keep changing evry time you click refresh.
So I am not sure what to conclude. It is possible to do something about the order in Crystal Reports. It looks hard to say how the performance is influenced by it.
Reacties