EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB8962: The shortest path is not always selected when two tables are joined in MicroStrategy SQL Generation Engine 9.x-10.x


Community Admin

• Strategy


SYMPTOM:
In Strategy SQL Generation Engine 9.x-10.x, when there are multiple join paths for two tables, the shortest path is not always selected by the engine.
 
For example, in a data warehouse, there are seven tables. Their structures are described in the following graphic:
 

ka04W000000OdYfQAK_0EM440000002G3E.jpeg

 
There are two paths available to join FACT_TABLE_1 and LOOKUP_MANAGER. One path includes four intermediary tables:
 
FACT_TABLE_1 > RELATE_ACCOUNT_REGION > RELATE_REGION_BRAND > LOOKUP_BRAND > LOOKUP_CATEGORY > LOOKUP_MANAGER
The other path (indicated in red) includes only one relate table:
 
FACT_TABLE_1 > RELATE_ACCOUNT_MANAGER > LOOKUP_MANAGER
It can be observed that the second join path is much shorter than the first path. For performance reasons, users would like the engine to choose the second join path in generating Structured Query Language (SQL). However, the SQL statement generated by the Strategy SQL Generation Engine actually uses the longer join path. The following table contains the desired SQL from the shorter path and the longer SQL generated by the engine:
 

DB object: “Microsoft SQL Server 2012”
RATE_IDRATE_DESC118.9212.635.749.7MONTH_IDMONTH_DESC200201Jan 02200202Feb 02200203Mar 03RATE_IDMONTH_IDFACT112002012120020342200201622002028220020310320020212420020314Type of informationLog componentLog dispatcherMDX execution errorDatabase ClassesErrorMDX for report executionEngineDFC EngineDatabase ClassesTrace SQLMDX for attribute element request *EngineDFC EngineType of informationLog componentLog dispatcherMDX execution errorDatabase ClassesErrorMDX for report executionEngineDFC EngineXMLAVerbose InfoDatabase ClassesTrace SQLMDX for attribute element requestEngineDFC EngineXMLAVerbose InfoSQL Generated by the EngineDesired SQL

DB object: “Microsoft SQL Server 2012”
RATE_IDRATE_DESC118.9212.635.749.7MONTH_IDMONTH_DESC200201Jan 02200202Feb 02200203Mar 03RATE_IDMONTH_IDFACT112002012120020342200201622002028220020310320020212420020314Type of informationLog componentLog dispatcherMDX execution errorDatabase ClassesErrorMDX for report executionEngineDFC EngineDatabase ClassesTrace SQLMDX for attribute element request *EngineDFC EngineType of informationLog componentLog dispatcherMDX execution errorDatabase ClassesErrorMDX for report executionEngineDFC EngineXMLAVerbose InfoDatabase ClassesTrace SQLMDX for attribute element requestEngineDFC EngineXMLAVerbose InfoSQL Generated by the EngineDesired SQL

select ...
from FACT_TABLE_1 a11,
RELATE_ACCOUNT_REGION a12,
RELATE_REGION_BRAND a13,
LOOKUP_BRAND a14,
LOOKUP_CATEGORY a15,
LOOKUP_MANAGER a16
where a11.ACCOUNT_ID = a12. ACCOUNT_ID and
a12.REGION_ID = a13.REGION_ID and
a13.BRAND_ID = a14.BRAND_ID and
a14.CATEGORY_ID=a15.CATEGORY_ID and
a15.MANAGER_ID =a16.MANAGER_ID

select ...
from FACT_TABLE_1 a11,
RELATE_ACCOUNT_MANAGER a12,
LOOKUP_MANAGER a13
where a11.ACCOUNT_ID = a12. ACCOUNT_ID and
a12. MANAGER_ID = a13. MANAGER_ID

CAUSE:
The Strategy SQL Generation Engine doesn't select join paths based on the length of join paths. For a report, the engine always chooses one particular path but not necessarily the shortest one.
 
WORKAROUND:
To force the engine to use the relate table instead of four other tables, it is necessary to break the longer path in order to make it invalid.
 
For example, search for the attribute defined on ACCOUNT_ID. Edit this attribute by removing RELATE_ACCOUNT_REGION table from the available table list. In that case, the ACCOUNT_ID column of FACT_TABLE_1 can't be joined with BRAND_ID column of RELATE_REGION_BRAND table because the join path between those two end tables have been removed. Since there is only join path available for FACT_TABLE_1 and LOOKUP_MANAGER, the join between those tables will always use the shorter path (the one involving RELATE_ACCOUNT_MANAGER table). The relationship between tables now is changed as follows:
 

ka04W000000OdYfQAK_0EM440000002G3a.jpeg

 
NOTE:
However, with the preceding action, a new issue arises. After breaking the two-table-join-path between FACT_TABLE_1and LOOKUP_BRAND table, the joining of these two tables will take a longer path involving the following tables:
 
FACT_TABLE_1 > RELATE_ACCOUNT_MANAGER > LOOKUP_MANAGER > LOOKUP_CATEGORY > LOOKUP_BRAND
Given this, the central question becomes which table join is more often used, FACT_TABLE_1 with LOOKUP_MANAGER or FACT_TABLE_1 with LOOKUP_BRAND? Users may sacrifice the less often used table join for the performance of the other. Since there are several joins in this long chain and breaking any join will serve the purpose, users can do a cost-and-benefit analysis for each option to see which join they want to break.
 


Comment

0 comments

Details

Knowledge Article

Published:

April 12, 2017

Last Updated:

April 12, 2017