SlideShare a Scribd company logo
Teradata Pro 
Teradata | Data Warehouse Consulting Companies | 
Data Warehouse Vendors | Teradata SQL 
http://www.teradatapro.com 
6 Golden Rules for Teradata SQL Tuning 
Author : Roland Wenzlofsky 
Date : October 29, 2014 
Teradata SQL Tuning Evergreens 
1. 
Ensure completeness and correctness of Teradata Statistics 
This is what I always teach in my performance Teradata SQL tuning workshops without ever 
disappointing my clients: 
The most important optimization task is to ensure statistic completeness and correctness. This 
is valid for statistics on all database objects, not only for tables (secondary indexes, join 
indexes). 
Detecting missing statistics is easier than you may expect, in your SQL assistant run the 
command: 
DIAGNOSTIC HELPSTATS ON FOR SESSION; 
and EXPLAIN your SQL statement. At the end of the explain output a list of statistics will be 
added which the optimizer would consider helpful in creating a better execution plan. Add them 
1 / 4
Teradata Pro 
Teradata | Data Warehouse Consulting Companies | 
Data Warehouse Vendors | Teradata SQL 
http://www.teradatapro.com 
one by one and re-check the execution plan. 
To detect stale statistics, there are several methods available. Maybe the easiest way is to split 
your SQL statement into parts and test each of them by comparing the estimated row count 
statistics (which the explain output shows you) with the real number of records returned. This 
approach makes especially sense if the SQL statement which has to be optimized is not 
runnable in a moderate time. Here is one example: 
SELECT t01.* 
FROM 
table_1 t01 
INNER JOIN 
table_2 t02 
ON 
t01.PK = t02.PK 
WHERE 
t01.column_1 = 1 
AND t02.column_a = 2 
; 
Above query can be split into two parts for testing: 
SELECT * FROM table_1 WHERE column_1 = 1; 
and 
SELECT * FROM table_2 WHERE column_a = 2; 
Execute and Explain both queries and compare the number of returned rows against the 
number of rows the explain output shows you. 
If there is a big difference, it could be related to stale statistics or similar problems related with 
the data distribution. 
2. 
The Primary Index (PI) Choice 
Use primary indexes for joins whenever possible, and specify in the where clause all the 
columns for the primary indexes. Joining on the complete set of primary index columns is the 
least resource intense join possibility. 
If your environment does not allow you to adjust primary indexes to suit your requirements or 
you would need a different primary index only for optimizing certain SQL statements, you should 
think about re-indexing the involved tables by using volatile tables or real temporary tables. 
2 / 4
Teradata Pro 
Teradata | Data Warehouse Consulting Companies | 
Data Warehouse Vendors | Teradata SQL 
http://www.teradatapro.com 
3. 
Teradata Indexing Techniques 
Using Teradata Indexing Techniques may be another option to improve your SQL statement. 
For example, secondary indexes could be especially helpful if you have highly selective 
WHERE conditions. 
You could try as well join indexes or even work with partitioning. 
Whenever working with indexing techniques you have to keep the overall data warehouse 
architecture in mind and how your solution fits into this architecture. 
If the identified indexes are not used by the optimizer and are not useful in the overall PDM 
design, drop them again immediately. 
4. 
Query Rewriting 
Many times, queries performance can be improved by rewriting the query in different way. 
Examples like using DISTINCT instead of GROUP BY on columns with many different values 
come to my mind. 
Union could be used to break up a large SQL statements into several smaller ones, which may 
be executed in parallel. 
While query rewriting may be very powerful in your query optimization toolkit, it may require to 
understand the business logic behind (“can this left join be replaced by an inner join?”) 
5. 
Real Time Monitoring 
Watch your query running in real-time. Observing your query while its running in Viewpoint or 
PMON, helps you to find out the critical steps of your query. 
Most performance issues are caused either by query steps with heavy skewing in the AMP’s or 
by a wrong execution plan caused by stale and missing statistics. 
Stale and missing statistics typically lead to wrong decisions in join preparation (copying a table 
to all AMP’s instead of rehashing) and join types used (product join instead of merge join). 
3 / 4
Teradata Pro 
Teradata | Data Warehouse Consulting Companies | 
Data Warehouse Vendors | Teradata SQL 
http://www.teradatapro.com 
6. 
Comparison of Resource Usage 
Another very important task in performance optimization is to measure the resources used 
before and after the optimization. Plain query run times can be misleading as they heavily 
depend on the current load on the Teradata Server and workload management blocking you 
may not even notice. 
Here is one example query which only needs the DBC.DBQLOGTBL table. Set a different 
QUERYBAND for each version of the query you are running: 
SET QUERY_BAND = 'Version=1;' FOR SESSION; 
SELECT 
AMPCPUTIME, 
(FIRSTRESPTIME-STARTTIME DAY(2) TO SECOND(6)) RUNTIME, 
SPOOLUSAGE/1024**3 AS SPOOL_IN_GB, 
CAST(100-((AMPCPUTIME/(HASHAMP()+1))*100/NULLIFZERO(MAXAMPCPUTIME)) AS 
INTEGER) AS CPU_SKEW, 
MAXAMPCPUTIME*(HASHAMP()+1) AS CPU_IMPACT, 
AMPCPUTIME*1000/NULLIFZERO(TOTALIOCOUNT) AS LHR 
FROM 
DBC.DBQLOGTBL 
WHERE 
QUERYBAND = 'Version=1;' 
Above query gives you detailed insight about how good or bad each step of your query is: 
The total CPU Usage 
The Spool Space needed 
The LHR (ratio between CPU and IO usage) 
The CPU Skew 
The Skew Impact on the CPU 
Goal is to reduce total CPU usage, consumed spool space and Skew impact on the CPU. 
Further, the LHR is optimally around 1.00 
Powered by TCPDF (www.tcpdf.org) 
4 / 4
Ad

