SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Table Statistics and its Effect on Query Plans

Create table statistics. Analyze impact of statistics on query plans.

Overview

🎓 beginner 15 min. SAP HANA Dynamic TieringBeginnerSAP HANASAP HANA StudioBig DataSql

You will learn

  • โœ”Creating table statistics.
  • โœ”Analyzing the effect of table statistics on query plans.
Unknown U Unknown November 1, 2022
Created by December 14, 2016
Contributors

Prerequisites

Prerequisites

Steps

Next Steps

Time to Complete

20 Min.


Intro

SAP HANA and Dynamic Tiering relies on statistics in order to help the optimizer choose the most effective access plan. Creating statistics is particularly important for queries involving Dynamic Tiering as they help SAP HANA determine when it is appropriate to use optimizations like joinRelocation or SemiJoin rules. These query operators help SAP HANA and Dynamic Tiering minimize the volume of data (# of rows & column values) transferred between the core SAP HANA and Dynamic Tiering nodes.

Step 1 Create Prepared and Executed Query Plans
โ€”

During this tutorial we will be creating statistics for the TPCH.PART_DT table. In order to see the effect of creating statistics, we first want to generate and save the Prepared and Executed plans for a query on the TPCH.PART_DT table before the statistics get created. Use the following script to create the Prepared and Executed Plans:

SQL
select
	s_acctbal,
	s_name,
	n_name,
	p_partkey,
	p_mfgr,
	s_address,
	s_phone,
	s_comment
from
	TPCH.PART_DT,
	TPCH.SUPPLIER_DT,
	TPCH.PARTSUPP_DT,
	TPCH.NATION_CS,
	TPCH.REGION_CS
where
	p_partkey = ps_partkey
	and s_suppkey = ps_suppkey
	and p_size = 38
	and p_type like '%COPPER'
	and s_nationkey = n_nationkey
	and n_regionkey = r_regionkey
	and r_name = 'AMERICA'
	and ps_supplycost = (
		select
			min(ps_supplycost)
		from
			TPCH.PARTSUPP_DT,
			TPCH.SUPPLIER_DT,
			TPCH.NATION_CS,
			TPCH.REGION_CS
		where
			p_partkey = ps_partkey
			and s_suppkey = ps_suppkey
			and s_nationkey = n_nationkey
			and n_regionkey = r_regionkey
			and r_name = 'AMERICA'
	)
order by
	s_acctbal desc,
	n_name,
	s_name,
	p_partkey;

You could also save the plans if you choose to by clicking on the “Save As” icon in the Prepared/Executed Plan window.

Save Plan
Save Plan

To open a saved plan, click on File > Open File… and then browse to where you saved the plan.

Open Plan
Open Plan

Step 2 Create Statistics and Opening Prepared and Executed Query Plans After Running Statistics
+
Step 3 Analyze the Impact of Statistics on Prepared Plans
+
Step 4 Analyze the Impact of Statistics on Executed Plans
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 4
1. Create Prepared and Executed Query Plans 2. Create Statistics and Opening Prepared and Executed Query Plans After Running Statistics 3. Analyze the Impact of Statistics on Prepared Plans 4. Analyze the Impact of Statistics on Executed Plans

Learn more →