Showing posts with label puzzle. Show all posts
Showing posts with label puzzle. Show all posts

Oracle BI EE 10.1.3.4.1 – Solutions – Puzzle 4

The 4th puzzle in this series was a reasonably simple one which basically demonstrates a capability that allows end users to bypass the security applied in the BI Server layer. There are 3 possible solutions for this
Solution 1: Using Evaluate
EVALUATE was introduced in the 10.1.3.3.1 version of BI EE, that allows end users to call database functions directly. This feature has a lot of uses and actually is widely used. One such use case (others might term this as a bug) is its ability to call table columns that are not in the repository, by using native database functions. For example, the report shown below is a very simple one where only dimensional attributes CHANNEL_CLASS and CHANNEL_TOTAL exist in the report
image
The SQL for this report is give below
select distinct T4167.CHANNEL_TOTAL as c1,
     T4167.CHANNEL_CLASS as c2
from
     CHANNELS T4167
order by c1, c2
In our case CHANNEL_DESC column is completely not available for reporting as that is blocked by Security in the presentation layer as shown below
image
To bypass this, in one of the columns of the above report, use an EVALUATE function shown below
EVALUATE(‘DECODE(%1,”Dummy”,NULL,CHANNEL_DESC)’ AS CHAR(10),Dim.CHANNEL_CLASS)
This will basically bypass the security of the BI Server and will provide a means of looking at the CHANNEL_DESC column directly. The report and the SQL are given below
image
select distinct T4167.CHANNEL_TOTAL as c1,
     T4167.CHANNEL_CLASS as c2,
     DECODE(T4167.CHANNEL_CLASS,'Dummy',NULL,CHANNEL_DESC) as c3
from
     CHANNELS T4167
order by c1, c2, c3
So far so good. Now, lets try adding a measure to this report. You will notice that this will start producing an OCI error.
image
The reason is since CHANNEL_DESC was not part of the report directly, BI Server did not include that as part of the Select or the Group By clause. The wrong SQL is given below
select T4167.CHANNEL_TOTAL as c1,
     T4167.CHANNEL_CLASS as c2,
     DECODE(T4167.CHANNEL_CLASS,'Dummy',NULL,CHANNEL_DESC) as c3,
     sum(1) as c4
from
     CHANNELS T4167
group by T4167.CHANNEL_CLASS, T4167.CHANNEL_TOTAL
order by c1, c2, c3
Now, to make this work even when a fact attribute is included, the only option is to somehow push this column inside an Aggregate function like SUM, MAX etc since we cannot make the BI Server to generate the Group By (for the secured column). This requires a non-secure dimensional attribute at the same grain as the secured column. In our case, both CHANNEL_CLASS and CHANNEL_DESC have one to one relation and hence i will use that itself to demonstrate. The idea is to encapsulate the EVALUATE expression inside a string aggregate function like MAX etc as shown below
MAX(EVALUATE(‘DECODE(%1,”Dummy”,NULL,CHANNEL_DESC)’ AS CHAR(10),Dim.CHANNEL_CLASS))
image
select T4167.CHANNEL_TOTAL as c1,
     T4167.CHANNEL_CLASS as c2,
     max(DECODE(T4167.CHANNEL_CLASS,'Dummy',NULL,CHANNEL_DESC)) as c3,
     sum(1) as c4
from
     CHANNELS T4167
group by T4167.CHANNEL_CLASS, T4167.CHANNEL_TOTAL
order by c1, c2
How do we disable this ability completely as this might be considered as a security bug? Ideally i would like to have a privilege in Answers, that can basically stop the use of EVALUATE functions thereby providing us with the capability of controlling who has access to this. But since this is not currently available, the easiest approach is to make sure that all your query columns are pushed into a sub-query. There are a multiple ways we can push all the columns to a sub-query. I will list them below
1. Using Logical Columns
2. Using Level Based Measures
3. Using SELECT based tables
There are other techniques as well. But for the sake of keeping this brief, i will show how all columns can be pushed into Sub-Queries using SELECT tables (instead of the normal tables obtained through Import). The idea is to use a simple table based on SELECT as shown below
image
instead of the normal imported table. Then we cannot use EVALUATE as the EVALUATE function can be pushed only to the sub-query. For example, the SQL for the same report above, using SELECT table instead of normal table is given below
select distinct T5419.CHANNEL_TOTAL as c1,
     T5419.CHANNEL_CLASS as c2