More Related Content

What's hot (20)

MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTUREMS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
 
Low level design template (1)
Low level design template (1)Low level design template (1)
Low level design template (1)
anosha jamshed
 
Concurrent Processing Performance Analysis for Apps DBAs
Concurrent Processing Performance Analysis for Apps DBAsConcurrent Processing Performance Analysis for Apps DBAs
Concurrent Processing Performance Analysis for Apps DBAs
Maris Elsins
 
NEW TOP FEATURES COMING TO SALESFORCE RELEASE WINTER 23 RELEASE BY NBSCONSULTING
NEW TOP FEATURES COMING TO SALESFORCE RELEASE WINTER 23 RELEASE BY NBSCONSULTINGNEW TOP FEATURES COMING TO SALESFORCE RELEASE WINTER 23 RELEASE BY NBSCONSULTING
NEW TOP FEATURES COMING TO SALESFORCE RELEASE WINTER 23 RELEASE BY NBSCONSULTING
NBSConsulting
 
Oracle report from ppt
Oracle report from pptOracle report from ppt
Oracle report from ppt
kingshuk_goswami
 
Oracle APEX, Low Code for Data Driving Apps
Oracle APEX, Low Code for Data Driving AppsOracle APEX, Low Code for Data Driving Apps
Oracle APEX, Low Code for Data Driving Apps
Franco Ucci
 
Oracle Applications R12 Architecture
Oracle Applications R12 ArchitectureOracle Applications R12 Architecture
Oracle Applications R12 Architecture
Viveka Solutions
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
Tom Kocjan
 
Oracle Apps - Forms
Oracle Apps - FormsOracle Apps - Forms
Oracle Apps - Forms
Bhaskara Reddy Sannapureddy
 
Sre summary
Sre summarySre summary
Sre summary
Yogesh Shah
 
Kata: Hexagonal Architecture / Ports and Adapters
Kata: Hexagonal Architecture / Ports and AdaptersKata: Hexagonal Architecture / Ports and Adapters
Kata: Hexagonal Architecture / Ports and Adapters
holsky
 
Oracle E-Business Suite 12.2 - The Upgrade to End All Upgrades
Oracle E-Business Suite 12.2 - The Upgrade to End All UpgradesOracle E-Business Suite 12.2 - The Upgrade to End All Upgrades
Oracle E-Business Suite 12.2 - The Upgrade to End All Upgrades
Shiri Amit
 
