Skip to Content
Trino 权威指南:原书第2版
book

Trino 权威指南:原书第2版

by Matt Fuller, Manfred Moser, Martin Traverso
July 2023
Intermediate to advanced
278 pages
5h 40m
Chinese
China Machine Press
Content preview from Trino 权威指南:原书第2版
240
|
12
12.2 Trino SQL
查询调优
参见
4.5
节,你已经了解了
Trino
的基于代价的优化器。回顾一下,
SQL
是一门声明式
的语言,用户编写
SQL
查询来描述他们想要的数据。与命令式程序不同,在
SQL
中,
用户并不指定如何处理数据并获得结果,获得所需结果的步骤将交由查询优化器来决
定。这里的执行步骤就是所谓的查询调优。
大多数情况下,提交
SQL
的终端用户可以依赖
Trino
来计划、优化和执行
SQL
查询,
并快速高效地获得结果。终端用户无须关心太多细节。
然而,有时你无法获得期望的性能,因此需要进行
Trino
查询调优。你需要鉴别是某个
查询本身存在性能问题,还是具有某些相似属性的多个查询存在性能问题。
下面先从单个查询的调优开始,假设系统上其他的查询运行正常。在检查慢查询时,你
应该首先检查查询使用到的表是否有数据统计信息。目前有许多连接器(如
Hive
连接器
PostgreSQL
连接器)都支持收集和维护表统计信息。预计将有更多的连接器开始提供
数据统计信息。
根据连接器和数据源配置,列和表统计信息已经可用。使用特定表的
SHOW STATS
命令
查看可用数据:
trino:ontime> SHOW STATS FOR flights;
如果统计信息不存在,可以通过
ANALYZE
命令添加统计信息。
SQL
Join
是成本最高的操作之一,在进行查询性能调优时应该重点关注
Join
。你可以
在查询上使用
EXPLAIN
命令来确定
Join
顺序:
trino:ontime> EXPLAIN
SELECT f.uniquecarrier, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

What Successful Brick-and-Mortar Retailers Get Right

What Successful Brick-and-Mortar Retailers Get Right

Rob Angell
Three Essentials for Agentic AI Security

Three Essentials for Agentic AI Security

Paolo Dal Cin, Daniel Kendzior, Yusof Seedat, Renato Marinho
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9787111731603