TATECHATLAS
◎ English
SAP & ERP / Guide

Managing Parallelism and Partitioning in SAP HANA Cloud with SQL Analyzer

Use SQL Analyzer to measure real parallelism and per-step record counts before partitioning, detect data skew on partition keys, and complement static partitioning with Plan Variants for parameterized workloads.

On this page

Measure actual query parallelism and per-operator record counts in SQL Analyzer before deciding on partitioning. Partition large tables so the execution engine can process segments concurrently, but verify that the partition key distributes rows evenly to avoid skew. For parameterized queries whose filter selectivity varies across executions, enable Plan Variants so SAP HANA caches multiple execution plans keyed on predicate selectivity clusters rather than reusing a single suboptimal plan.

Context: Why SQL Analyzer Is the Starting Point

Debug Query mode in SAP Business Application Studio reveals the generated SQL for a calculation view and shows how filters are pushed down and columns are pruned. That information is useful for structural review, but it does not answer the questions that matter for performance tuning: total execution time, time spent in each operator step, record counts processed per step, the degree to which SAP HANA Cloud parallelized the query, which processing engines were invoked, and whether all plan steps were fully unfolded. Without those runtime metrics you are optimizing blind. The SQL Analyzer view fills this gap by collecting a plan file that captures the actual execution profile of a specific query run, letting you drill into a timeline graph, inspect per-step durations, and compare record counts across parallel threads. The source material on the SAP Learning course for SAP HANA Cloud modeling states explicitly that seeing generated SQL does not tell us how the SQL actually performs, which is precisely why the SQL Analyzer exists as a separate diagnostic step.

Run the partition-distribution query in section five against a representative production snapshot, not a development copy, because row counts on the partition key can differ dramatically between environments and a skew that is invisible in development will appear under real load.

Recommendation: Measure Parallelism Before Partitioning

Partitioning a table creates segments that the engine can scan and process concurrently, but it only helps when the query plan actually exploits those segments. If a query already runs serially through a single thread regardless of table size, adding partitions will not change the execution path and may even add overhead from segment management. Before applying partitioning, open the SQL Analyzer view, run the target query, and examine the parallelism indicator in the plan file. Look at how many threads the optimizer assigned to each operator and whether record counts are spread across those threads. If the parallelism degree is already high and the bottleneck lies elsewhere, such as a missing join predicate or an unpruned column list, partitioning is the wrong lever. Only when the plan shows a single-threaded scan over a large table should you consider partitioning as a means to unlock concurrency.

Reasoning: How Partitioning Enables Concurrency

When a table is partitioned, SAP HANA Cloud stores rows in separate physical segments based on the partition key. During query execution the optimizer can assign different worker threads to different segments, allowing scans, joins, and aggregations to proceed in parallel rather than serially over one monolithic table. This reduces the per-thread workload proportionally to the number of segments and can cut wall-clock time significantly for large analytical queries. The mechanism is most effective on column-store tables where the engine already benefits from parallel column scans, and where the partition key aligns with the query's filter predicates so that partition pruning eliminates irrelevant segments before any thread begins work.

Trade-off: Data Skew Can Nullify Partitioning Gains

Partitioning assumes that rows distribute roughly evenly across segments. If the partition key has an uneven distribution, some segments hold disproportionately many rows while others hold very few. The threads assigned to the heavy segments dominate wall-clock time, and the threads on light segments finish early and sit idle. The result is that the slowest segment determines total execution time, effectively serializing the query despite the partitioning effort. In extreme cases a skewed partition is worse than no partition at all because the overhead of managing empty or tiny segments adds to the cost without contributing to parallelism. Diagnosing this imbalance requires per-segment record counts, which the SQL Analyzer provides in its operator-step breakdown.

Illustration: Diagnosing Skew Through SQL Analyzer Metrics

Consider a cube calculation view that joins a 500-million-row fact table partitioned by calendar month against a dimension table. The SQL Analyzer shows the join operator on the fact table taking 45 seconds total. Drilling into the step breakdown reveals that January through March segments each process 15 million rows in about 3 seconds, while the December segment processes 120 million rows in 39 seconds because of a year-end batch load. The partition key is skewed. The remedy is to switch to a composite partition key such as month combined with company code, which spreads the December volume across multiple company-code segments. After redeploying, regenerate the plan file in SQL Analyzer and confirm that per-segment record counts are roughly equal and that total join time drops below 15 seconds. The following query helps verify distribution before and after the change.