How to create generic delta
How to create generic deltaHow to create generic delta
How to create generic delta
Jacques Kalees
 
Oracle Database Introduction
Oracle Database IntroductionOracle Database Introduction
Oracle Database Introduction
Chhom Karath
 
Oracle db architecture
Oracle db architectureOracle db architecture
Oracle db architecture
Simon Huang
 
Make Your Application “Oracle RAC Ready” & Test For It
Make Your Application “Oracle RAC Ready” & Test For ItMake Your Application “Oracle RAC Ready” & Test For It
Make Your Application “Oracle RAC Ready” & Test For It
Markus Michalewicz
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
ESUG
 
FMI Open Data Interface and Usage
FMI Open Data Interface and UsageFMI Open Data Interface and Usage
FMI Open Data Interface and Usage
Roope Tervo
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning Concept
Chien Chung Shen
 
Complex Event Flows in Distributed Systems (Bernd Ruecker, Camunda) Kafka Sum...
Complex Event Flows in Distributed Systems (Bernd Ruecker, Camunda) Kafka Sum...Complex Event Flows in Distributed Systems (Bernd Ruecker, Camunda) Kafka Sum...
Complex Event Flows in Distributed Systems (Bernd Ruecker, Camunda) Kafka Sum...
confluent
 
Low level design template (1)
Low level design template (1)Low level design template (1)
Low level design template (1)
anosha jamshed
 
Concurrent Processing Performance Analysis for Apps DBAs
Concurrent Processing Performance Analysis for Apps DBAsConcurrent Processing Performance Analysis for Apps DBAs
Concurrent Processing Performance Analysis for Apps DBAs
Maris Elsins
 
NEW TOP FEATURES COMING TO SALESFORCE RELEASE WINTER 23 RELEASE BY NBSCONSULTING
NEW TOP FEATURES COMING TO SALESFORCE RELEASE WINTER 23 RELEASE BY NBSCONSULTINGNEW TOP FEATURES COMING TO SALESFORCE RELEASE WINTER 23 RELEASE BY NBSCONSULTING
NEW TOP FEATURES COMING TO SALESFORCE RELEASE WINTER 23 RELEASE BY NBSCONSULTING
NBSConsulting
 
Oracle APEX, Low Code for Data Driving Apps
Oracle APEX, Low Code for Data Driving AppsOracle APEX, Low Code for Data Driving Apps
Oracle APEX, Low Code for Data Driving Apps
Franco Ucci
 
Oracle Applications R12 Architecture
Oracle Applications R12 ArchitectureOracle Applications R12 Architecture
Oracle Applications R12 Architecture
Viveka Solutions
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
Tom Kocjan
 
Kata: Hexagonal Architecture / Ports and Adapters
Kata: Hexagonal Architecture / Ports and AdaptersKata: Hexagonal Architecture / Ports and Adapters
Kata: Hexagonal Architecture / Ports and Adapters
holsky
 
Oracle E-Business Suite 12.2 - The Upgrade to End All Upgrades
Oracle E-Business Suite 12.2 - The Upgrade to End All UpgradesOracle E-Business Suite 12.2 - The Upgrade to End All Upgrades
Oracle E-Business Suite 12.2 - The Upgrade to End All Upgrades
Shiri Amit
 
How to create generic delta
How to create generic deltaHow to create generic delta
How to create generic delta
Jacques Kalees
 
Oracle Database Introduction
Oracle Database IntroductionOracle Database Introduction
Oracle Database Introduction
Chhom Karath
 
Oracle db architecture
Oracle db architectureOracle db architecture
Oracle db architecture
Simon Huang
 
Make Your Application “Oracle RAC Ready” & Test For It
Make Your Application “Oracle RAC Ready” & Test For ItMake Your Application “Oracle RAC Ready” & Test For It
Make Your Application “Oracle RAC Ready” & Test For It
Markus Michalewicz
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
ESUG
 
