Multiple SQL Statement for Each Measure problems.

This is behaving strangely in my opinion. First of all I would note that the check box itself is misleading. It doesn’t generate a separate SQL statement for each measure. It seems to generate a separate SQL statement for each table which has measures (and this makes sense). Secondly the help says it generates separate SQL statements for classes which again is not correct. The organization of the classes don’t make any difference it seems.

Anyway the real puzzle is that the separate SQL statements only seem to occur if the measure is defined as an SQL sum function (or other aggregates I assume). Does anybody have experience or explanations of this. I can validate this very simply. Take measures on two different tables and define them as SUM(column name) and I get two SQL statements. I remove the SUM and it goes back to one SQL statement.

Can anybody help me out with what is going on here and why?

Greg Mills
Conoco Inc.
(580) 767-5597 ETN 442-5597
s-greg.mills@usa.conoco.com


Listserv Archives (BOB member since 2002-06-25)

First, let me agree with you – it’s all very confusing, but it’s really because SQL itself is confusing. In general, that “strange” behavior that you see is exactly what you want – we have spent a lot of time working with the twisted logic of SQL, and so try to default to doing the “right thing” for you, so that you don’t have to go through the same effort.

I believe that there is a white paper available on our technical site that explains this particular case in more detail, which we call the “chasm trap” – but in general, the SQL is generated is such a way as to avoid erroneously summing partial cartesian results, which would result in end users getting incorrect results, without necessarily realizing it. It’s worth noting that none of the other products in this space even attempt to control this – presumably relying on end users to notice the errors on their own, and learn how to avoid certain types of queries!

In general, if the cardinality of the joins has been correctly defined, and contexts set up where required (again, most of the time the defaults proposed to you by the Designer are the correct ones), the SQL you’ll get will ensure correct results.

Timo

From: Mills, S. Greg [SMTP:S-GREG.MILLS@USA.CONOCO.COM] Sent: Thursday, October 08, 1998 06:19

This is behaving strangely in my opinion. First of all I would note that the check box itself is misleading. It doesn’t generate a separate SQL statement for each measure. It seems to generate a separate SQL statement for each table which has measures (and this makes sense). Secondly the help says it generates separate SQL statements for classes which again is not correct. The organization of the classes don’t make any difference it seems.

Anyway the real puzzle is that the separate SQL statements only seem to occur if the measure is defined as an SQL sum function (or other aggregates I assume). Does anybody have experience or explanations of this. I can validate this very simply. Take measures on two different tables and define them as SUM(column name) and I get two SQL statements. I remove the SUM and it goes back to one SQL statement.

Can anybody help me out with what is going on here and why?

Greg Mills
Conoco Inc.
(580) 767-5597 ETN 442-5597
s-greg.mills@usa.conoco.com


Listserv Archives (BOB member since 2002-06-25)

We were having this same problem. We did not want to generate a query for each measure. There are options in Designer so that this does not happen. If you go to parameters in Designer, then go to the SQL tab. In The Multpile Paths group box, uncheck “Multiple SQL statements for each context” and uncheck “Multiple SQL statements for each measure”. Your queries will no longer generate the multiple SQL statements.

Amy Martel
amartel@allmerica.com

“Mills, S. Greg” S-GREG.MILLS@USA.CONOCO.COM 10/08/1998 09:18am

This is behaving strangely in my opinion. First of all I would note that the check box itself is misleading. It doesn’t generate a separate
SQL statement for each measure. It seems to generate a separate SQL statement for each table which has measures (and this makes sense). Secondly the help says it generates separate SQL statements for classes
which again is not correct. The organization of the classes don’t make any difference it seems.

Anyway the real puzzle is that the separate SQL statements only seem to occur if the measure is defined as an SQL sum function (or other aggregates I assume). Does anybody have experience or explanations of this. I can validate this very simply. Take measures on two different tables and define them as SUM(column name) and I get two SQL statements.
I remove the SUM and it goes back to one SQL statement.

Can anybody help me out with what is going on here and why?

Greg Mills
Conoco Inc.
(580) 767-5597 ETN 442-5597
s-greg.mills@usa.conoco.com


Listserv Archives (BOB member since 2002-06-25)

Hi Greg,

I read the replies to your question, but don’t think these are completely true. First of all: do not use this checkbox, because it is possible to get results you really don’t want. I’ll try to explain this with an example (but the subject is still giving me headaches, so I hope I’m being clear).

Imagine a universe with three tables. Customer - Order - Orderline. (Customer:Order=1:n; Order:Orderline=1:n) Tables contain these values:

Customer: Cus_id,Name
(1,a) (2,b)

Order: Cus_id,Ord_id,Total
(1,1,10) (1,2,15) (2,3,10) (2,4,20)

Orderline: Ord_id, Ord_l_id, Amount
(1,1,6) (1,2,4) (2,4,8) (2,4,7) (3,5,3) (3,6,7) (4,8,20)

Having this implemented in your universe, BO could generate the following SQL:
Select Cus_id, Ord_id, sum(Total), sum(Amount) From Customer, Order, Orderline
Where Customer.cus_id = Order.cus_id
and order.ord_id = orderline.ord_id
Group by cus_id, ord_id

This is called the fan trap (in stead of chasm trap). Your database will do this:

1, 1, 10, 6
1, 1, 10, 4
1, 2, 15, 8
1, 2, 15, 7
2, 3, 10, 3
2, 3, 10, 7
2, 4, 20, 20

Your results will be:
Customer 1, Order 1, Total 20, Amount 10 Customer 1, Order 2, Total 30, Amount 15 Customer 2, Order 3, Total 20, Amount 10 Customer 2, Order 4, Total 20, Amount 20 Apparently you would like the totals to be equal to the amounts.

This is why Business Objects came up with the idea of the check box your question is about. If you have this check box checked, Business Objects will generate two SQL’s. One to sum the totals for the customers, one to sum the amounts for the orders. The results will be joined at the client instead of the database. Now you will get the right results.

Still you should not use the check box because when you take a condition on orderline into your querie, Business Objects will still create two SQL’s, but it will take the condition into both SQL’s, which results again into the wrong result for the customer-order-querie (because the querie joins through to orderline).

When you really want to solve this problem, you’ll have to create an alias and two contexts (which Business Objects won’t detect for you, because it only detects contexts within loops). You’ll have to alias order and have one context containing customer and order_alias and one context containing order and order_line. All measure objects selecting order now have to select order_alias. By this you’ll prevent BusinessObjects from stepping into the fan trap.

This solution seems inefficient, but it is the only way to get around the shortcomings of SQL and get meaningful querie results.

I really hope this explanation is somewhat clear.

Best regards,

Susanne Bakker
ING Netherlands.


Listserv Archives (BOB member since 2002-06-25)

Thanks Susanne. Yes it is clear and I have done an enormous amount of testing the last couple of days and came to a similar conclusion. If you want multiple SQL statements is best to have multiple contexts. What I found on the multiple SQL per measures was similar. If you included a dimension from the lower table in the query it will still join on all tables in the separate SQL. The bottom line is that you must understand exactly how all this works and tailor each universe to get the correct result. There are a number of different alternatives and they all seem to have some quirks.

At the users conference Alan Mayer of Integra Solutions provided a Fan Trap solution that included a SUM (Distinct) that solves some of these problems.

Greg Mills
Conoco Inc.
(580) 767-5597 ETN 442-5597
s-greg.mills@usa.conoco.com


Listserv Archives (BOB member since 2002-06-25)