🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Synapse SQL Pool Tuning: Distribution to Caching

Azure Data EngineeringSynapse Performance⭐ Premium

A dedicated SQL pool distributes every table across sixty distributions, and the single decision that shapes most query performance is how rows are assigned to them. Get distribution right and joins happen locally between matching distributions. Get it wrong and the engine must shuffle data across the network for every join, which dominates runtime regardless of how well the rest of the query is written.

You will be able to do the following after this lesson:

  • Choose a distribution strategy from the query pattern, not habit.
  • Detect skew and fix it before it becomes a support ticket.
  • Select indexes and statistics that suit analytical workloads.
  • Read a query plan and identify where time is actually spent.

Prerequisites

  • !T-SQL fluency
  • !Star schema concepts: fact and dimension tables
  • !Access to a dedicated SQL pool to experiment

Distribution decides before indexing does

Four distribution options exist, and each one optimizes a different access pattern.

DistributionHow rows are placedBest forCost when wrong
HashKey value determines the distributionLarge facts joined on a keyShuffles if the key is not in joins
Round robinArbitrary placementStaging and bulk loadNo locality for any join
ReplicatedFull copy on every nodeSmall dimensions under about 2 GBMemory pressure when oversized
UnknownLegacy, avoid for new tablesNothingNo optimization available

A hash key should appear in the joins that dominate your workload, and it should also have decent cardinality so rows spread evenly. A low-cardinality key such as a boolean or a two-value status column concentrates rows into a few distributions and recreates the very problem distribution was meant to solve. Replicated dimensions avoid shuffles entirely, which is why star schema designs replicate the small tables and hash the large fact on the dimension key.

Finding skew before it finds you

Skew means one or more distributions hold far more rows than the others, so the slowest distribution sets the pace for every operation. Even a modest imbalance multiplies under joins, because the skewed distribution becomes the tail of the whole query.

-- Row counts and sizes per distribution
DBCC PDW_SHOWSPACEUSED('dbo.FactSales');

-- Recent requests ordered by elapsed time
SELECT
    r.request_id,
    r.status,
    r.total_elapsed_time / 1000 AS duration_ms,
    r.row_count,
    r.spilled_thread_count,
    r.database_name,
    LEFT(r.command, 400) AS command_text
FROM sys.dm_pdw_exec_requests r
WHERE r.status = 'Completed'
ORDER BY r.total_elapsed_time DESC;

In practice DBCC PDW_SHOWSPACEUSED is the first command to run after loading a large table. If the largest distribution holds several times the average, change the hash key to something with higher cardinality, or move the table to round robin if it is a staging table that will be redistributed anyway when it moves downstream.

Indexing for analytical access patterns

Clustered columnstore indexes are the default for large fact tables because analytical queries read wide, filter, and aggregate. Columnstore delivers strong compression and batch-mode execution, both of which turn full scans into something affordable.

-- Columnstore for the fact, with a deliberate sort order
CREATE CLUSTERED COLUMNSTORE INDEX CCI_FactSales
ON dbo.FactSales
WITH (MAXDOP = 8);

-- Point-lookup path for a narrow lookup pattern
CREATE NONCLUSTERED INDEX IX_FactSales_CustomerKey
ON dbo.FactSales (customer_key)
INCLUDE (sale_date, total_amount);

-- Materialized view for a recurring aggregation
CREATE MATERIALIZED VIEW MV_DailySalesSummary
WITH (DISTRIBUTION = HASH(sale_date))
AS
SELECT
    sale_date,
    COUNT_BIG(*) AS transaction_count,
    SUM(total_amount) AS daily_revenue
FROM dbo.FactSales
GROUP BY sale_date;

Columnstore is weak for very selective single-row lookups, which is where a narrow nonclustered index earns its maintenance cost. Apply the same reasoning to statistics: without up-to-date statistics the optimizer cannot estimate selectivity, and it will choose a plan that shuffles when a local join was available.

Session settings that change behaviour

A handful of SET options move the needle and cost nothing to try. Result set caching makes repeated identical queries return almost instantly. Statement-level degree of parallelism controls how aggressively a single query uses the node resources. Statistics profiling reveals where the optimizer's estimates diverged from reality.

SET RESULT_SET_CACHING ON;
SET STATISTICS PROFILE ON;
SET statement_dop = 4;
SET LOCK_TIMEOUT 5000;

-- Refresh statistics after a bulk load so estimates stay honest
UPDATE STATISTICS dbo.FactSales WITH FULLSCAN;

-- Verify cache behaviour for a dashboard query
SELECT TOP 100 * FROM dbo.vw_DailySalesSummary;

Use statement-level DOP rather than session-level wherever possible, so one heavy report cannot silently reshape every query for the connection. After a bulk load, recompiling the affected object is cheaper than waiting for statistics to be sampled during the first user query.