FMI Open Data Interface and Usage
FMI Open Data Interface and UsageFMI Open Data Interface and Usage
FMI Open Data Interface and Usage
Roope Tervo
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning Concept
Chien Chung Shen
 
Complex Event Flows in Distributed Systems (Bernd Ruecker, Camunda) Kafka Sum...
Complex Event Flows in Distributed Systems (Bernd Ruecker, Camunda) Kafka Sum...Complex Event Flows in Distributed Systems (Bernd Ruecker, Camunda) Kafka Sum...
Complex Event Flows in Distributed Systems (Bernd Ruecker, Camunda) Kafka Sum...
confluent
 

Viewers also liked (20)

ABC of Teradata System Performance Analysis
ABC of Teradata System Performance AnalysisABC of Teradata System Performance Analysis
ABC of Teradata System Performance Analysis
Shaheryar Iqbal
 
Teradata introduction - A basic introduction for Taradate system Architecture
Teradata introduction - A basic introduction for Taradate system ArchitectureTeradata introduction - A basic introduction for Taradate system Architecture
Teradata introduction - A basic introduction for Taradate system Architecture
Mohammad Tahoon
 
Introduction to Teradata And How Teradata Works
Introduction to Teradata And How Teradata WorksIntroduction to Teradata And How Teradata Works
Introduction to Teradata And How Teradata Works
BigClasses Com
 
Teradata introduction
Teradata introductionTeradata introduction
Teradata introduction
Rameejmd
 
Teradata 13.10
Teradata 13.10Teradata 13.10
Teradata 13.10
Teradata
 
Teradata memory management - A balancing act
Teradata memory management  -  A balancing actTeradata memory management  -  A balancing act
Teradata memory management - A balancing act
Shaheryar Iqbal
 
Understanding System Performance
Understanding System PerformanceUnderstanding System Performance
Understanding System Performance
Teradata
 
Teradata
TeradataTeradata
Teradata
Teja Bheemanapally
 
Teradata Big Data London Seminar
Teradata Big Data London SeminarTeradata Big Data London Seminar
Teradata Big Data London Seminar
Hortonworks
 
Teradata Aggregate Join Indices And Dimensional Models
Teradata Aggregate Join Indices And Dimensional ModelsTeradata Aggregate Join Indices And Dimensional Models
Teradata Aggregate Join Indices And Dimensional Models
pepeborja
 
Manuel del buen vivir
Manuel del buen vivirManuel del buen vivir
Manuel del buen vivir
Yazz K'brera
 
BIG DATA - TERADATA
BIG DATA - TERADATABIG DATA - TERADATA
BIG DATA - TERADATA
ibankuk
 
Teradata Overview
Teradata OverviewTeradata Overview
Teradata Overview
Teradata
 
Teradata Intelligent Memory
Teradata Intelligent MemoryTeradata Intelligent Memory
Teradata Intelligent Memory
inside-BigData.com
 
Teradata Architecture
Teradata Architecture Teradata Architecture
Teradata Architecture
BigClasses Com
 
Teradata - Presentation at Hortonworks Booth - Strata 2014
Teradata - Presentation at Hortonworks Booth - Strata 2014Teradata - Presentation at Hortonworks Booth - Strata 2014
Teradata - Presentation at Hortonworks Booth - Strata 2014
Hortonworks
 
Seminar Presentation on raspberry pi
Seminar Presentation on raspberry piSeminar Presentation on raspberry pi
Seminar Presentation on raspberry pi
Georgekutty Francis
 
Working with informtiaca teradata parallel transporter
Working with informtiaca teradata parallel transporterWorking with informtiaca teradata parallel transporter
Working with informtiaca teradata parallel transporter
Anjaneyulu Gunti
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi
praveen_23
 
RDBMS.ppt
RDBMS.pptRDBMS.ppt
RDBMS.ppt
Ketan Chaoji
 
ABC of Teradata System Performance Analysis
ABC of Teradata System Performance AnalysisABC of Teradata System Performance Analysis
ABC of Teradata System Performance Analysis
Shaheryar Iqbal
 
