Lightning-fast queries thanks to Teradata Sparse Maps

DWH Pro Admin

June 14, 2022

minutes reading time


Introduction to Teradata Sparse Maps

The Teradata hashing architecture and how AMPs are used to split tables for maximum parallelism evenly have been unchanged since the beginning. What is new is the ability to create your hash maps. Hash maps, as we usually know them, are also called contiguous maps. If you are not familiar with the details of how Teradata distributes the rows of tables, I recommend you read this article first and then come back:

Relatively new is the concept of Teradata sparse maps. They are used when we do not want to distribute our table over all AMPs. Unlike contiguous maps, sparse maps can be created by us almost arbitrarily. The goal of sparse maps is to keep tables on one or a few AMPs:

Lightning-fast queries thanks to Teradata Sparse Maps 1
One AMP Sparse Map

Sparse maps exist within a contiguous map. Teradata comes with two predefined sparse maps:

  • Single AMP Sparse Map
  • Sparse map with one AMP per Node

When should we use sparse maps?

Teradata sparse maps are used with small tables to prevent all-AMP access. Besides the better efficiency, this can also avoid waiting on a skewed system because of the all-AMP step, although Teradata should read-only rows of one or a few AMPs because all-AMP access also means that we have to wait for the slowest AMP. Sparse maps allow the optimizer to perform single-AMP operations with advantages such as fewer IOs, less vulnerability for congestion, etc.

We can therefore expect more stable response times. As you may have noticed, spare maps are especially suitable for tactical workloads due to the abovementioned properties. Single-AMP sparse maps allow the optimizer to prioritize our queries as a tactical workload. If you are interested in tactical workload tuning, I can recommend this article:

Teradata sparse maps are ideal for small tables. Especially if they have fewer rows than the system has AMPs. Using sparse maps for tiny tables also minimizes the risk of skewed dynamic AMP samples. In general, small tables we query frequently are good candidates.

How are tables distributed inside the sparse map?

Unlike contiguous maps, the rows of different tables within a single-AMP sparse map are not all mapped to the same AMP. This would also overload this AMP. Instead, Teradata decides for each table on which AMP Teradata will manage it. The tables are distributed evenly across all nodes on the AMPs. The sparse map does not assign all rows to one AMP. Here the whole is graphically represented. There are three tables (each shown in a different color) held on three AMPs:

Teradata sparse maps
Single AMP Sparse Map with three tables

The presented design and the automatic distribution of small tables to different AMPs have advantages in even workload distribution. But there are also disadvantages that we have to consider—the main disadvantage. Even though two tables are in the same single-AMP sparse map can’t be AMP joined locally because the tables are on different AMPs. With contiguous maps, this is possible without any problems. The same map means that the rows of a table joined via the primary index are on the same AMP. However, Teradata offers the possibility to force different tables to the same AMP(s) when creating a table by using the so-called colocation name (MAP = MySingleAMPMap COLLOCATE USING my_colocation_name)

As we have seen, sparse maps are an essential tool to improve the performance of small tables. Predominantly tactical workloads can benefit considerably from them. Teradata provides automated capabilities in Viewpoint to find small tables and automatically switch to a sparse map. Teradata considers tables to be small if they are smaller than 128 kilobytes.

Can I use Teradata Sparse Maps for big tables?

There are some possibilities to use sparse maps also for large tables. In the following article, you will learn how this is possible, but we will also show you alternatives to sparse maps (e.g., if you are on an older Teradata system where this feature is not yet available):

Finally, I would like to refer you here to an article about tactical workload because that is where sparse maps are predominantly needed:

Teradata Docs: Sparse Maps

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

You might also like

>