Optimal Performance by Avoiding CHARACTER Columns in the Primary Index

The Teradata Primary Index and Hash Collisions

Using either INTEGER or CHARACTER data types for the Teradata Primary Index does not usually impact performance. The hashing algorithm in Teradata is highly efficient. In the rare case where primary index columns from different tables have different CHARACTER SET, there may be minimal performance losses, but this is insignificant.

This article addresses a performance issue with CHARACTER columns in the primary index. Although not as apparent as skew, this problem is often overlooked and remains hidden.

Assuming a Teradata system with 160 AMPs and 20-bit hash buckets, we create a table with a primary index of a CHARACTER(8) column that contains 100 million phone numbers. The 20-bit hash buckets allow for 1,048,576 unique hash buckets. The hashing algorithm is expected to provide:

  • Each hash bucket is used approx. 95 times
  • Each AMP receives approx. 625,000 rows
  • Minimal to no hash collisions, as billions of different hash values can be generated

We computed the DSW, AMP, and collision count for every possible input value.

The chart displays the quantity of hash buckets (y-axis) produced by the frequency generation of the primary index column utilizing strings (x-axis). An ideal distribution would exhibit an impulse function with 1,048,576 counts focused on 95. Our test results show a distribution still centered on 95, but resembling a bell curve with a peak of approximately 43,000 counts, a mere 25% of the expected value. The frequency of certain buckets is significantly lower, with one bucket only occurring 50 times and another 51 times. The majority of buckets fall within the range of 120 to 150 occurrences.

teradata primary index

Upon closer examination, it becomes evident that the equitable allocation of rows across the AMPs is not the underlying issue. Each AMP receives an almost identical number of rows, ranging from 623,000 to 627,000. Rather, the problem lies in generating hash collisions on all AMPs, as demonstrated in the subsequent graph.

teradata hash collisions

The algorithm produced around 15,000 hash collisions per 160 AMPS. Most of these collisions result from three or four primary index values being linked to the same hash value. This is concerning, as hash collisions have a negative impact on performance.

Let’s revisit the scenario, but this time, we store the phone numbers in a BIGINT column and employ it as the Teradata Primary Index. We create a table containing 100 million rows. The resulting graph corresponds to our expectations for the CHARACTER column.

teradata primary index

The graph is now a precise impulse function, with values ranging exclusively from 93 to 98. Each AMP is allocated 625,000 rows, with a minimum fluctuation of ±280. Most importantly, there are currently no duplicate hashes.

Summary

Using CHARACTER columns in the primary index may result in numerous hash collisions. While the contents of such columns are usually limited, this may not be a concern. Nevertheless, significant performance issues may arise in exceptional scenarios where millions of distinct values are present in the primary index column.

To prevent confusion, it is worth noting that implementing CHARACTER columns in the primary index is usually not detrimental. Retrieval, joining, and aggregating are ordinarily not impacted. The situation demonstrated in this test scenario involves storing numerous (millions) diverse values in a CHARACTER column, which only results in an immense amount of hash collisions in this circumstance. Therefore, it is advised not to overhaul the PDM presently but to remain vigilant for these kinds of cases.

This article will illustrate additional factors to consider when selecting the Primary Index for optimal performance.

Related Services

⚡ Need Help Optimizing Your Data Platform?

We cut data platform costs by 30–60% without hardware changes. 25+ years of hands-on tuning experience.

Explore Our Services →

📋 Considering a Move From Teradata?

Get a personalized migration roadmap in 2 minutes. We have migrated billions of rows from Teradata to Snowflake, Databricks, and more.

Free Migration Assessment →

📊 Data Platform Migration Survey

Help us map where the industry is heading. Results are public — see what others chose.

1. What is your current data platform?

2. Where are you migrating to (or evaluating)?

Migrating FROM
Migrating TO

Thanks for voting! Share this with your network.

Follow me on LinkedIn for daily insights on data warehousing and platform migrations.

Stay Ahead in Data Warehousing

Get expert insights on Teradata, Snowflake, BigQuery, Databricks, Microsoft Fabric, and modern data architecture — delivered to your inbox.

Leave a Comment

DWHPro

Expert network for enterprise data platforms. Senior consultants, project teams built for your challenge — across Teradata, Snowflake, Databricks, and more.

📍Vienna, Austria & Jacksonville, Florida

Quick Links
Services Team Teradata Book Blog Contact Us
Connect
LinkedIn → [email protected]
Newsletter

Join 4,000+ data professionals.
Weekly insights on Teradata, Snowflake & data architecture.