Teradata introduction - A basic introduction for Taradate system Architecture
Teradata introduction - A basic introduction for Taradate system ArchitectureTeradata introduction - A basic introduction for Taradate system Architecture
Teradata introduction - A basic introduction for Taradate system Architecture
Mohammad Tahoon
 
Introduction to Teradata And How Teradata Works
Introduction to Teradata And How Teradata WorksIntroduction to Teradata And How Teradata Works
Introduction to Teradata And How Teradata Works
BigClasses Com
 
Teradata introduction
Teradata introductionTeradata introduction
Teradata introduction
Rameejmd
 
Teradata 13.10
Teradata 13.10Teradata 13.10
Teradata 13.10
Teradata
 
Teradata memory management - A balancing act
Teradata memory management  -  A balancing actTeradata memory management  -  A balancing act
Teradata memory management - A balancing act
Shaheryar Iqbal
 
Understanding System Performance
Understanding System PerformanceUnderstanding System Performance
Understanding System Performance
Teradata
 
Teradata Big Data London Seminar
Teradata Big Data London SeminarTeradata Big Data London Seminar
Teradata Big Data London Seminar
Hortonworks
 
Teradata Aggregate Join Indices And Dimensional Models
Teradata Aggregate Join Indices And Dimensional ModelsTeradata Aggregate Join Indices And Dimensional Models
Teradata Aggregate Join Indices And Dimensional Models
pepeborja
 
Manuel del buen vivir
Manuel del buen vivirManuel del buen vivir
Manuel del buen vivir
Yazz K'brera
 
BIG DATA - TERADATA
BIG DATA - TERADATABIG DATA - TERADATA
BIG DATA - TERADATA
ibankuk
 
Teradata Overview
Teradata OverviewTeradata Overview
Teradata Overview
Teradata
 
Teradata Architecture
Teradata Architecture Teradata Architecture
Teradata Architecture
BigClasses Com
 
Teradata - Presentation at Hortonworks Booth - Strata 2014
Teradata - Presentation at Hortonworks Booth - Strata 2014Teradata - Presentation at Hortonworks Booth - Strata 2014
Teradata - Presentation at Hortonworks Booth - Strata 2014
Hortonworks
 
Seminar Presentation on raspberry pi
Seminar Presentation on raspberry piSeminar Presentation on raspberry pi
Seminar Presentation on raspberry pi
Georgekutty Francis
 
Working with informtiaca teradata parallel transporter
Working with informtiaca teradata parallel transporterWorking with informtiaca teradata parallel transporter
Working with informtiaca teradata parallel transporter
Anjaneyulu Gunti
 
Introduction to raspberry pi
Introduction to raspberry piIntroduction to raspberry pi
Introduction to raspberry pi
praveen_23
 
Ad

Similar to Teradata sql-tuning-top-10 (20)

Crucial Tips to Improve MySQL Database Performance.pptx
Crucial Tips to Improve MySQL Database Performance.pptxCrucial Tips to Improve MySQL Database Performance.pptx
Crucial Tips to Improve MySQL Database Performance.pptx
Tosska Technology
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
Chris Adkin
 
Tips for Database Performance
Tips for Database PerformanceTips for Database Performance
Tips for Database Performance
Kesavan Munuswamy
 
PostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingPostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / Sharding
Amir Reza Hashemi
 
Chapter16
Chapter16Chapter16
Chapter16
gourab87
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
Dhananjay Goel
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
guest9d79e073
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
Mark Ginnebaugh
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
paulguerin
 
Performance tuning
Performance tuningPerformance tuning
Performance tuning
ami111
 
Optimize access
Optimize accessOptimize access
Optimize access
Ala Esmail
 
Oracle SQL tuning pocket reference 1st ed Edition Mark Gurry
Oracle SQL tuning pocket reference 1st ed Edition Mark GurryOracle SQL tuning pocket reference 1st ed Edition Mark Gurry
Oracle SQL tuning pocket reference 1st ed Edition Mark Gurry
koppamebraam
 
Optimizer Hints
Optimizer HintsOptimizer Hints
Optimizer Hints
InMobi Technology
 
