Crystal Report Suddenly Slowed to a crawl

I have a Crystal Report that is linking CI_Item, to IM_ItemWarehouse and also linking to IM_TransactionHistory all with Inner Joins. The criteria are the following:  

{IM_ItemWarehouse.WarehouseCode} = "003" and
{IM_ItemTransactionHistory.TransactionDate} in CurrentDate-92 to CurrentDate-1 and
{IM_ItemTransactionHistory.TransactionCode} in ["WI", "BI", "SO"] and
{CI_Item.DefaultWarehouseCode} = "003" and
{CI_Item.BuyerCode} = {?Buyer/Planner}

When I run this report, it runs in about 1-2 minutes, but if I change the select criteria to select items where the Buyer Code OR the Planner Code are equal to the user supplied parameter, the report doesn't work right or slows to a crawl.

Here is what I tried:

{IM_ItemWarehouse.WarehouseCode} = "003" and
{IM_ItemTransactionHistory.TransactionDate} in CurrentDate-92 to CurrentDate-1 and
{IM_ItemTransactionHistory.TransactionCode} in ["WI", "BI", "SO"] and
{CI_Item.DefaultWarehouseCode} = "003" and
{CI_Item.BuyerCode} = {?Buyer/Planner} or
{IM_ItemWarehouse.WarehouseCode} = "003" and
{IM_ItemTransactionHistory.TransactionDate} in CurrentDate-92 to CurrentDate-1 and
{IM_ItemTransactionHistory.TransactionCode} in ["WI", "BI", "SO"] and
{CI_Item.DefaultWarehouseCode} = "003" and
{CI_Item.PlannerCode} = {?Buyer/Planner}

This criteria just doesn't work.  It shows the items where the Buyer Code is equal to the parameter field but not the Planner Code.  If I put the Planner Code before the OR statement, then the items where the Planner Code appear but not the Buyer Code.

I created a formula field that looks at the buyer code and planner code and combines them:  If ProcurementType = :"B" then BuyerCode Else PlannerCode and then put that criteria in the report and ran it and it does work, but it was taking more than 90 minutes to run.  Why is this the case?

Thank you,

  • 0

    Try this as the last line in your first criteria (including the brackets):

    ({CI_Item.BuyerCode} = {?Buyer/Planner} or {CI_Item.PlannerCode} = {?Buyer/Planner})

  • 0 in reply to Kevin M

    Kevin has you on the right track.   The problem in your original is the order of evaluation of the ands and or.  If I recall correctly ANDs and ORS are at the same evaluation level so they get evaluated left to right.  The parenthesis added help to get the evaluation order correct.

    Correction:  Looks like ands are evaluated before ors.   Seems like your original should work but adding parenthesis can't hurt.  I suspect Kevin's variation might help in speeding it up (just have to try it).

  • 0 in reply to Kevin M

    I am running this right now, but it seems to be taking far longer than what I would expect.  Any reason why it dramatically increases the run time for the report?

  • 0 in reply to Tyler Christensen

    What is your order of linking of the tables?   That can make a big difference.

    If you haven't done it already.  Link in this order.

    IM_TransactionHistory->CI_Item

                                       ->IM_ItemWarehouse

    Biggest file should generally be on the left side of the link for best performance.

  • 0 in reply to TomTarget

    Tom,

    I did change the linking and the report is executing quickly, but even with the parentheses around the OR statement, I am still not picking up the items with planner code equal to the parameter.  I am only getting the items where the buyer code is equal to the parameter.  Here is what I tried:

    {IM_ItemWarehouse.WarehouseCode} = "003" and

    {IM_ItemTransactionHistory.TransactionDate} in CurrentDate-92 to CurrentDate-1 and

    {IM_ItemTransactionHistory.TransactionCode} in ["WI", "BI", "SO"] and

    {CI_Item.DefaultWarehouseCode} = "003" and

    ({CI_Item.BuyerCode} in {?Buyer/Planner} or {CI_Item.PlannerCode} in {?Buyer/Planner})

    Any other ideas?

    Tyler

  • 0 in reply to Tyler Christensen

    Are you positive that you have matching values in CI_Item.PlannerCode?   Don't know how many time I got caught by a selection criteria where the data didn't have what I thought was there.  

    Might try running it once with only the reference to the planner code.

  • 0 in reply to TomTarget

    Tom,

    I am positive.  If I run report only referencing Planner Code I pick up those items.  If I run it with reference to Buyer Code I get those items.  If I put in the OR statement, I only get the items for whichever comes first in the OR statement.  I am at a loss on this one.  I can show you the SQL statement if that helps.

    SELECT "CI_Item"."ItemCode", "CI_Item"."ItemCodeDesc", "IM_ItemTransactionHistory"."TransactionDate", "IM_ItemTransactionHistory"."TransactionCode", "IM_ItemTransactionHistory"."TransactionQty", "CI_Item"."BuyerCode", "CI_Item"."StandardUnitOfMeasure", "IM_ItemWarehouse"."QuantityOnHand", "IM_ItemWarehouse"."QuantityOnPurchaseOrder", "IM_ItemWarehouse"."QuantityOnWorkOrder", "IM_ItemWarehouse"."QuantityOnSalesOrder", "IM_ItemWarehouse"."QuantityOnBackOrder", "IM_ItemWarehouse"."QuantityRequiredForWO", "IM_ItemWarehouse"."ReorderPointQty", "IM_ItemWarehouse"."WarehouseCode", "CI_Item"."DefaultWarehouseCode", "CI_Item"."PlannerCode", "CI_Item"."ProcurementType"

    FROM   "IM_ItemTransactionHistory" "IM_ItemTransactionHistory", "CI_Item" "CI_Item", "IM_ItemWarehouse" "IM_ItemWarehouse"

    WHERE  ("IM_ItemTransactionHistory"."ItemCode"="CI_Item"."ItemCode") AND ("CI_Item"."ItemCode"="IM_ItemWarehouse"."ItemCode") AND ("CI_Item"."BuyerCode"='SE' OR "CI_Item"."PlannerCode"='SE') AND "IM_ItemWarehouse"."WarehouseCode"='003' AND ("IM_ItemTransactionHistory"."TransactionDate">={d '2015-01-22'} AND "IM_ItemTransactionHistory"."TransactionDate"<={d '2015-04-23'}) AND ("IM_ItemTransactionHistory"."TransactionCode"='BI' OR "IM_ItemTransactionHistory"."TransactionCode"='SO' OR "IM_ItemTransactionHistory"."TransactionCode"='WI') AND "CI_Item"."DefaultWarehouseCode"='003'

    Thanks!

  • 0 in reply to Tyler Christensen

    Looks good to me?

    You might try creating a formula that returns true or false based on the buyer and planner codes,  then use the result of the formula as a selection criteria instead.

  • 0 in reply to TomTarget

    Tom,

    I had tried putting the formula in, but then it slowed down the report dramatically.  I will try it again with the new linking and let you know.

    Tyler

  • 0 in reply to Tyler Christensen

    Tom,

    That did it!  By changing the linking as you suggested and then inserting a formula that looked at Planner Code and Buyer code, I got it to work.  Many thanks!

    Tyler