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

KB484742: Improved performance by push down of Percentile function to the data source


Min Zhao

Quality Engineer, Principal • MicroStrategy


This article describes how MicroStrategy has improved performance when using percentile functions by pushing the calculation to underlying data source.

Description

The percentile function is an eggregate function used in Strategy. Prior to Strategy 2020, it was calculated in the Analytical Engine, which means it fetches raw data from memory.
In the following example, the percentile function fetches all raw data from the MNTH_CATEGORY_SLS fact table in the data source. Then, it calculates the metrics defined with the percentile function in the Analytical Engine.


M01: Percentile(Cost, 0.3) {~}
Report: Quarter, Month, M01
select	"a11"."MONTH_ID"  "MONTH_ID",
	"a11"."CATEGORY_ID"  "CATEGORY_ID",
	"a11"."TOT_COST"  "WJXBFS1"
from	"MNTH_CATEGORY_SLS"	"a11"

create table ZZMD01(
	"MONTH_ID"	NUMBER(10), 
	"WJXBFS1"	FLOAT(24))

[Analytical SQL calculated by the Analytical Engine:
	select	MONTH_ID,
		Percentile("WJXBFS1", 0.3)
	from	[previous pass]
]

insert into ZZMD01 values ([Analytical Engine Results: MONTH_ID, Percentile("WJXBFS1", 0.3)])

Solution

In Strategy 2021, the calculation of the percentile function has been pushed to the data source side to improve performance.
The top ten gateways, including Oracle and SQL Server, support percentile functions in SQL statements. For the supported gateways listed at the end of this article, calculating the percentile function at the data source side can improve performance. This is because the amount of data that needs to be transferred can be substantially reduced, depending on the "cardinality" or number of rows in the fact table versus the aggregate table.

SQL Syntax

Different gateways support different SQL syntax to calculate the percentile function.
PARTITION by


select	distinct [a11].[MONTH_ID]  [MONTH_ID],
	PERCENTILE_CONT (0.3) WITHIN GROUP ( ORDER BY [a11].[TOT_COST] asc) OVER (PARTITION BY [a11].[MONTH_ID])  [WJXBFS1]
into ##ZZT8N58IE65MD001
from	[MNTH_CATEGORY_SLS]	[a11]

GROUP By

select	"a11"."MONTH_ID"  "MONTH_ID",
	PERCENTILE_CONT (0.3) WITHIN GROUP ( ORDER BY "a11"."TOT_COST" asc)  "WJXBFS1"
from	"MNTH_CATEGORY_SLS"	"a11"
group by	"a11"."MONTH_ID"

Cases that don't support the percentile function push down

For the following situation, we still keep the old logic to calculate percentile functions in the Analytic Engine due to production limitations, even if percentile functions are supported on the data source side:
Compound metrics defined with more than two metrics. At least one metric is using the percentile function and the other metric is using other functions.
Example:


(Sum(Cost){~+} - Percentile(Cost, 0.3) {~} )

Metadata and Data Engine Version Requirements

Your metadata must be upgraded to Strategy 2021 or above to populate the new SQL pattern. This requires switching the Data Engine Version to 2021 or above to push down the percentile function calculation to the data source side.

Supported Gateways

  • Microsoft SQL Server 2008 and 2008 R2
  • Microsoft SQL Server 2012
  • Microsoft SQL Server 2014
  • Microsoft SQL Server 2016
  • Microsoft SQL Server 2017
  • Microsoft SQL Server 2019
  • PostgreSQL
  • Amazon Redshift
  • Google BigQuery
  • Oracle 11gr2
  • Oracle 12c
  • Oracle 12cr2
  • Oracle 18c
  • Oracle 19c
  • SAP HANA 1.x
  • SAP HANA 2.x
  • Teradata 15.x
  • Teradata 16.x
  • Teradata 17.00
  • Snowflake
  • IBM Db2
  • Azure Synapse Analytics

Comment

0 comments

Details

Knowledge Article

Published:

December 3, 2020

Last Updated:

January 11, 2021