In questo argomento viene descritto come assegnare in modo esplicito la regola di aggregazione per i totali dei report al fine di migliorare le prestazioni. Queste informazioni sono destinate in modo specifico agli sviluppatori tecnici che scrivono report con Oracle Analytics.
Nella figura riportata di seguito viene mostrato un esempio in cui la definizione del report include l'anno, il mese e l'area del cliente, con una metrica Count Distinct of Customers with Orders
definita come conteggio distinto dei clienti con ordini.
La query logica ha l'aspetto seguente:
SELECT 0 s_0, "A - Sample Sales"."Cust Regions"."C50 Region" s_1, "A - Sample Sales"."Counts"."32 # of Cust with Orders (Cnt Distinct)" s_2, REPORT_AGGREGATE("A - Sample Sales"."Counts"."32 # of Cust with Orders (Cnt Distinct)" BY ) s_3 FROM "A - Sample Sales" WHERE ("Time"."T02 Per Name Month" = '2011 / 11') ORDER BY 2 ASC NULLS LAST FETCH FIRST 500001 ROWS ONLY
La query fisica generata ha l'aspetto seguente:
WITH SAWITH0 AS (select count(distinct T42433.Cust_Key) as c1, T42430.Region as c2 from BISAMPLE.SAMP_CUSTOMERS_D T42428 /* D60 Customers */ , BISAMPLE.SAMP_ADDRESSES_D T42430 /* D62 Customers Addresses */ , BISAMPLE.SAMP_TIME_MTH_D T42405 /* D02 Time Month Grain */ , BISAMPLE.SAMP_REVENUE_F T42433 /* F10 Billed Rev */ where ( T42405.Mth_Key = T42433.Bill_Mth_Key and T42405.Per_Name_Month = '2011 / 11' and T42428.Cust_Key = T42433.Cust_Key and T42428.Address_Key = T42430.Address_Key ) group by T42430.Region), SAWITH1 AS (select count(distinct T42433.Cust_Key) as c1 from BISAMPLE.SAMP_TIME_MTH_D T42405 /* D02 Time Month Grain */ , BISAMPLE.SAMP_REVENUE_F T42433 /* F10 Billed Rev */ where ( T42405.Per_Name_Month = '2011 / 11' and T42405.Mth_Key = T42433.Bill_Mth_Key ) ) select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3, D1.c4 as c4 from ( select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3, D1.c4 as c4 from (select 0 as c1, D1.c2 as c2, D1.c1 as c3, D2.c1 as c4, ROW_NUMBER() OVER (PARTITION BY D1.c2 ORDER BY D1.c2 ASC) as c5 from SAWITH0 D1, SAWITH1 D2 ) D1 where ( D1.c5 = 1 ) order by c2 ) D1 where rownum <= 500001
Il valore totale, 480, corrisponde alla somma dei valori costitutivi, ossia 182 + 113 + 185. L'espressione di query logica che calcola il totale è la seguente: "REPORT_AGGREGATE("A - Sample Sales"."Counts"."32 # of Cust with Orders (Cnt Distinct)" BY ) s_3".
Quando si utilizza REPORT_AGGREGATE
, il totale viene calcolato indipendentemente dai valori costituivi. Tuttavia, per questa progettazione di report, il totale corretto può essere calcolato in base ai valori costitutivi del report.
Se si modifica la formula della colonna in modo da cambiare il valore di Regola di aggregazione (riga Totali) da Aggregato complesso server in Somma, le query SQL logica e fisica vengono modificate.
Nella figura riportata di seguito viene mostrata l'aggregazione originale.
Nella figura riportata di seguito viene mostrata l'aggregazione modificata.
Nella query SQL logica modificata ora è indicato REPORT_SUM
:
SELECT 0 s_0, "A - Sample Sales"."Cust Regions"."C50 Region" s_1,"A - Sample Sales"."Counts"."32 # of Cust with Orders (Cnt Distinct)" s_2, REPORT_SUM("A - Sample Sales"."Counts"."32 # of Cust with Orders (Cnt Distinct)" BY ) s_3 FROM "A - Sample Sales" WHERE ("Time"."T02 Per Name Month" = '2011 / 11') ORDER BY 2 ASC NULLS LAST FETCH FIRST 500001 ROWS ONLY
Questa è la query fisica generata:
WITH SAWITH0 AS (select count(distinct T42433.Cust_Key) as c1, T42430.Region as c2 from BISAMPLE.SAMP_CUSTOMERS_D T42428 /* D60 Customers */ , BISAMPLE.SAMP_ADDRESSES_D T42430 /* D62 Customers Addresses */ , BISAMPLE.SAMP_TIME_MTH_D T42405 /* D02 Time Month Grain */ , BISAMPLE.SAMP_REVENUE_F T42433 /* F10 Billed Rev */ where ( T42405.Mth_Key = T42433.Bill_Mth_Key and T42405.Per_Name_Month = '2011 / 11' and T42428.Cust_Key = T42433.Cust_Key and T42428.Address_Key = T42430.Address_Key ) group by T42430.Region), SAWITH1 AS (select 0 as c1, D1.c2 as c2, D1.c1 as c3 from SAWITH0 D1) select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3, D1.c4 as c4 from ( select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3, sum(D1.c3) over () as c4 from SAWITH1 D1 order by c2 ) D1 where rownum <= 500001
La stessa opzione per impostare in modo esplicito l'aggregazione è disponibile nelle cartelle di lavoro. Vedere Formattare i valori numerici delle visualizzazioni. In questo esempio, modificare Metodo di aggregazione in Somma per la colonna Count Distinct Customers with Orders.
Rivedere i report per verificare che venga utilizzata la regola di aggregazione migliore. Utilizzare una regola di aggregazione esplicita quando la progettazione del report lo consente.
Per ulteriori informazioni sui report, vedere Creare analisi.