Databases and question engines, together with Amazon Redshift, typically depend on totally different statistics concerning the underlying knowledge to find out the best approach to execute a question, such because the variety of distinct values and which values have low selectivity. When Amazon Redshift receives a question, comparable to
the question planner makes use of statistics to make an informed guess on the best methodology to load and course of knowledge from storage. Extra statistics concerning the underlying knowledge can typically assist a question planner choose a plan that results in one of the best question efficiency, however this could require a tradeoff among the many value of computing, storing, and sustaining statistics, and would possibly require extra question planning time.
Knowledge lakes are a robust structure to arrange knowledge for analytical processing, as a result of they let builders use environment friendly analytical columnar codecs like Apache Parquet, whereas letting them proceed to change the form of their knowledge as their functions evolve with open desk codecs like Apache Iceberg. One problem with knowledge lakes is that they don’t at all times have statistics about their underlying knowledge, making it troublesome for question engines to find out the optimum execution path. This will result in points, together with sluggish queries and surprising modifications in question efficiency.
In 2024, Amazon Redshift clients queried over 77 EB (exabytes) of knowledge residing in knowledge lakes. Given this utilization, the Amazon Redshift group works to innovate on knowledge lake question efficiency to assist clients effectively entry their open knowledge to get close to real-time insights to make crucial enterprise selections. In 2024, Amazon Redshift launched a number of options that enhance question efficiency for knowledge lakes, together with quicker question instances when an information lake doesn’t have statistics. With Amazon Redshift patch 190, the TPC-DS 3TB benchmark confirmed an general 2x question efficiency enchancment on Apache Iceberg tables with out statistics, together with TPC-DS Question #72, which improved by 125 instances from 690 seconds to five.5 seconds.
On this put up, we first briefly evaluate how planner statistics are collected and what influence they’ve on queries. Then, we focus on Amazon Redshift options that ship optimum plans on Iceberg tables and Parquet knowledge even with the shortage of statistics. Lastly, we evaluate some instance queries that now execute quicker due to these newest Amazon Redshift improvements.
Stipulations
The benchmarks on this put up had been run utilizing the next setting:
- Amazon Redshift Serverless with a base capability of 88 RPU (Amazon Redshift processing unit)
- The Cloud Knowledge Warehouse Benchmark derived from the TPC-DS 3TB dataset. The next tables had been partitioned on this dataset (the remainder had been unpartitioned):
catalog_returns
oncr_returned_date_sk
catalog_sales
oncs_sold_date_sk
store_returns
onsr_returned_date_sk
store_sales
onss_sold_date_sk
web_returns
onwr_returned_date_sk
web_sales
onws_sold_date_sk
stock
oninv_date_sk
For extra data on loading the Cloud Knowledge Warehouse Benchmark into your Amazon Redshift Serverless workgroup, see the Cloud Knowledge Warehouse Benchmark documentation.
Now, let’s evaluate how database statistics work and the way they influence question efficiency.
Overview of the influence of planner statistics on question efficiency
To know why database statistics are necessary, first let’s evaluate what a question planner does. A question planner is the mind of a database: while you ship a question to a database, the question planner should decide essentially the most environment friendly approach to load and compute the entire knowledge required to reply the question. Having details about the underlying dataset, comparable to statistics concerning the variety of rows in a dataset, or the distribution of knowledge, may also help the question planner generate an optimum plan for retrieving the information. Amazon Redshift makes use of statistics concerning the underlying knowledge in tables and columns statistics to find out construct an optimum question execution path.
Let’s see how this works in an instance. Take into account the next question to find out the highest 5 gross sales dates in December 2024 for shops in North America:
On this question, the question planner has to think about a number of elements, together with:
- Which desk is bigger,
shops
orreceipts
? Am I capable of question the smaller desk first to scale back the quantity of looking out on the bigger desk? - Which returns extra rows,
receipts.insert_date BETWEEN '2024-12-01' AND '2024-12-31'
orshops.area = 'NAMER'
? - Is there any partitioning on the tables? Can I search over a smaller set of knowledge to hurry up the question?
Having details about the underlying knowledge may also help to generate an optimum question plan. For instance, shops.area = 'NAMER'
would possibly solely return a couple of rows (that’s, it’s extremely selective), that means it’s extra environment friendly to execute that step of the question first earlier than filtering by means of the receipts
desk. What helps a question planner make this choice is the statistics out there on columns and tables.
Desk statistics (often known as planner statistics) present a snapshot of the information out there in a desk to assist the question planner make an knowledgeable choice on execution methods. Databases gather desk statistics by means of sampling, which entails reviewing a subset of rows to find out the general distribution of knowledge. The standard of statistics, together with the freshness of knowledge, can considerably influence a question plan, which is why databases will reanalyze and regenerate statistics after a sure threshold of the underlying knowledge modifications.
Amazon Redshift helps a number of desk and column degree statistics to help in constructing question plans. These embody:
Statistic | What it’s | Affect | Question plan affect |
Variety of rows (numrows) | Variety of rows in a desk | Estimates the general measurement of question outcomes and JOIN sizes | Selections on JOIN ordering and algorithms, and useful resource allocation |
Variety of distinct values (NDV) | Variety of distinctive values in a column | Estimates selectivity, that’s, what number of rows will probably be returned from predicates (for instance, WHERE clause) and the dimensions of JOIN outcomes | Selections on JOIN ordering and algorithms |
NULL rely | Variety of NULL values in a column | Estimates variety of rows eradicated by IS NULL or IS NOT NULL | Selections on filter pushdown (that’s, what nodes execute a question) and JOIN methods |
Min/max values | Smallest and largest values in a column | Helps range-based optimizations (for instance, WHERE x BETWEEN 10 AND 20) | Selections on JOIN order and algorithms, and useful resource allocation |
Column measurement | Complete measurement of column knowledge in reminiscence | Estimates general measurement of scans (studying knowledge), JOINs, and question outcomes | Selections on JOIN algorithms and ordering |
Open codecs comparable to Apache Parquet don’t have any of the previous statistics by default and desk codecs like Apache Iceberg have a subset of the previous statistics comparable to variety of rows, NULL rely and min/max values. This will make it difficult for question engines to plan environment friendly queries. Amazon Redshift has added improvements that enhance general question efficiency on knowledge lake knowledge saved in Apache Iceberg and Apache Parquet codecs even when all or partial desk or column-level statistics are unavailable. The following part opinions options in Amazon Redshift that assist enhance question efficiency on knowledge lakes even when desk statistics aren’t current or are restricted.
Amazon Redshift options when knowledge lakes don’t have statistics for Iceberg tables and Parquet
As talked about beforehand, there are a lot of circumstances the place tables saved in knowledge lakes lack statistics, which creates challenges for question engines to make knowledgeable selections on selecting the right question plan. Nevertheless, Amazon Redshift has launched a sequence of improvements that enhance efficiency for queries on knowledge lakes even when there aren’t desk statistics out there. On this part, we evaluate a few of these enhancements and the way they influence your question efficiency.
Dynamic partition elimination by means of distributed joins
Dynamic partition elimination is a question optimization approach that enables Amazon Redshift to skip studying knowledge unnecessarily throughout question execution on a partitioned desk. It does this by figuring out which partitions of a desk are related to a question and solely scanning these partitions, considerably decreasing the quantity of knowledge that must be processed.
For instance, think about a schema that has two tables:
gross sales
(truth desk) with columns:sale_id
product_id
sale_amount
sale_date
merchandise
(dimension desk) with columns:product_id
product_name
class
The gross sales desk is partitioned by product_id
. Within the following instance, you need to discover the full gross sales quantity for merchandise within the Electronics class in December 2024.
SQL question:
How Amazon Redshift improves this question:
- Filter on dimension desk:
- The question filters the merchandise desk to solely embody merchandise within the
Electronics
class.
- The question filters the merchandise desk to solely embody merchandise within the
- Establish related partitions:
- With the brand new enhancements, Amazon Redshift analyzes this filter and determines which partitions of the gross sales desk should be scanned.
- It appears to be like on the
product_id
values within the merchandise desk that match theElectronics
class and solely scans these particular partitions within the gross sales desk. - As an alternative of scanning all the gross sales desk, Amazon Redshift solely scans the partitions that include gross sales knowledge for electronics merchandise.
- This considerably reduces the quantity of knowledge Amazon Redshift must course of, making the question quicker.
Beforehand, this optimization was solely utilized on broadcast joins when all youngster joins under the be part of had been additionally broadcast joins. The Amazon Redshift group prolonged this functionality to work on all broadcast joins, regardless if the kid joins under them are broadcast. This enables extra queries to profit from dynamic partition elimination, comparable to TPC-DS Q64 and Q75 for Iceberg tables, and TPC-DS Q25 in Parquet.
Metadata caching for Iceberg tables
The Iceberg open desk format employs a two-layer construction: a metadata layer and an information layer. The metadata layer has three ranges of recordsdata (metadata.json
, manifest lists, and manifests), which permits for efficiency options comparable to quicker scan planning and superior knowledge filtering. Amazon Redshift makes use of the Iceberg metadata construction to effectively establish the related knowledge recordsdata to scan, utilizing partition worth ranges and column-level statistics and eliminating pointless knowledge processing.
The Amazon Redshift group noticed that Iceberg metadata is steadily fetched a number of instances each inside and throughout queries, resulting in potential efficiency bottlenecks. We applied an in-memory LRU (least not too long ago used) cache for parsed metadata, manifest record recordsdata, and manifest recordsdata. This cache retains essentially the most not too long ago used metadata in order that we keep away from fetching them repeatedly from Amazon Easy Storage Service (Amazon S3) throughout queries. This caching has helped with general efficiency enhancements of as much as 2% in a TPC-DS 3TB workload. We observe greater than 90% cache hits for these metadata buildings, decreasing the iceberg metadata processing instances significantly.
Stats inference for Iceberg tables
As talked about beforehand, the Apache Iceberg file format comes with some statistics comparable to variety of rows, variety of nulls, column min/max values and column storage measurement within the metadata recordsdata referred to as manifest recordsdata. Nevertheless, they don’t at all times present all of the statistics that we’d like particularly common width which is necessary for the cost-based optimizer utilized by Amazon Redshift.
We delivered a function to estimate common width for variable size columns comparable to string and binary from Iceberg metadata. We do that through the use of the column storage measurement and the variety of rows, and we modify for column compression when mandatory. By inferring these extra statistics, our optimizer could make extra correct value estimates for various question plans. This stats inference function, launched in Amazon Redshift patch 186, affords as much as a 7% enchancment within the TPC-DS benchmarks. We have now additionally enhanced Amazon Redshift optimizer’s value mannequin. The enhancements embody planner optimizations that enhance the estimations of the totally different be part of distribution methods to take into consideration the networking value of distributing the information between the nodes of an Amazon Redshift cluster. The enhancements additionally embody enhancements to Amazon Redshift question optimizer. These enhancements, that are a end result of a number of years of analysis, testing, and implementation demonstrated as much as a forty five% enchancment in a set of TPC-DS benchmarks.
Instance: TPC-DS benchmark highlights on Amazon Redshift no stats queries on knowledge lakes
One approach to measure knowledge lake question efficiency for Amazon Redshift is utilizing the TPC-DS benchmark. The TPC-DS benchmark is a standardized benchmark designed to check choice assist techniques, particularly taking a look at concurrently accessed techniques the place queries can vary from shorter analytical queries (for instance, reporting, dashboards) to longer working ETL-style queries for transferring and reworking knowledge into a distinct system. For these exams, we used the Cloud Knowledge Warehouse Benchmark derived from the TPC-DS 3TB to align our testing with many frequent analytical workloads, and supply a regular set of comparisons to measure enhancements to Amazon Redshift knowledge lake question efficiency.
We ran these exams throughout knowledge saved each within the Apache Parquet knowledge format, along with Apache Iceberg tables with knowledge in Apache Parquet recordsdata. As a result of we centered these exams on out-of-the-box efficiency, none of those knowledge units had any desk statistics out there. We carried out these exams utilizing the desired Amazon Redshift patch variations within the following desk, and used Amazon Redshift Serverless with 88 RPU with none extra tuning. The next outcomes characterize a energy run, which is the sum of how lengthy it took to run all of the exams, from a heat run, that are the outcomes of the facility run after a minimum of one execution of the workload:
P180 (12/2023) | P190 (5/2025) | |
Apache Parquet (solely numrows) | 7,796 | 3,553 |
Apache Iceberg (out-of-the-box, no tuning) | 4,411 | 1,937 |
We noticed notable enhancements in a number of question run instances. For this put up, we concentrate on the enhancements we noticed in question 82:
On this question, we’re trying to find the highest 100 promoting manufacturers from a selected supervisor in December 2002, which represents a usually dashboard-style analytical question. In our energy run, we noticed a discount in question time from 512 seconds to 18.1 seconds for Apache Parquet knowledge, or a 28.2x enchancment in efficiency. The accelerated question efficiency for this question in a heat run is because of the enhancements to the cost-based optimizer and dynamic partition elimination.
We noticed question efficiency enhancements throughout most of the queries discovered within the Cloud Knowledge Warehouse Benchmark derived from the TPC-DS take a look at suite. We encourage you to attempt your personal efficiency exams utilizing Amazon Redshift Serverless in your knowledge lake knowledge to see what efficiency positive factors you possibly can observe.
Cleanup
For those who ran these exams by yourself and don’t want the sources anymore, you’ll have to delete your Amazon Redshift Serverless workgroup. See Shutting down and deleting a cluster. For those who don’t have to retailer the Cloud Knowledge Warehouse Benchmark knowledge in your S3 bucket anymore, see Deleting Amazon S3 objects.
Conclusion
On this put up, you discovered how cost-based optimizers for databases work, and the way statistical details about your knowledge may also help Amazon Redshift execute queries extra effectively. You’ll be able to optimize question efficiency for Iceberg tables by mechanically accumulating Puffin statistics, which lets Amazon Redshift use these latest improvements to extra effectively question your knowledge. Giving extra data to your question planner—the mind of Amazon Redshift—helps to offer extra predictable efficiency and lets you additional scale the way you work together along with your knowledge in your knowledge lakes and knowledge lakehouses.
In regards to the authors
Martin Milenkoski is a Software program Growth Engineer on the Amazon Redshift group, at present specializing in knowledge lake efficiency and question optimization. Martin holds an MSc in Laptop Science from the École Polytechnique Fédérale de Lausanne.
Kalaiselvi Kamaraj is a Sr. Software program Growth Engineer on the Amazon Redshift group. She has labored on a number of initiatives throughout the Amazon Redshift Question processing group and at present specializing in efficiency associated initiatives for Amazon Redshift DataLake and question optimizer.
Jonathan Katz is a Principal Product Supervisor – Technical on the AWS Analytics group and relies in New York. He’s a Core Staff member of the open-source PostgreSQL mission and an lively open-source contributor, together with to the pgvector mission.