Understanding Teradata's Architecture

AMPs and Data Distribution

Teradata relies on a shared-nothing architecture where data is evenly distributed across AMPs. A hashing algorithm assigns rows to AMPs based on the Primary Index (PI). Ideally, uniform distribution ensures parallel query execution. However, poorly chosen PIs or data anomalies can lead to skew, where one or more AMPs handle disproportionate data volumes.

Why Skew Matters in Enterprise Systems

In high-throughput environments, AMP skew leads to:

  • Degraded query performance due to bottlenecks
  • Overutilization of specific AMPs and underutilization of others
  • Unpredictable resource allocation, impacting SLAs and workload management

Diagnosing AMP Skew

Using Teradata Viewpoint and DBQL

Viewpoint provides AMP-level performance graphs, highlighting response time deviations. Additionally, DBQL (Database Query Log) helps detect queries contributing to skew.

-- Identify skewed queries
SELECT QueryID, TotalFirstRespTime, (MaxAmpCPUTime / TotalAmpCPUTime) * 100 AS SkewPercent
FROM DBC.DBQLogTbl_Hst
WHERE TotalAmpCPUTime > 0
AND TotalFirstRespTime > 1
ORDER BY SkewPercent DESC;

Manual Skew Detection

Use the following SQL to analyze table skew at rest:

-- Check table distribution
SELECT HashAMP(HASHBUCKET(HASHROW(PrimaryIndexCol))), COUNT(*)
FROM YourDB.YourTable
GROUP BY 1
ORDER BY 2 DESC;

Common Pitfalls Causing AMP Skew

1. Poor Primary Index Choice

A non-unique or low-cardinality PI can funnel records into a few AMPs. For example, using a status flag or date field as PI leads to poor distribution.

2. Data Anomalies

Even a good PI can skew if incoming data is imbalanced. A recent batch load with concentrated PI values can break distribution.

3. Spool Skew During Joins

Improper join strategies cause spool files to concentrate on a few AMPs. Nested joins with mismatched join columns exacerbate this issue.

Step-by-Step Remediation

1. Reevaluate the Primary Index

Choose a PI with high cardinality and even distribution. For example, use surrogate keys or composite fields.

-- Create table with better PI
CREATE TABLE YourDB.OptimizedTable (
 ID INT, DateCol DATE, ...
)
PRIMARY INDEX (ID);

2. Collect and Refresh Statistics

Ensure statistics are up to date on PIs and join columns. Skew can worsen without statistics guiding the optimizer.

-- Refresh stats
COLLECT STATISTICS ON YourDB.YourTable COLUMN (YourPICol);

3. Apply Partitioned Primary Index (PPI)

Use PPIs to separate data by logical partitions (e.g., by date), reducing the impact of PI imbalance.

-- Example PPI
CREATE TABLE YourDB.PPI_Table (ID INT, EventDate DATE, ...)
PRIMARY INDEX (ID)
PARTITION BY RANGE_N(EventDate BETWEEN DATE '2023-01-01' AND DATE '2025-01-01' EACH INTERVAL '1' MONTH);

4. Optimize Join Strategies

Force joins to use hash redistribution or replicated joins to balance execution across AMPs.

-- Use EXPLAIN to check join plan
EXPLAIN
SELECT * FROM A JOIN B ON A.ID = B.ID;

5. Analyze and Tune ETL Loads

Distribute ETL loads in a balanced manner. Pre-sorting or hashing during staging can preempt skew before data reaches Teradata.

Best Practices for Preventing Skew

  • Design Primary Indexes based on access pattern and cardinality
  • Regularly monitor AMP usage via Viewpoint
  • Automate stats collection as part of the ETL pipeline
  • Isolate heavy queries in workload groups using TASM (Teradata Active System Management)
  • Perform routine validation of table distribution post-load

Conclusion

AMP skew in Teradata is a silent but critical performance challenge in enterprise data environments. Through diligent index selection, proactive monitoring, and tactical optimization of joins and loads, organizations can maintain the efficiency and reliability expected from Teradata. Understanding skew not only resolves short-term issues but also future-proofs performance scalability.

FAQs

1. How do I know if a query is experiencing AMP skew?

High disparity in AMP CPU or I/O usage in DBQL or Viewpoint charts is a key indicator of skew. Queries with high SkewPercent should be investigated.

2. Is skew always caused by bad Primary Indexes?

No. While PI choice is critical, skew can also arise from transient data anomalies, poor statistics, or inefficient joins during query execution.

3. Can Partitioned Primary Indexes fully eliminate skew?

PPIs help isolate skew within partitions but do not guarantee uniformity. They should be used in conjunction with good PI design.

4. Does collecting stats frequently impact performance?

Collecting stats has minimal overhead if done incrementally. Automating it as part of ETL is a best practice to maintain optimizer accuracy.

5. How can I simulate AMP skew for testing?

Create test tables with imbalanced PI values and observe AMP utilization. This helps validate that monitoring tools and alerts are configured correctly.