Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Reporting - Is it better to copy data first into a temporary table
    text
    copied!<p>We have tables in the following format:</p> <pre><code>Order(OrderID,CustomerID,OrderDate,CreatedByUserID,LastModifiedByUserID) OrderItem(OrderID,ProductID,ProviderID,ItemStatus,CompletedByUserID) Companies(CompanyID, CompanyName, CompanyParentID, CompanyRegionID) </code></pre> <p>The full data table required for generating reports for Orders requires almost 12 joins and about 250 fields. Below is a short example</p> <pre><code>SELECT o.OrderID, o.CustomerID ... FROM Orders AS o INNER JOIN OrderItems AS items ON o.OrderID = items.OrderID INNER JOIN Products AS p ON items.ProductID = p.ProductID INNER JOIN Companies AS cust ON o.CustomerID = cust.ComapnyID LEFT OUTER JOIN Companies AS prov ON items.ProviderID = prov.ComapnyID INNER JOIN Users AS u1 ON items.CreatedByUserID = u1.UserID INNER JOIN Users AS u2 ON items.LastModifiedByUserID = u2.UserID LEFT OUTER JOIN Users AS ui1 ON items.CompletedByUserID = ui1.UserID LEFT OUTER JOIN Users AS ui2 ON items.VerifiedByUserID = ui2.UserID LEFT OUTER JOIN Companies AS parent ON cust.CompanyParentID = parent.ComapnyID LEFT OUTER JOIN Companies AS region ON cust.CompanyRegionID = region.ComapnyID </code></pre> <p><strong>My question is:</strong> SInce this is a reporting application, should we run this SQL once (e.g. every hour) and copy the data to a temp table from which the reports are run, or should we always run all these joins whenever a user requests to see the report?</p> <p><strong>Note:</strong></p> <ol> <li>The reports can be up to an hour out of date. Since they are typically run on a weekly/monthly basis.</li> <li>The data is multi-tenant. i.e. it is filtered depending on who is running reports (customers, parent companies, regional offices, product providers etc.)</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload