Products | Versions |
---|---|
TIBCO Data Virtualization | All supported versions |
In TIBCO Data Virtualization, executing the below packaged query against a database runs without any noticeable lag:
SELECT o1.owner, oa1.owner_acc, COALESCE(SUM(CASE WHEN nd1.credit=1 THEN nd1.nom_value ELSE nd1.nom_value*-1 END), 0.00) AS expenditure_prev_year FROM SQL92.owner_SQL92 AS o1 INNER JOIN SQL92.owner_acc_SQL92 AS oa1 ON oa1.owner=o1.owner AND oa1.owner_acc BETWEEN 2000 and 2999 INNER JOIN SQL92.nomdet_SQL92 AS nd1 ON nd1.owner=o1.owner AND nd1.owner_acc=oa1.owner_acc AND nd1.acc_year={1}-1 INNER JOIN SQL92.expense_type_SQL92 AS et1 ON et1.expense_type=nd1.nom_code AND et1.expense_cat BETWEEN 16 and 28 WHERE o1.owner='{0}' GROUP BY o1.owner, oa1.owner_acc
After placing the query in a VIEW which contains INNER JOINs (as given below) results in a lag during the query execution.
SELECT {DECLARE inClientNo VARCHAR(10)} owner, {DECLARE inAccYear INTEGER} AccYear, oa1.owner_acc, COALESCE(SUM(CASE WHEN nd1.credit=1 THEN nd1.nom_value ELSE nd1.nom_value*-1 END), 0.00) AS expenditure_prev_year FROM /shared/Physical/Formatting/Propman/Owner_SQL92 AS o1 INNER JOIN /shared/Physical/Formatting/Propman/Owner_Acc_SQL92 AS oa1 ON oa1.owner=o1.owner AND oa1.owner_acc BETWEEN 2000 and 2999 INNER JOIN /shared/Physical/Formatting/Propman/Nomdet_SQL92 AS nd1 ON nd1.owner=o1.owner AND nd1.owner_acc=oa1.owner_acc AND nd1.acc_year=inAccYear-1 INNER JOIN /shared/Physical/Formatting/Propman/Expense_Type_SQL92 AS et1 ON et1.expense_type=nd1.nom_code AND et1.expense_cat BETWEEN 16 and 28 WHERE o1.owner=inClientNo GROUP BY o1.owner, oa1.owner_acc
Note that the above queries are very similar. However, the resulting query sent to the data-source is automatically rewritten by TDV with subqueries after the INNER JOINs. This will add an overhead to the overall query execution time.
SELECT oa1.Owner_Acc AS owner_acc, COALESCE(SUM(CASE WHEN nd1.Credit = 1 THEN nd1.Nom_Value ELSE (nd1.Nom_Value * (- (1))) END), 0.00) AS expenditure_prev_year FROM (((SELECT Owner_SQL92.Owner FROM "SQL92"."Owner_SQL92" Owner_SQL92 WHERE Owner_SQL92.Owner = '0682') o1 INNER JOIN (SELECT Owner_Acc_SQL92.Owner_Acc, Owner_Acc_SQL92.Owner FROM "SQL92"."Owner_Acc_SQL92" Owner_Acc_SQL92 WHERE ('0682' = Owner_Acc_SQL92.Owner )) oa1 ON o1.Owner = oa1.Owner) INNER JOIN (SELECT Nomdet_SQL92.Credit, Nomdet_SQL92.Nom_Value, Nomdet_SQL92.Nom_Code, Nomdet_SQL92.Owner, Nomdet_SQL92.Owner_Acc FROM "SQL92"."Nomdet_SQL92" Nomdet_SQL92 WHERE ('0682' = Nomdet_SQL92.Owner AND Nomdet_SQL92.Acc_Year = (2018 - 1) AND Nomdet_SQL92.Owner_Acc <= 2999 AND Nomdet_SQL92.Owner_Acc >= 2000 )) nd1 ON o1.Owner = nd1.Owner AND oa1.Owner_Acc = nd1.Owner_Acc) INNER JOIN (SELECT Expense_Type_SQL92.Expense_Type FROM "SQL92"."Expense_Type_SQL92" Expense_Type_SQL92 WHERE Expense_Type_SQL92.Expense_Cat <= 28 AND Expense_Type_SQL92.Expense_Cat >= 16) et1 ON nd1.Nom_Code = et1.Expense_Type GROUP BY o1.Owner, oa1.Owner_Acc
Append {OPTION DISABLE_SELECTION_REWRITER} parameter in the query to help prevent the QE from re-writing INNER JOINS with SELECT's which results in treating the query as it is written.
Here is an example query:
SELECT {OPTION DISABLE_SELECTION_REWRITER} oa1.Owner_Acc AS owner_acc, COALESCE(SUM(CASE .... .... GROUP BY o1.Owner, oa1.Owner_Acc