Teradata Architecture and Its Implications

Parallel Processing Model

Teradata's architecture is built on AMP (Access Module Processor) units, each responsible for a portion of the data. A misconfigured primary index or non-uniform data distribution can lead to skew, where a few AMPs handle most of the workload while others remain underutilized.

Key Architectural Challenges

  • Skewed Joins: Poorly distributed join columns can result in severe AMP workload imbalance.
  • Spool Space Errors: Temporary tables exceeding available spool can terminate sessions.
  • Incorrect Stats: Stale or missing statistics lead to suboptimal query plans.

Common Issues and Root Causes

1. High AMP Skew

Occurs when data is unevenly distributed across AMPs. A tell-tale sign is one AMP doing most of the work while others are idle.

SELECT AMP, COUNT(*) FROM dbc.tablesize GROUP BY 1;

2. Excessive Spool Usage

Temporary tables or intermediate query results can consume all available spool space, especially during complex joins or aggregations.

SELECT username, spool FROM dbc.diskspace WHERE spool > 100000000;

3. Long-Running Queries

These often result from full table scans, bad join orders, or insufficient indexing. They need to be profiled using query plans and DBQL.

Diagnostics and Profiling

Using EXPLAIN and Visual Explain

Always begin with EXPLAIN to review the execution plan. Look for keywords like "Product Join" or "Duplication of rows" which signal inefficiencies.

Enabling DBQL (Database Query Logging)

DBQL logs provide insight into resource usage, skew, query text, and execution steps.

BEGIN LOGGING ON EACH TABLE; -- Enable query logging
SELECT * FROM dbc.qrylog; -- Analyze logs
END LOGGING ON EACH TABLE;

Detecting Skewed Steps

Use dbc.qrylogsteps to identify which execution steps are causing skew or long delays.

Step-by-Step Fixes

Step 1: Analyze and Adjust Primary Indexes

Ensure high-cardinality and frequently-joined columns are used as primary indexes to reduce skew and improve join performance.

HELP INDEX your_table_name;

Step 2: Update and Collect Statistics

Regularly collect stats on join columns, WHERE clause columns, and large tables to ensure the optimizer has accurate information.

COLLECT STATISTICS ON your_table COLUMN your_column;

Step 3: Refactor Inefficient Queries

Break large queries into smaller subqueries. Avoid product joins unless necessary and use hash joins for better performance.

Step 4: Increase Spool Space or Refactor Usage

Request increased spool for resource-heavy users or optimize queries to minimize intermediate results.

Step 5: Implement Workload Management

Use Teradata's TASM (Teradata Active System Management) to assign resource groups and limit runaway queries.

Best Practices for Stability and Performance

  • Use high-cardinality columns as primary indexes.
  • Regularly collect and refresh statistics on large tables.
  • Avoid SELECT * in production queries.
  • Review execution plans regularly using EXPLAIN or Visual Explain.
  • Set up proactive alerting on spool space and AMP usage.

Conclusion

Teradata troubleshooting goes beyond just tuning SQL—it requires a holistic understanding of its parallel architecture, indexing strategies, and system resource constraints. DBAs and architects must proactively monitor system metrics, enforce query standards, and apply architecture-aware fixes. With the right diagnostics and preventative strategies, Teradata can deliver the high performance it's known for—even at petabyte scale.

FAQs

1. What causes AMP skew and how can it be avoided?

AMP skew occurs when data is not evenly distributed, usually due to low-cardinality or poorly chosen primary indexes. Use high-cardinality columns and analyze AMP usage metrics regularly.

2. How often should statistics be collected in Teradata?

It depends on data volatility, but a good baseline is weekly for large tables or after major data loads.

3. What is the best way to identify resource-heavy queries?

Use DBQL logging and monitor tables like dbc.qrylog and dbc.qrylogsteps to track long-running or skewed queries.

4. Can spool space be permanently increased for a user?

Yes, administrators can increase the spool space allocation per user via MODIFY USER command.

5. How does TASM help with query performance?

TASM allows administrators to classify queries by priority, throttle resource usage, and prevent low-priority queries from overwhelming the system.