SELECT PARTITION_ID, COUNT(*) AS ROW_COUNT
FROM MY_FACT_TABLE
GROUP BY PARTITION_ID
ORDER BY ROW_COUNT DESC;

Complementary Approach: Plan Variants for Parameterized Workloads

Static partitioning addresses structural parallelism but does not solve performance fluctuation caused by varying parameter values in parameterized queries. When the same SQL statement is executed with different filter values, the selectivity of those filters can change dramatically, making a single cached plan suboptimal for some executions. Plan Variants let SAP HANA cache multiple execution plans for one parameterized statement, grouping filter values into selectivity clusters. The optimizer evaluates predicates, compiles a plan for each cluster, and associates the cluster with the specific filter values observed at runtime. You can monitor active variants and their execution statistics through the M_SQL_PLAN_VARIANTS and M_SQL_PLAN_VARIANT_STATISTICS system views. This mechanism complements partitioning by handling the dynamic dimension of performance variation that a fixed partition scheme cannot address.

Operational Setup: Privileges and Tooling Requirements

The SQL Analyzer view is available only when the SAP HANA Performance Tools extension has been added to your SAP Business Application Studio development space. The extension can be added when the space is stopped or during creation. The user who runs the analysis, whether the technical HDI container user or a classic database user, needs two system privileges: TRACE ADMIN and INIFILE ADMIN. Without these, plan file generation will fail. The typical workflow is to place the SQL statement in an SQL Console, invoke Analyze then Generate SQL Analyzer Plan File, and open the resulting .plv file in the SQL Analyzer view. If the plan file was generated outside the embedded Database Explorer, download it and upload it to a project folder before opening it in the analyzer.

GRANT TRACE ADMIN TO ANALYZING_USER;
GRANT INIFILE ADMIN TO ANALYZING_USER;

Limits: When These Techniques Do Not Apply

SQL Analyzer captures a single execution snapshot. It does not predict behavior under different concurrent workloads, varying data volumes, or after statistics changes without repeated measurement. Partitioning benefits queries that scan or aggregate large portions of a table; point lookups returning a handful of rows gain little because the engine resolves them through index or hash access regardless of segment count. Data skew on the partition key can make partitioning worse than the unpartitioned baseline if not diagnosed and corrected before deployment. Plan Variants address parameter-value-driven fluctuation but do not fix structural model issues such as missing join predicates, unpruned columns, or inefficient join order. Finally, the plan-file generation and upload workflow adds operational overhead compared to inline debugging tools, so it is best reserved for targeted performance investigations rather than routine development checks.

Things to check

  • Confirm that the SAP HANA Performance Tools extension is installed in the development space before attempting to open the SQL Analyzer view.
  • Verify that the analyzing user holds both TRACE ADMIN and INIFILE ADMIN system privileges; plan file generation fails silently or with a permission error otherwise.
  • Run the partition-distribution query against production-scale data, not a development copy, because row counts on the partition key can differ by orders of magnitude between environments.
  • After applying a composite partition key, regenerate the SQL Analyzer plan file and compare per-segment record counts to the previous run to confirm the skew was resolved.
  • For parameterized queries, check M_SQL_PLAN_VARIANTS to confirm that multiple plan variants are active and that filter values are mapped to the expected selectivity clusters.

SQL Analyzer measures one execution snapshot and does not generalize across concurrent workloads or varying data volumes without repeated measurement. Partitioning only benefits scan-heavy or aggregate-heavy queries over large tables; point lookups on small result sets gain little. Data skew on the partition key can make partitioning worse than no partitioning if not diagnosed and corrected before deployment. Plan Variants address parameter-value-driven fluctuation but do not fix structural model inefficiencies such as missing joins, unpruned columns, or poor join order. The plan-file workflow adds operational overhead compared to inline debugging tools.

Sources

  1. SAP Learning: Analyzing executions with the SQL Analyzer ↗
  2. SAP Learning: Using plan variants to optimize parameterized queries ↗
Back to top ↑