from
     (SELECT
CHANNEL_CLASS,
CHANNEL_CLASS_ID,
CHANNEL_ID,
CHANNEL_TOTAL,
CHANNEL_TOTAL_ID
FROM
CHANNELS) T5419
order by c1, c2
As you see, whatever function we apply in the front-end will always be pushed only to the outer query (inner sub-query will always remain the same which is for the SELECT table). Hence other than the columns in the Select sub-Query, EVALUATE cannot get external columns residing in the actual table (CHANNEL_DESC for example). If we try using the same EVALUATE function we will get an error. But this approach has potential performance issues since for every query, depending on the database, predicates might not get pushed from outer query to inner sub-query(within the optimizer) thereby causing performance issues.
People who answered this correctly: Craig, Anu
Solution 2: Using BYPASS_NQS authentication
This is not something that is normally used. But this is another important example where when the authentication model gets changed, the entire BI EE security can be bypassed. This security model allows any user to login to BI EE. But only database users will be allowed to report out of the databases(login to BI EE with the same username/password as the database). When this is done, any security that is applied at the column level will be bypassed and hence everyone can see the secured column data as well
image
Solution 3: Impersonation & Proxy Authentication
For this solution to work, one needs to have the privilege to do proxy authentication. Also, one cannot call this exactly as a security bypass since the user requires the capability to proxy in as another user. But there are cases when logged in as a single user, to look at the actual report values (during report development) we might want to login as Administrator which will essentially bypass all the security that is applied at the column level in BI Administrator. For more details on Proxy Authentication refer my blog post here.
The 5th Puzzle in this series to follow later this week.

Oracle BI EE 10.1.3.4.1 – Solutions – Puzzles 1 & 2