Optimizer hint
Optimizer hintOptimizer hint
Optimizer hint
Rajeev Rastogi (KRR)
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancements
infusiondev
 
Database performance tuning and query optimization
Database performance tuning and query optimizationDatabase performance tuning and query optimization
Database performance tuning and query optimization
Usman Tariq
 
Why dba needed in dwh projects
Why dba needed in dwh projectsWhy dba needed in dwh projects
Why dba needed in dwh projects
anurag.vidyarthi
 
When & Why\'s of Denormalization
When & Why\'s of DenormalizationWhen & Why\'s of Denormalization
When & Why\'s of Denormalization
Aliya Saldanha
 
Increase database-performance
Increase database-performanceIncrease database-performance
Increase database-performance
raima sen
 
SQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersSQL Server 2008 Development for Programmers
SQL Server 2008 Development for Programmers
Adam Hutson
 
Crucial Tips to Improve MySQL Database Performance.pptx
Crucial Tips to Improve MySQL Database Performance.pptxCrucial Tips to Improve MySQL Database Performance.pptx
Crucial Tips to Improve MySQL Database Performance.pptx
Tosska Technology
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
Chris Adkin
 
Tips for Database Performance
Tips for Database PerformanceTips for Database Performance
Tips for Database Performance
Kesavan Munuswamy
 
PostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingPostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / Sharding
Amir Reza Hashemi
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
guest9d79e073
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
Mark Ginnebaugh
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
paulguerin
 
Performance tuning
Performance tuningPerformance tuning
Performance tuning
ami111
 
Optimize access
Optimize accessOptimize access
Optimize access
Ala Esmail
 
Oracle SQL tuning pocket reference 1st ed Edition Mark Gurry
Oracle SQL tuning pocket reference 1st ed Edition Mark GurryOracle SQL tuning pocket reference 1st ed Edition Mark Gurry
Oracle SQL tuning pocket reference 1st ed Edition Mark Gurry
koppamebraam
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancements
infusiondev
 
Database performance tuning and query optimization
Database performance tuning and query optimizationDatabase performance tuning and query optimization
Database performance tuning and query optimization
Usman Tariq
 
Why dba needed in dwh projects
Why dba needed in dwh projectsWhy dba needed in dwh projects
Why dba needed in dwh projects
anurag.vidyarthi
 
When & Why\'s of Denormalization
When & Why\'s of DenormalizationWhen & Why\'s of Denormalization
When & Why\'s of Denormalization
Aliya Saldanha
 
Increase database-performance
Increase database-performanceIncrease database-performance
Increase database-performance
raima sen
 
SQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersSQL Server 2008 Development for Programmers
SQL Server 2008 Development for Programmers
Adam Hutson
 
Ad

Recently uploaded (20)

Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 

