Optimizing Teradata Queries: From No Index to Hashed NUSI

tune3

The initial situation without any index In this blog, I will demonstrate how to optimize a query using Teradata’s tools. We will begin with the following test scenario: The data is evenly distributed. To demonstrate the query’s selectivity for the tested indexes we will define later, I assigned a significant portion of rows the same …

Read more

Understanding Teradata’s Primary AMP Index for Improved Performance

tune4

Experienced Teradata users are familiar with the concept of a primary index. However, a new term has surfaced with the introduction of Teradata Release 15: Primary AMP Index. This blog post will demonstrate a Primary AMP Index’s benefits and optimal usage for improving load and query performance. First, let us examine Teradata’s approaches over the …

Read more

Optimize Teradata UNION ALL with a Single Table Scan Trick

tune1

The Idea Behind This Trick for Teradata UNION ALL What if you need to apply a UNION ALL operation to distinct columns within a single table? Typically, the process would involve: The drawback of this method is that it scans the Customer table twice. To achieve the same output with just one full table scan, …

Read more

Teradata Access Paths: 8 Essential Ones to Know

tune1

The optimizer has various access paths to consider when creating the execution plan, each with unique advantages and disadvantages. This article will introduce the 8 most essential access paths. The lack of a hash index may surprise you; however, Teradata has entirely substituted it with the single-table join index and discourages its utilization in the …

Read more

Teradata Sample Statistics: When, How, and Why to Use Them

tune1

Introduction to Teradata Sample Statistics Discover the optimal utilization of Teradata Sample Statistics, including when, how, and why to implement them. Sample statistics require columns with a high degree of diversity in values. A UPI satisfies this criterion, and only columns with numerous unique values should be considered for collecting sample statistics for the NUPI. …

Read more

Maximizing Performance with Multiple Teradata Sessions

tune2

Teradata Sessions explained in a few Sentences Example 1: Multiple Sessions which do not improve performance The graph shows that all four transactions (T1, T2, T3, T4) are concurrently active on all AMPs. Even for a single-row lookup, these transactions necessitate accessing all AMPs. None of the transactions use a single rowhash for access, resulting …

Read more

Optimizing Teradata Requests with Group-AMP Operations for Improved Performance

tune4

All-AMP and single-AMP operations are well-understood. All-AMP retrieval typically involves full table scans, including NUSI sub-table scans. On the other hand, single-AMP retrieval typically involves indexed access, such as UPI and NUPI. Group-AMP operations optimize requests by minimizing the number of active AMPs. These operations fall between single-AMP and all-AMP operations. The Optimizer employs group-AMP …

Read more

Learn Teradata Indexing Techniques in this 2-Hour Video Course

tune2

Introduction

Teradata SQL lacks a built-in function to determine the ASCII code of a character. But fear not, for there exists a query workaround to this dilemma. This blog post will guide you through the process of using a straightforward SQL query in Teradata to find the ASCII code of a character.

The solution is as follows:

We use the Teradata SQL function CHAR2HEXINT to obtain a hexadecimal value for a character. Our objective is to convert this hexadecimal value to its decimal counterpart, which signifies the character’s ASCII code.

This SQL query accomplishes the task.

SELECT
CASE SUBSTRING(CHAR2HEXINT('B') FROM 3 FOR 1)
WHEN '0' THEN 0
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN '4' THEN 4
WHEN '5' THEN 5
WHEN '6' THEN 6
WHEN '7' THEN 7
WHEN '8' THEN 8
WHEN '9' THEN 9
WHEN 'A' THEN 10
WHEN 'B' THEN 11
WHEN 'C' THEN 12
WHEN 'D' THEN 13
WHEN 'E' THEN 14
WHEN 'F' THEN 15
END * 16 +
CASE SUBSTRING(CHAR2HEXINT('B') FROM 4 FOR 1)
WHEN '0' THEN 0
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN '4' THEN 4
WHEN '5' THEN 5
WHEN '6' THEN 6
WHEN '7' THEN 7
WHEN '8' THEN 8
WHEN '9' THEN 9
WHEN 'A' THEN 10
WHEN 'B' THEN 11
WHEN 'C' THEN 12
WHEN 'D' THEN 13
WHEN 'E' THEN 14
WHEN 'F' THEN 15
END

Using a CASE statement, the query extracts two hexadecimal digits with the SUBSTRING function and converts them to decimal values. It then calculates the character’s ASCII code by multiplying the first digit’s decimal value by 16 and adding the second digit’s decimal value.

Conclusion

Teradata SQL lacks a dedicated feature for determining the ASCII code of a given character. However, this blog post offers a straightforward and efficient workaround for this issue. By utilizing the CHAR2HEXINT function and performing basic arithmetic operations, you can effectively determine the ASCII code of any character within your Teradata SQL queries.

Is Teradata Compression Worth Your Time and Effort?

tune3

Teradata DBMS offers various compression options to save disk space and improve performance. But, the cost of implementing the compression takes man-time. This article discusses the cost vs. benefit of compression and suggests carefully considering the compression setting when designing new or modifying existing tables.

Teradata SQL Tuning: How to Optimize Queries for Stable Runtimes

sql1

Learn how to optimize Teradata SQL Tuning with comprehensive analysis of available tools in this article. Discover the optimal approach for query optimization for both tactical and strategic workloads, as well as methods for eliminating full table scans, reducing skew, and examining the execution plan. Plus, find out how to address common issues like concurrency and misestimation.

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.