Well its been almost a week since i blogged the first 2 puzzles in this puzzle series. I guess it is time for me to blog about the solutions. I have been amazed by the response so far. Its been really positive, so more puzzles to come during this week and the next.
Puzzle 1 Solution1:
Well, this was a very easy puzzle and lot of people got it right. There are a couple of possible solutions. The most obvious and the easiest solution for this is to create a universal security group in the repository and then in the filters area assign the column level filters (vary the filter depending on the column) as shown below
image
I had to put this as a puzzle since this is one feature that i feel is the most under-utilized in BI EE. The drawback with this is the fact that this solution cannot be applied for Administrator user directly. But that is one user that is rarely exposed directly to end users.
People who got it right: Nicolas Gerard, Fiston and Harish Gopalan
Puzzle 1 Solution 2:
The other solution is to use a combination of multiple logical table sources in the dimension logical table. This is again another solution that directly affects the modeling we do in the Business Model and Mapping layer. Though it requires some work compared with solution 1, this can prove to be quite useful when the requirement is rephrased a bit like this. The report columns and the filters for the rephrased question is given below
“CHANNEL_CLASS & AMOUNT_SOLD” – Filter required is CHANNEL_CLASS = ‘Puzzle1 Test’
“CHANNEL_DESC & AMOUNT_SOLD” – Filter required is CHANNEL_DESC = ‘Puzzle Test2′
“CHANNEL_CLASS, CHANNEL_DESC & AMOUNT_SOLD” – Filter required is CHANNEL_DESC = ‘Puzzle Test3′ and CHANNEL_CLASS = ‘Puzzle Test4′
In such a case, solution 1 cannot be used. Only solution 2 can be used. Screenshots of the BMM is given below for this
image
image
image
image
Each LTS will have a separate filter. Ordering of the LTS is important to push the predicate filters properly.
People who got it right: Christian Berg, Nicholas Gerard and Ilmari Alto
Puzzle 2:
Puzzle 2 was a bit trickier as there are quite a few possible solutions. But lot of people answered it correctly.
Puzzle 2 Solution 1:
Everyone who answered this correctly, have used the solution 1. This basically alters 2 Database Features. They are given below. The idea is to basically enable both the options below
1. PERF_PREFER_MINIMAL_WITH_USAGE
2. PERF_PREFER_INTERNAL_STITCH_JOIN
image
Or the other option is to just switch between 10gR1 and 11g/10gR2 as the database in the database type (this basically does the same thing as above – enables both the options above)
Picture 2
The drawback with this solution is, altering the database features can start affecting other queries. WITH clause provides such an advantage and sometimes even in a normal model(without conforming dimensions), the queries might get pushed to the BI Server. I generally do not recommend altering the database features unless its told by Oracle support. For example there have been instances in older versions of BI EE where PERF_PREFER_INTERNAL_STITCH_JOIN was asked to be enabled/disabled by Oracle support (due to bypass some 10gR1/10gR2 database bug). I generally prefer a solution where everything is always pushed to the database but if due to some reason we want to enable the BI Server join then we should be in a position to do that. For example, there have been instances(couple of bugs in BI EE which even exists in 10.1.3.4.1) where BI EE generates wrong sub-totals when pushed to the database. In many cases, this happens when conforming dimension joins happen at the database and we start getting nulls in the results. To check whether sub-total query is wrong we might want to push everything (even the conforming dimension join to the BI Server). The following 2 solutions basically demonstrate that. One other potential issue is, if you have more than one fact table from the same database then, even those conforming dimensions will be pushed to the BI Server layer. The other drawback is, i can still make BI EE to generate the database joins. Want to know how? Well, lets enable the above 2 settings in the physical database features. And lets create a report. In the Advanced SQL of the report, enter the below logical SQL
SELECT A.CHANNEL_CLASS saw_0,
 A.QUANTITY_SOLD saw_1,
 B.UNIT_COST saw_2
 FROM
 (
 SELECT Channel.CHANNEL_CLASS,
 Sales.QUANTITY_SOLD
 FROM "SH - Conforming Dimension)
 A FULL OUTER JOIN
 (
 SELECT Channel.CHANNEL_CLASS,
 Costs.UNIT_COST
 FROM "SH - Conforming Dimension") B
 ON A.CHANNEL_CLASS = B.CHANNEL_CLASS
 ORDER BY saw_0
If you look at the report now, you will notice that this join has actually been pushed into the database (even after disabling the WITH clause and STITCH join features)
image
But from a Puzzle standpoint, i was expecting any one of these solutions. So thanks for everyone who answered this correctly.
People who got it right: Vinod Jaganathan, Harish Gopalan, Somasekhar
Puzzle 2 Solution 2:
This involves adding more metadata to the repository and altering the BMM layer. But this provides you complete control on how the joins will be generated and you can be sure about the structure of the SQL Query. Basically the idea is to replicate the dimension and the fact table in 2 separate databases. For example, CHANNELS and SALES in one database & CHANNELS and COSTS in the other database as shown below
image
And your BMM dimension will have 2 sources (same CHANNELS source coming from 2 different Physical Databases as shown below
image
image
If you think logically, when we model the same set of tables in different databases, from a BI EE standpoint, these 2 are completely different. So, if you think from a SQL standpoint, the only way we can enforce the conforming dimension join in the database is by using Database links. Since we do not have them here, only way BI EE can join them is by stitching them in its memory. Remember, if you create aliases within the same physical database, even then BI EE will force the SQL to the database as, from a BI EE perspective, all the tables still reside in the same database. The issue with this approach is, it will become very difficult to manage the BMM layer especially when you have a physical source like BI Applications. But this is something to keep in mind while doing any Repository Modeling.
People Who got it right: Scott Powell (was close in mentioning the alias solution but i give the benefit of the doubt as this was the only comment suggested that was in line with this solution)
Puzzle 2 Solution 3:
This is something that is used rarely. Now that 11g is around the corner where everything will be based on View Objects etc, it becomes even more important to consider this. Understanding Logical SQL is very important as in many cases we would be using BI Server and some other front end instead of presentation services. The solution is to use a logical SQL that basically combines both the facts in separate sub-queries. This is not a straight forward solution. This requires introducing just a single CHANNELS table in another physical database (instead of all the tables,including the facts as described in the above solution) and creating a dummy Presentation Subject area containing the table.
image
Then use logical SQL method to push the join to the BI Server layer (introduce the new presentation layer object Channels)
A simple logical SQL that i used is given below
SELECT
 A.CHANNEL_CLASS saw_0, A.QUANTITY_SOLD saw_1, B.UNIT_COST saw_2
 FROM (
 SELECT
 Channel.CHANNEL_CLASS,
 Sales.QUANTITY_SOLD
 FROM "SH - Conforming Dimension"
 ) A FULL OUTER JOIN (
 SELECT
 Channel.CHANNEL_CLASS
 FROM
 "SH - Conforming Dimension#1"
 ) B ON A.CHANNEL_CLASS = B.CHANNEL_CLASS FULL OUTER JOIN (
 SELECT
 Channel.CHANNEL_CLASS,
 Costs.UNIT_COST
 FROM
 "SH - Conforming Dimension"
) C ON A.CHANNEL_CLASS = C.CHANNEL_CLASS
 ORDER BY saw_0
As you see i basically fired 3 separate sub-queries and then joined them together in the logical SQL. When you enter this in Answers, you will notice that the join is pushed to the BI Server irrespective of how you have modeled the repository. A sub-query join in BI Server means a join at the BI Server layer.
image
If you look at the SQL, you will notice that there are 3 SQLs that get fired simultaneously and all of them are joined in the BI Server memory. Not exactly the solution i was looking for but this pushes the join to the BI Server layer. This technique has a lot of drawbacks as well like you lose the drills in the front-end etc. But i generally always like the logical SQL approach not for implementation but for visualizing how your BMM layer has to be structured.
image
There is one more solution as which also uses an extra new physical database table. But i will leave that for now as it more or less follows what i have discussed in the above 2.
There can be other possible solutions as well. If you can think of any feel free to add them in the comments. As i have said this before BI Server is one of the best tools out there that can effectively model most reporting scenarios. There can be more than one possible way of arriving at a solution. Of course, there will be advantages and disadvantages associated with each approach. The idea of the Puzzle series is to basically highlight as many solutions along with their drawbacks etc.

Oracle BI EE 10.1.3.4.1 – Solutions – Puzzle 3

After almost a week of me giving out the Puzzle 3, there was hardly any interest for this one (just couple of odd replies requesting clarification of the Puzzle). Probably this is because this one has no direct practical usage and also there are lots of possibilities. But to me this is one very important Puzzle as in many cases when we are called in for repository tuning, the first question that we normally get in such situations is, why does BI EE generate such a big query when the same report can be solved by a very simple query. In such cases, we need to know where to look at and also understand what can cause BI EE to generate long SQLs. Remember, there is no theoretical limit to the length of the SQL generated (we can make it to generate as big a SQL as we want). The puzzle was meant primarily to know the possibilities of what can make BI EE to generate long SQLs. I always try to visualize a repository by looking at the SQL. That generally helps in doing further analysis on a pre-built repository.
Solution 1 – Conforming Dimensions:
This is probably the easiest and the most common reason why BI EE generates a lot of sub-queries. Always conforming dimensions should be used only when absolutely necessary as that will start generating sub-queries for every fact. For example, if you look at the repository below, it shows a very simple Business Model and Mapping layer containing one dimension with one Logical table source pointing to the physical CHANNELS table.It also contains 3 Facts each having a count metric (Mapped to 1 in the BMM layer for all the 3 columns)
image
image
There is also one more Logical Column that basically adds all the 3 columns together using a logical calculation
image
Now, when you generate a report using the CHANNEL_TOTAL and the logical calculated column, you will notice that BI EE will generate 3 sub-queries and then will bring them together as shown below
image
So the solution is you can create n number of conforming dimensions like this to make BI EE to produce n sub-queries thereby making the SQL very long. In this case there is no need for actually using conforming dimensions. The same SQL can actually be converted into a single SQL with all the counts (without the sub-queries). This basically demonstrates a bad use of Conforming Dimensions.
Solution 2 – Fragmentation:
This is another way of generating big SQLs. Same source can be made to appear as part of UNION ALL queries using Fragmentation. For example, if you look at the repository below
image
there are basically 3 logical table sources that contribute to the Fact Count. Each logical table source is modeled in a way such that all of them contribute to the Count and follow Parallel Fragmentation as shown below
imageimage
image
And if you look at the SQL, you will notice that BI EE will fire 3 UNION ALLs to generate the count. You can make this query as big as you want by adding more and more logical table sources.
image
Solution 3 – Level Based Measures:
This is another possible solution where incorrect use of Level-Based aggregation can start generating pretty complex queries. In your queries, if you start noticing Partition By using ROW_NUMBER or SUM() OVER functions then that means level based measures are being used somewhere (not in all cases but in most of them). For example, lets look at the repository below
image
As you notice we basically have have 3 count columns each dependent on the other. Count1 is a normal measure assigned to a constant 1 and to the lowermost level in the Channel Dimension. Count 1 is a measure which is equal to measure Count(logically calculated) but assigned to the Channel Class level. Count3 is equal to measure Count2(logically calculated) but assigned to the Total level.
image
image
image
As you see, this basically demonstrates why logically calculated measures can have different level assignments than their base members. If you look at the SQL generated,
image
you will notice a number of sub-queries which will equal to the number of level assignments for each dependent measure.
In all the cases above, the queries were generated using a single Physical table and from just using 2 report attributes. Much more complex queries are possible using other methods but most of them will be a variation of the 3 listed above. Puzzle 4 to follow tomorrow.