Partitioning and the loading path

Partitioning rarely speeds up a query on its own, but it dramatically reduces the work of maintenance operations. Most reporting filters carry a date, so partitioning a fact table by a date column lets a monthly archive or a partition switch touch a narrow slice instead of rewriting the whole table.

Choose the partition column from the filter that appears most often, and pick a granularity that makes each partition large enough to be worth managing. Daily partitions on a table that receives ten thousand rows a day produce an unmanageable number of tiny partitions, while yearly partitions on a high-volume feed leave partitions so large that archiving them is impractical.

The loading path matters just as much. A staging table distributed round robin accepts bulk loads efficiently, then a single redistribute step moves rows into the hashed fact table as part of the same transaction. This keeps the expensive data movement to one deliberate operation rather than scattering it across every insert.

Finally, remember that partition metadata, not just rows, consumes resources. Thousands of empty or near-empty partitions slow down metadata operations and complicate maintenance scripts, so review partition counts quarterly and merge slices that are no longer queried individually.

Document the distribution and partitioning decisions next to the table definition. When a new report arrives with a different join pattern, that note is what lets you tell a deliberate design choice from an accident, and it saves the next engineer an afternoon of reverse engineering.

Reading where time actually goes

The query plan tells you whether the cost is data movement, a partition scan, or a spilled sort. Distributed moves, shuffles and broadcasts, are the signature of a distribution mismatch; spills indicate that memory granted was insufficient for the working set.

Plan symptomLikely causeFirst fix
Large shuffle on a joinDistribution keys do not matchAlign hash keys or replicate the dimension
Broadcast of a large tableReplicated table exceeds size guidanceConvert to hash distribution
Partition scan despite a filterPartition column mismatchPartition by the filter column
Sort spill to diskMemory grant too small for row widthReduce row width or raise DOP carefully
Long parse and compileStale statisticsUpdate statistics and recompile

Work in that order. Fixing distribution first often removes the need for the other adjustments, while tuning caching on top of a shuffling query only changes how fast the shuffle runs.

Common Mistakes

Hash distributing on a low-cardinality column

Fix: Pick a high-cardinality key used in joins, or use round robin for pure staging tables.

Replicating a dimension far larger than 2 GB

Fix: Switch it to hash distribution so the broadcast stops saturating node memory.

Creating columnstore indexes and never refreshing statistics

Fix: Update statistics after bulk loads and recompile so the optimizer sees current selectivity.

Tuning session settings without reading the plan first

Fix: Identify whether data movement or spills dominate, then choose settings that address that cause.

Best Practices

  • Decide distribution during table design, not after a slow report appears
  • Run DBCC PDW_SHOWSPACEUSED after every large load
  • Replicate small dimensions, hash large facts on the join key
  • Check spilled_thread_count when queries exceed their memory grant
  • Revisit distribution keys whenever the dominant join pattern changes

Questions interviewers ask about Synapse performance

đŸŽ¯Interview Tip

Skew is the question that separates candidates who have operated a pool from those who have only read about it. Describe the command you would run, the ratio you would treat as suspicious, and the change you would make, rather than giving a generic answer about indexes.

Interview Questions

Q1: How do you identify and fix data skew?

Run DBCC PDW_SHOWSPACEUSED and compare row counts per distribution. A distribution holding several times the average indicates skew. Fix it by changing the hash key to a higher-cardinality column, or by using round robin for a table that does not participate in keyed joins.

Q2: Clustered columnstore versus clustered index?

Columnstore suits analytical scans and aggregations, offering high compression and batch mode. A B-tree clustered index suits point lookups and narrow range scans. Use columnstore on fact tables and narrow indexes only where a specific lookup pattern justifies them.

Q3: When would you use a replicated table?

For small dimension tables, typically under about 2 GB, that are joined to large facts. Every distribution holds a full copy, so the join is local and no shuffle occurs. Above that size the memory cost outweighs the saved data movement.

Q4: How does result set caching help?

Identical query text and structure return a cached result instead of re-executing, which benefits dashboards that refresh frequently. It depends on the query being deterministic, so time-dependent or parameterized expressions that change will not hit the cache.

Key Takeaways

  • Distribution is the first lever, indexing the second
  • Skew makes the slowest distribution the pace for every operation
  • Replicate small dimensions, hash large facts on real join keys
  • Statistics and columnstore work together, not instead of each other
  • Shuffles in the plan point to distribution, spills point to memory
  • Recompile after bulk loads so the first user query gets a fair plan
🔒

Premium Content

Synapse SQL Pool Tuning: Distribution to Caching

You've previewed the first section. Unlock this full lesson and 900+ advanced tutorials with a Premium plan.

đŸŽ¯End-to-end Projects
đŸ’ŧInterview Prep
📜Certificates
🤝Community Access

Already a member? Log in

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-12

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Advertisement