Teradata sql-tuning-top-10

  • 1. Teradata Pro Teradata | Data Warehouse Consulting Companies | Data Warehouse Vendors | Teradata SQL http://www.teradatapro.com 6 Golden Rules for Teradata SQL Tuning Author : Roland Wenzlofsky Date : October 29, 2014 Teradata SQL Tuning Evergreens 1. Ensure completeness and correctness of Teradata Statistics This is what I always teach in my performance Teradata SQL tuning workshops without ever disappointing my clients: The most important optimization task is to ensure statistic completeness and correctness. This is valid for statistics on all database objects, not only for tables (secondary indexes, join indexes). Detecting missing statistics is easier than you may expect, in your SQL assistant run the command: DIAGNOSTIC HELPSTATS ON FOR SESSION; and EXPLAIN your SQL statement. At the end of the explain output a list of statistics will be added which the optimizer would consider helpful in creating a better execution plan. Add them 1 / 4
  • 2. Teradata Pro Teradata | Data Warehouse Consulting Companies | Data Warehouse Vendors | Teradata SQL http://www.teradatapro.com one by one and re-check the execution plan. To detect stale statistics, there are several methods available. Maybe the easiest way is to split your SQL statement into parts and test each of them by comparing the estimated row count statistics (which the explain output shows you) with the real number of records returned. This approach makes especially sense if the SQL statement which has to be optimized is not runnable in a moderate time. Here is one example: SELECT t01.* FROM table_1 t01 INNER JOIN table_2 t02 ON t01.PK = t02.PK WHERE t01.column_1 = 1 AND t02.column_a = 2 ; Above query can be split into two parts for testing: SELECT * FROM table_1 WHERE column_1 = 1; and SELECT * FROM table_2 WHERE column_a = 2; Execute and Explain both queries and compare the number of returned rows against the number of rows the explain output shows you. If there is a big difference, it could be related to stale statistics or similar problems related with the data distribution. 2. The Primary Index (PI) Choice Use primary indexes for joins whenever possible, and specify in the where clause all the columns for the primary indexes. Joining on the complete set of primary index columns is the least resource intense join possibility. If your environment does not allow you to adjust primary indexes to suit your requirements or you would need a different primary index only for optimizing certain SQL statements, you should think about re-indexing the involved tables by using volatile tables or real temporary tables. 2 / 4
  • 3. Teradata Pro Teradata | Data Warehouse Consulting Companies | Data Warehouse Vendors | Teradata SQL http://www.teradatapro.com 3. Teradata Indexing Techniques Using Teradata Indexing Techniques may be another option to improve your SQL statement. For example, secondary indexes could be especially helpful if you have highly selective WHERE conditions. You could try as well join indexes or even work with partitioning. Whenever working with indexing techniques you have to keep the overall data warehouse architecture in mind and how your solution fits into this architecture. If the identified indexes are not used by the optimizer and are not useful in the overall PDM design, drop them again immediately. 4. Query Rewriting Many times, queries performance can be improved by rewriting the query in different way. Examples like using DISTINCT instead of GROUP BY on columns with many different values come to my mind. Union could be used to break up a large SQL statements into several smaller ones, which may be executed in parallel. While query rewriting may be very powerful in your query optimization toolkit, it may require to understand the business logic behind (“can this left join be replaced by an inner join?”) 5. Real Time Monitoring Watch your query running in real-time. Observing your query while its running in Viewpoint or PMON, helps you to find out the critical steps of your query. Most performance issues are caused either by query steps with heavy skewing in the AMP’s or by a wrong execution plan caused by stale and missing statistics. Stale and missing statistics typically lead to wrong decisions in join preparation (copying a table to all AMP’s instead of rehashing) and join types used (product join instead of merge join). 3 / 4
  • 4. Teradata Pro Teradata | Data Warehouse Consulting Companies | Data Warehouse Vendors | Teradata SQL http://www.teradatapro.com 6. Comparison of Resource Usage Another very important task in performance optimization is to measure the resources used before and after the optimization. Plain query run times can be misleading as they heavily depend on the current load on the Teradata Server and workload management blocking you may not even notice. Here is one example query which only needs the DBC.DBQLOGTBL table. Set a different QUERYBAND for each version of the query you are running: SET QUERY_BAND = 'Version=1;' FOR SESSION; SELECT AMPCPUTIME, (FIRSTRESPTIME-STARTTIME DAY(2) TO SECOND(6)) RUNTIME, SPOOLUSAGE/1024**3 AS SPOOL_IN_GB, CAST(100-((AMPCPUTIME/(HASHAMP()+1))*100/NULLIFZERO(MAXAMPCPUTIME)) AS INTEGER) AS CPU_SKEW, MAXAMPCPUTIME*(HASHAMP()+1) AS CPU_IMPACT, AMPCPUTIME*1000/NULLIFZERO(TOTALIOCOUNT) AS LHR FROM DBC.DBQLOGTBL WHERE QUERYBAND = 'Version=1;' Above query gives you detailed insight about how good or bad each step of your query is: The total CPU Usage The Spool Space needed The LHR (ratio between CPU and IO usage) The CPU Skew The Skew Impact on the CPU Goal is to reduce total CPU usage, consumed spool space and Skew impact on the CPU. Further, the LHR is optimally around 1.00 Powered by TCPDF (www.tcpdf.org) 4 / 4