简体   繁体   中英

Slow calculated measure with tuple

I have one fact table that has all information regarding how much a company buys and sells. In order to create som calculation regarding f.ex margin I need to use the rows for a purchase together with rows for sales to get the correct calculations.

Now, I have created a calculated measure that gives me the correct result, but the more dimensions I add to my query the slower the query runs when using this calculated measure. It seems like it is using a lot of time to return the tuples I am using to find the rows regarding purchase.

I am using tuples to "store" the purcase row, but the tuple becomes quite large because I need to include all default members of dimensions used by the sales rows in order for them to be used. Basicly my tuples looks like this just with more dimension hierarchies:

(
        [Dimension 1].[Hierarchy 1].&[member]
        ,[Dimension 1].[Hierarchy 2].&[member]    
        ,[Dimension 2].[Hierarchy 1].&[member]
        ,[Dimension 3].[Hierarchy 1].&[member]
        ,[Dimension 4].[Hierarchy 1].&[member]          
        ,[Measures].[Purchase Standard Cost]
    )

I then multiply this tuple with a measure from the sales rows and I get my result.

Anyone have any tips on how to improve the query performance? The calculation works and if I slice by just a couple of dimensions it works just fine and performance is not to bad, but the more I add the slower it gets and the users will hit performance issues.

Since amount of used dimensions increased, Storage Engine has to scan additional files, it could be a reason of such performance degradation.

I have several suggestions based on their effectiveness from my point of view:

  1. Implement partitioning (if it's not implemented yet) to scan lower amount of data.
  2. "Materialize" some tuples into physical dimension (if there are no dynamics, late-binding functions etc. in MDX):

    2.1. Add corresponding keys, which represents tuples, to your source tables.

    2.2. Build appropriate dimensions on these keys.

    2.3. Use calculated measures with these "ex-tuples".

Example:

You have a 100M rows table with columns: SomeDate, Customer, Product, Amount and a single-partitioned measure group.

You need to create tuples like (2015-01-01, Customer A, Product Z, Amount) .

Server have to scan the entire data to take exact values.

  1. Once you add partitions by SomeDate years (+slices), server will take only 2015 partition.

2.1. Add column Tuple_ID int to the table and map it during ETL.

Eg Tuple_ID = 1 where Customer = 'Customer A' and Product = 'Product Z'

2.2. Create a dimension on this new field (or on additional table with list of combinations to be able to modify logic easily).

2.3. Use ([Tuple ID].[Tuple ID].&[1],[Measures].[Amount]) in calculation.

Advantage of such technique is that server takes only pre-calculated values, and queries speed as a result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM