SlideShare a Scribd company logo
Tempura: A General Cost-Based
Optimizer Framework for
Incremental Data Processing
Zuozhi Wang2
, Kai Zeng1
, Botong Huang1
, Wei Chen1
, Xiaozong Cui1
,
Bo Wang1
, Ji Liu1
, Liya Fan1
, Dachuan Qu1
, Zhenyu Hou1
, Tao Guan1
,
Chen Li2, Jingren Zhou1
1. Alibaba Group 2. UC Irvine
1
Zuozhi Wang
Incremental Computation
• Widely Used in Many Scenarios
• Discretized Stream Processing
• Progressive Data Warehouse
• Late Data Processing
• Incremental View Maintenance
• …
• Different Scenarios have Different Characteristics
2
Zuozhi Wang
Total Income of the Day over Time
Discretized Stream Processing
Sales
1AM 2AM
Sales
…… 11PM 12 midnight
Sales Sales
……
3
Zuozhi Wang
Data Arrives Continuously with 1 hour Interval
Total Income of the Day over Time
Discretized Stream Processing
Sales
1AM
∑
2AM
$100
Sales
∑
+
…… 11PM 12 midnight
Sales
∑
+
Sales
∑
+
…… $2300
……
$100
$200
$100
$2400
$100
4
……
Zuozhi Wang
End-of-Day Report
Data Warehouse
Sales
1AM 2AM
Sales
…… 11PM 12 midnight
Sales Sales
……
Traditional Batch Computation
Accumulate all data and compute at the end.
Accumulate All Data
5
Resource
Usage
Zuozhi Wang
End-of-Day Report
Data Warehouse
Sales
1AM 2AM
Sales
…… 11PM 12 midnight
Sales Sales
……
Problem:
Many daily routine analytical queries run around the same time.
High cluster resource load at midnight.
Accumulate All Data
6
Resource
Usage
Zuozhi Wang
End-of-Day Report
Progressive Data Warehouse
Sales
1AM 2AM
Sales
…… 11PM 12 midnight
Sales Sales
……
Incremental Computation: Update result as soon as new data arrives.
Problem: Some jobs still execute in rush hours.
……
7
Cluster Usage
Zuozhi Wang
End-of-Day Report
Progressive Data Warehouse
Sales
1AM 2AM
Sales
…… 11PM 12 midnight
Sales Sales
……
Observation: User only cares about the last result.
Intermediate incremental jobs can have more flexibility.
……
8
Cluster Usage
Zuozhi Wang
End-of-Day Report
Progressive Data Warehouse
Sales
1AM 2AM
Sales
…… 11PM 12 midnight
Sales Sales
……
𝐶𝑜𝑠𝑡 𝑉𝑒𝑐𝑡𝑜𝑟: [ 0.9 0.3 …… 0.2 1.0 ]
9
Predictable
Resource Usage
Pattern
Zuozhi Wang
Assign a cost factor at each time point based on resource usage.
The optimizer can choose to skip the execution at 1AM.
Late Data Processing
Sales
12 midnight 1AM …… 5AM 6AM
Sales (late) Sales (late)
Complete Result
Operator1:
Low Incremental Computation Overhead (filters, aggregations, ...)
Operator2:
High Incremental Computation Overhead (outer joins, nested queries, …)
Partial Result
10
Zuozhi Wang
Sales (late)
……
Small amounts of late
data arrive continuously.
Late Data Processing
Sales
12 midnight 1AM
Sales (late)
…… 5AM 6AM
……
Sales (late) Sales (late)
Complete Result
……
Partial Result
11
Zuozhi Wang
Only incrementally compute operator1.
Compute operator2 (high overhead) only
when the user needs the output result.
𝑇= [ ] k time points
Tempura: A General Cost-Based Optimizer
Framework for Incremental Data Processing
• Incremental Computation in its Most General Form
• Single Optimizer Framework for Many Scenarios
𝑄= [ ] Expected delivered result
𝐷= [ ] Input data at each time
𝐷1
T1
𝑄𝑢𝑒𝑟𝑦(𝐷1)
𝐷2
T2
Ø
𝐷𝑘
T𝑘
𝑄𝑢𝑒𝑟𝑦(𝐷𝑘)
…
𝑃= [ ] Incremental Plan
𝐶= [ 𝑐1 𝑐2 𝑐𝑘 ] Cost function
Inputs
12
(Optimizer Output)
…
Ø
Zuozhi Wang
How to do Incremental Computation?
• Many Incremental Computation Algorithms
• Retractable
• Non-Retractable
• Outer Join View Maintenance
• Higher Order View Maintenance
• …
• Best Algorithm is Data Dependent
13
Zuozhi Wang
How to do Incremental Computation?
14
Sales
id profit
o1 100
o2 100
o3 100
Returns
id loss
o1 10
o2 20
id income
o1 -10
o2 -20
o3 100
Left Outer Join
Zuozhi Wang
gross
70 Sum SELECT SUM(income) AS gross FROM
(SELECT
sales.id,
CASE
WHEN loss IS NOT NULL THEN -loss
ELSE profit END AS income
FROM sales LEFT OUTER JOIN returns
ON sales.id = returns.id
) AS sales_status
Compute gross income based on
profit from sales and loss from returns.
Retractable Incremental Computation
Returns
Sales Returns
id profit
o1 100
o2 100
o3 100
id loss
o1 10
id loss
o2 20
id income
o1 100 -10
o2 100
o3 100
id income
o1 -10
o2 100 -20
o3 100
id income
o1 -10
o2 -20
o3 100
t1 t2 t3 t4 15
Zuozhi Wang
id income
o1 100
o2 100
o3 100
gross
300
gross
190
gross
70
gross
70
Non-Retractable Incremental Computation
Returns
Sales Returns
id profit
o1 100
o2 100
o3 100
id loss
o1 10
id loss
o2 20
id income
o1 -10
id income
o1 -10
o2 -20
id income
o1 -10
o2 -20
o3 100
t1 t2 t3 t4 16
Zuozhi Wang
id income
gross gross
-10
gross
-30
gross
70
Retractable vs Non-Retractable Algorithm
• Retractable Incremental Computation
• Needs to retract output whenever new return orders arrive.
• Better when return orders are rare. (Less computation in the end)
• Non-Retractable Incremental Computation
• Holds more data to ensure no retractions. (Less computation overhead)
• Better when return orders are frequent.
• Let an optimizer automatically finds the best algorithm!
Zuozhi Wang 17
Tempura: Contributions
18
Zuozhi Wang
• Propose a New Model for Incremental Computation
• Provide a Rewrite-Rule Framework
• Describes and unifies many incremental computation techniques
• Integrate with a Volcano/Cascades-style Optimizer
TVR-Based Incremental Processing
• Time-Varying Relation (TVR)
• Mapping from a time domain to relations
• Snapshot and Delta
id income
𝑜1 100
𝑜2 100
𝑜3 100
id income
𝑜1 -10
𝑜2 100
𝑜3 100
𝑜4 170
Snapshot(𝑡1) Snapshot(t2)
id income #
𝑜1 100 -1
𝑜1 -10 +1
𝑜4 170 +1
Delta(t1, t2)
t1 t2
+#
→
Merge Operation
19
Zuozhi Wang
Query Optimization on TVR
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
20
Zuozhi Wang
Σ Σ(R ⋈ 𝑙𝑜 S)
SELECT SUM(income) AS gross FROM
(SELECT
sales.id,
CASE
WHEN loss IS NOT NULL THEN -loss
ELSE profit END AS income
FROM sales LEFT OUTER JOIN returns
ON sales.id = returns.id
) AS sales_status
Each horizontal line is a TVR.
TVR-Generating Rules
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
Snapshot(2)
21
Zuozhi Wang
Σ Σ(R ⋈ 𝑙𝑜 S)
Snapshot(1) Delta(1,2)
𝑆1
⋈ 𝑙𝑜
𝑅1
Σ
𝑆2
𝑅2
? ? ?
? ? ?
With 2 time points:
Expand operator tree into 3 trees:
Snapshot(1), Delta(1,2), and Snapshot(2)
TVR-Generating Rules
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
Snapshot(2)
22
Zuozhi Wang
Σ Σ(R ⋈ 𝑙𝑜 S)
Snapshot(1) Delta(1,2)
𝑆1
⋈ 𝑙𝑜
𝑅1
Σ
𝑆2
𝑅2
Δ ⋈ 𝑙𝑜
? ? ?
Compute the delta of left outer join.
TVR-Generating Rules
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
Snapshot(2)
23
Zuozhi Wang
Σ Σ(R ⋈ 𝑙𝑜 S)
Snapshot(1) Delta(1,2)
𝑆1
⋈ 𝑙𝑜
𝑅1
Σ
𝑆2
𝑅2
Σ
Δ ⋈ 𝑙𝑜
Compute the delta of aggregation.
Intra-TVR Rules
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
Snapshot(2)
24
Zuozhi Wang
Σ Σ(R ⋈ 𝑙𝑜 S)
Snapshot(1) Delta(1,2)
𝑆1
⋈ 𝑙𝑜
𝑅1
Σ
𝑆2
𝑅2
Σ
Δ ⋈ 𝑙𝑜
+𝑈𝑛𝑖𝑜𝑛
How to merge snapshot and delta?
Intra-TVR Rules
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
Snapshot(2)
25
Zuozhi Wang
Σ Σ(R ⋈ 𝑙𝑜 S)
Snapshot(1) Delta(1,2)
𝑆1
⋈ 𝑙𝑜
𝑅1
Σ
𝑆2
𝑅2
Σ
Δ ⋈ 𝑙𝑜
+𝑈𝑛𝑖𝑜𝑛
+𝑆𝑢𝑚
How to merge snapshot and delta?
Inter-TVR Rules: Non-Retractable Algorithm
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
Snapshot(2)
26
Zuozhi Wang
Σ Σ(R ⋈ 𝑙𝑜 S)
Snapshot(1) Delta(1,2)
⋈
⋈ 𝑙𝑎
𝑅 ⋈ 𝑆
𝑅 ⋈ 𝑙𝑎 𝑆
𝑈𝑛𝑖𝑜𝑛
𝑆1
⋈ 𝑙𝑜
𝑅1
Σ
⋈
⋈ 𝑙𝑎
𝑈𝑛𝑖𝑜𝑛
Decompose
Left Outer Join
into:
Left Anti Join
- Retractable
Inner Join
- Insertion Only
Full Search Space
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
Snapshot(2)
27
Zuozhi Wang
Σ Σ(R ⋈ 𝑙𝑜 S)
Snapshot(1) Delta(1,2)
⋈
⋈ 𝑙𝑎
𝑈𝑛𝑖𝑜𝑛
𝑅 ⋈ 𝑆
𝑅 ⋈ 𝑙𝑎 𝑆
Σ(R ⋈ 𝑙a S)
Σ(R ⋈ S)
Σ
Σ
𝑆1
⋈ 𝑙𝑜
𝑅1
Σ
𝑆2
𝑅2
Σ
⋈
⋈ 𝑙𝑎
Δ
⋈
Δ ⋈ 𝑙𝑜
𝑈𝑛𝑖𝑜𝑛
Σ
Σ
𝑈𝑛𝑖𝑜𝑛
Σ
𝑈𝑛𝑖𝑜𝑛
+𝑆𝑢𝑚
+𝑈𝑛𝑖𝑜𝑛
Any path that can reach the final output
is a valid execution plan.
Plan: Retractable Algorithm
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
Snapshot(2)
28
Zuozhi Wang
Σ(R ⋈ 𝑙𝑜 S)
Snapshot(1) Delta(1,2)
⋈
⋈ 𝑙𝑎
𝑈𝑛𝑖𝑜𝑛
𝑅 ⋈ 𝑆
𝑅 ⋈ 𝑙𝑎 𝑆
Σ(R ⋈ 𝑙a S)
Σ(R ⋈ S)
Σ
Σ
𝑆1
⋈ 𝑙𝑜
𝑅1
Σ
𝑆2
𝑅2
Σ
⋈
⋈ 𝑙𝑎
Δ
⋈
Δ ⋈ 𝑙𝑜
𝑈𝑛𝑖𝑜𝑛
Σ
Σ
𝑈𝑛𝑖𝑜𝑛
Σ
Σ
𝑈𝑛𝑖𝑜𝑛
+𝑆𝑢𝑚
+𝑈𝑛𝑖𝑜𝑛
Plan: Non-Retractable Algorithm
𝑆2
⋈ 𝑙𝑜
𝑅2
𝑆
𝑅
R ⋈ 𝑙𝑜 S
Snapshot(2)
29
Zuozhi Wang
Σ(R ⋈ 𝑙𝑜 S)
Snapshot(1) Delta(1,2)
⋈
⋈ 𝑙𝑎
𝑈𝑛𝑖𝑜𝑛
𝑅 ⋈ 𝑆
𝑅 ⋈ 𝑙𝑎 𝑆
Σ(R ⋈ 𝑙a S)
Σ(R ⋈ S)
Σ
𝑆1
⋈ 𝑙𝑜
𝑅1
Σ
𝑆2
𝑅2
Σ
⋈
⋈ 𝑙𝑎
Δ
⋈
Δ ⋈ 𝑙𝑜
𝑈𝑛𝑖𝑜𝑛
Σ
Σ
𝑈𝑛𝑖𝑜𝑛
Σ
Σ
𝑈𝑛𝑖𝑜𝑛
+𝑆𝑢𝑚
+𝑈𝑛𝑖𝑜𝑛
Σ
Tempura: More Details in the Paper
• Integration with Volcano/Cascades-style Optimizer
• Speed up Optimization Process
• How to choose optimal plan?
• Dynamic re-optimization
• Statistics Estimation
• ……
30
Zuozhi Wang
Experimental Study
• TPC-DS
• 4 basic incremental computation algorithms:
• IM1 (Retractable Incremental Computation)
• IM2 (Non-retractable Incremental Computation)
• OJV (Outer-Join View Maintenance)
• HOV (Higher-Order View Maintenance)
• Tempura
• Unify all 4 algorithms.
31
Zuozhi Wang
Effectiveness
32
• 5 queries, 4 data arrival patterns, and 2 cost functions.
• Different methods are good at different scenarios.
• Tempura is always the best.
Zuozhi Wang
Query Optimization Performance
• For 80% TPC-DS query: optimization finished within 3 seconds
• Slower than traditional optimizers but can generate much better plans.
33
Zuozhi Wang
Tempura
• Open Source
• Built on top of Apache Calcite
• https://github.com/alibaba/cost-based-incremental-optimizer
• https://issues.apache.org/jira/browse/CALCITE-4568
34
Zuozhi Wang

More Related Content

What's hot (20)

PDF
ClickHouse Analytical DBMS: Introduction and Case Studies, by Alexander Zaitsev
Altinity Ltd
 
PDF
Don’t optimize my queries, optimize my data!
Julian Hyde
 
PDF
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
Altinity Ltd
 
PPTX
High Performance, High Reliability Data Loading on ClickHouse
Altinity Ltd
 
PDF
Bind Peek をもっと使おうぜ!(柴田 歩) - JPOUG Advent Calendar 2014(Day 5) -
歩 柴田
 
PDF
Hudi architecture, fundamentals and capabilities
Nishith Agarwal
 
PDF
Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기
AWSKRUG - AWS한국사용자모임
 
PPTX
Need for Time series Database
Pramit Choudhary
 
PDF
MongoDB WiredTiger Internals
Norberto Leite
 
PDF
[db tech showcase Tokyo 2016] B27:SQL Server 2016 AlwaysOn 可用性グループ New Featur...
Insight Technology, Inc.
 
PDF
InfluxDB & Grafana
Pedro Salgado
 
PDF
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13c
Alfredo Krieg
 
PDF
[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?
Juhong Park
 
PDF
redis 소개자료 - 네오클로바
NeoClova
 
PPTX
Adapting and adopting spm v04
Carlos Sierra
 
PPTX
Data stage
Sai Kiran
 
PPT
Exadata architecture and internals presentation
Sanjoy Dasgupta
 
PDF
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Jean-François Gagné
 
PDF
When Apache Spark Meets TiDB with Xiaoyu Ma
Databricks
 
PPTX
Extreme Apache Spark: how in 3 months we created a pipeline that can process ...
Josef A. Habdank
 
ClickHouse Analytical DBMS: Introduction and Case Studies, by Alexander Zaitsev
Altinity Ltd
 
Don’t optimize my queries, optimize my data!
Julian Hyde
 
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
Altinity Ltd
 
High Performance, High Reliability Data Loading on ClickHouse
Altinity Ltd
 
Bind Peek をもっと使おうぜ!(柴田 歩) - JPOUG Advent Calendar 2014(Day 5) -
歩 柴田
 
Hudi architecture, fundamentals and capabilities
Nishith Agarwal
 
Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기
AWSKRUG - AWS한국사용자모임
 
Need for Time series Database
Pramit Choudhary
 
MongoDB WiredTiger Internals
Norberto Leite
 
[db tech showcase Tokyo 2016] B27:SQL Server 2016 AlwaysOn 可用性グループ New Featur...
Insight Technology, Inc.
 
InfluxDB & Grafana
Pedro Salgado
 
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13c
Alfredo Krieg
 
[KAIST 채용설명회] 데이터 엔지니어는 무슨 일을 하나요?
Juhong Park
 
redis 소개자료 - 네오클로바
NeoClova
 
Adapting and adopting spm v04
Carlos Sierra
 
Data stage
Sai Kiran
 
Exadata architecture and internals presentation
Sanjoy Dasgupta
 
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Jean-François Gagné
 
When Apache Spark Meets TiDB with Xiaoyu Ma
Databricks
 
Extreme Apache Spark: how in 3 months we created a pipeline that can process ...
Josef A. Habdank
 

Similar to Tempura: A General Cost-Based Optimizer Framework for Incremental Data Processing (20)

PPTX
Data Stream Management
k_tauhid
 
PDF
Learning Timed Automata with Cypher
openCypher
 
PPTX
bx16_debreceni
Csaba Debreceni
 
PDF
How to Improve Data Labels and Feedback Loops Through High-Frequency Sensor A...
InfluxData
 
PDF
PyCon KR 2018 Effective Tips for Django ORM in Practice
Seomgi Han
 
PDF
Realtime Analytics
eXascale Infolab
 
PDF
Learning Timed Automata with Cypher
Gábor Szárnyas
 
PDF
A Call for Sanity in NoSQL
C4Media
 
PDF
Modifying Your SQL Streaming Queries on the Fly: The Impossible Trinity
HostedbyConfluent
 
PPT
Using Simplicity to Make Hard Big Data Problems Easy
nathanmarz
 
PDF
Cómo hemos implementado semántica de "Exactly Once" en nuestra base de datos ...
javier ramirez
 
PDF
Batch Processing at Scale with Flink & Iceberg
Flink Forward
 
PPTX
Part 1: Lambda Architectures: Simplified by Apache Kudu
Cloudera, Inc.
 
PPTX
Moving Beyond Lambda Architectures with Apache Kudu
Cloudera, Inc.
 
PPT
Database Research Principles Revealed
infoblog
 
PDF
Beyond EXPLAIN: Query Optimization From Theory To Code
Yuto Hayamizu
 
PDF
Optimization for iterative queries on Mapreduce
makoto onizuka
 
PPT
Scheduling with Startup and Holding Costs
Rajendran
 
PDF
Correctly Loading Incremental Data at Scale
Alluxio, Inc.
 
PPT
Unit 2 for the Artificial intelligence and machine learning
ganapathi2952005
 
Data Stream Management
k_tauhid
 
Learning Timed Automata with Cypher
openCypher
 
bx16_debreceni
Csaba Debreceni
 
How to Improve Data Labels and Feedback Loops Through High-Frequency Sensor A...
InfluxData
 
PyCon KR 2018 Effective Tips for Django ORM in Practice
Seomgi Han
 
Realtime Analytics
eXascale Infolab
 
Learning Timed Automata with Cypher
Gábor Szárnyas
 
A Call for Sanity in NoSQL
C4Media
 
Modifying Your SQL Streaming Queries on the Fly: The Impossible Trinity
HostedbyConfluent
 
Using Simplicity to Make Hard Big Data Problems Easy
nathanmarz
 
Cómo hemos implementado semántica de "Exactly Once" en nuestra base de datos ...
javier ramirez
 
Batch Processing at Scale with Flink & Iceberg
Flink Forward
 
Part 1: Lambda Architectures: Simplified by Apache Kudu
Cloudera, Inc.
 
Moving Beyond Lambda Architectures with Apache Kudu
Cloudera, Inc.
 
Database Research Principles Revealed
infoblog
 
Beyond EXPLAIN: Query Optimization From Theory To Code
Yuto Hayamizu
 
Optimization for iterative queries on Mapreduce
makoto onizuka
 
Scheduling with Startup and Holding Costs
Rajendran
 
Correctly Loading Incremental Data at Scale
Alluxio, Inc.
 
Unit 2 for the Artificial intelligence and machine learning
ganapathi2952005
 
Ad

Recently uploaded (20)

PPT
1 DATALINK CONTROL and it's applications
karunanidhilithesh
 
PPTX
Resmed Rady Landis May 4th - analytics.pptx
Adrian Limanto
 
PPTX
Introduction to Artificial Intelligence.pptx
StarToon1
 
PDF
WEF_Future_of_Global_Fintech_Second_Edition_2025.pdf
AproximacionAlFuturo
 
PPTX
AI Project Cycle and Ethical Frameworks.pptx
RiddhimaVarshney1
 
PDF
How to Avoid 7 Costly Mainframe Migration Mistakes
JP Infra Pvt Ltd
 
PDF
Incident Response and Digital Forensics Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
DATA-COLLECTION METHODS, TYPES AND SOURCES
biggdaad011
 
PDF
apidays Helsinki & North 2025 - How (not) to run a Graphql Stewardship Group,...
apidays
 
PPTX
Human-Action-Recognition-Understanding-Behavior.pptx
nreddyjanga
 
DOCX
AI/ML Applications in Financial domain projects
Rituparna De
 
PDF
Context Engineering vs. Prompt Engineering, A Comprehensive Guide.pdf
Tamanna
 
PPT
Lecture 2-1.ppt at a higher learning institution such as the university of Za...
rachealhantukumane52
 
PPTX
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
PPTX
recruitment Presentation.pptxhdhshhshshhehh
devraj40467
 
PDF
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
PPTX
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
PPTX
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
PDF
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
PDF
How to Connect Your On-Premises Site to AWS Using Site-to-Site VPN.pdf
Tamanna
 
1 DATALINK CONTROL and it's applications
karunanidhilithesh
 
Resmed Rady Landis May 4th - analytics.pptx
Adrian Limanto
 
Introduction to Artificial Intelligence.pptx
StarToon1
 
WEF_Future_of_Global_Fintech_Second_Edition_2025.pdf
AproximacionAlFuturo
 
AI Project Cycle and Ethical Frameworks.pptx
RiddhimaVarshney1
 
How to Avoid 7 Costly Mainframe Migration Mistakes
JP Infra Pvt Ltd
 
Incident Response and Digital Forensics Certificate
VICTOR MAESTRE RAMIREZ
 
DATA-COLLECTION METHODS, TYPES AND SOURCES
biggdaad011
 
apidays Helsinki & North 2025 - How (not) to run a Graphql Stewardship Group,...
apidays
 
Human-Action-Recognition-Understanding-Behavior.pptx
nreddyjanga
 
AI/ML Applications in Financial domain projects
Rituparna De
 
Context Engineering vs. Prompt Engineering, A Comprehensive Guide.pdf
Tamanna
 
Lecture 2-1.ppt at a higher learning institution such as the university of Za...
rachealhantukumane52
 
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
recruitment Presentation.pptxhdhshhshshhehh
devraj40467
 
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
How to Connect Your On-Premises Site to AWS Using Site-to-Site VPN.pdf
Tamanna
 
Ad

Tempura: A General Cost-Based Optimizer Framework for Incremental Data Processing

  • 1. Tempura: A General Cost-Based Optimizer Framework for Incremental Data Processing Zuozhi Wang2 , Kai Zeng1 , Botong Huang1 , Wei Chen1 , Xiaozong Cui1 , Bo Wang1 , Ji Liu1 , Liya Fan1 , Dachuan Qu1 , Zhenyu Hou1 , Tao Guan1 , Chen Li2, Jingren Zhou1 1. Alibaba Group 2. UC Irvine 1 Zuozhi Wang
  • 2. Incremental Computation • Widely Used in Many Scenarios • Discretized Stream Processing • Progressive Data Warehouse • Late Data Processing • Incremental View Maintenance • … • Different Scenarios have Different Characteristics 2 Zuozhi Wang
  • 3. Total Income of the Day over Time Discretized Stream Processing Sales 1AM 2AM Sales …… 11PM 12 midnight Sales Sales …… 3 Zuozhi Wang Data Arrives Continuously with 1 hour Interval
  • 4. Total Income of the Day over Time Discretized Stream Processing Sales 1AM ∑ 2AM $100 Sales ∑ + …… 11PM 12 midnight Sales ∑ + Sales ∑ + …… $2300 …… $100 $200 $100 $2400 $100 4 …… Zuozhi Wang
  • 5. End-of-Day Report Data Warehouse Sales 1AM 2AM Sales …… 11PM 12 midnight Sales Sales …… Traditional Batch Computation Accumulate all data and compute at the end. Accumulate All Data 5 Resource Usage Zuozhi Wang
  • 6. End-of-Day Report Data Warehouse Sales 1AM 2AM Sales …… 11PM 12 midnight Sales Sales …… Problem: Many daily routine analytical queries run around the same time. High cluster resource load at midnight. Accumulate All Data 6 Resource Usage Zuozhi Wang
  • 7. End-of-Day Report Progressive Data Warehouse Sales 1AM 2AM Sales …… 11PM 12 midnight Sales Sales …… Incremental Computation: Update result as soon as new data arrives. Problem: Some jobs still execute in rush hours. …… 7 Cluster Usage Zuozhi Wang
  • 8. End-of-Day Report Progressive Data Warehouse Sales 1AM 2AM Sales …… 11PM 12 midnight Sales Sales …… Observation: User only cares about the last result. Intermediate incremental jobs can have more flexibility. …… 8 Cluster Usage Zuozhi Wang
  • 9. End-of-Day Report Progressive Data Warehouse Sales 1AM 2AM Sales …… 11PM 12 midnight Sales Sales …… 𝐶𝑜𝑠𝑡 𝑉𝑒𝑐𝑡𝑜𝑟: [ 0.9 0.3 …… 0.2 1.0 ] 9 Predictable Resource Usage Pattern Zuozhi Wang Assign a cost factor at each time point based on resource usage. The optimizer can choose to skip the execution at 1AM.
  • 10. Late Data Processing Sales 12 midnight 1AM …… 5AM 6AM Sales (late) Sales (late) Complete Result Operator1: Low Incremental Computation Overhead (filters, aggregations, ...) Operator2: High Incremental Computation Overhead (outer joins, nested queries, …) Partial Result 10 Zuozhi Wang Sales (late) …… Small amounts of late data arrive continuously.
  • 11. Late Data Processing Sales 12 midnight 1AM Sales (late) …… 5AM 6AM …… Sales (late) Sales (late) Complete Result …… Partial Result 11 Zuozhi Wang Only incrementally compute operator1. Compute operator2 (high overhead) only when the user needs the output result.
  • 12. 𝑇= [ ] k time points Tempura: A General Cost-Based Optimizer Framework for Incremental Data Processing • Incremental Computation in its Most General Form • Single Optimizer Framework for Many Scenarios 𝑄= [ ] Expected delivered result 𝐷= [ ] Input data at each time 𝐷1 T1 𝑄𝑢𝑒𝑟𝑦(𝐷1) 𝐷2 T2 Ø 𝐷𝑘 T𝑘 𝑄𝑢𝑒𝑟𝑦(𝐷𝑘) … 𝑃= [ ] Incremental Plan 𝐶= [ 𝑐1 𝑐2 𝑐𝑘 ] Cost function Inputs 12 (Optimizer Output) … Ø Zuozhi Wang
  • 13. How to do Incremental Computation? • Many Incremental Computation Algorithms • Retractable • Non-Retractable • Outer Join View Maintenance • Higher Order View Maintenance • … • Best Algorithm is Data Dependent 13 Zuozhi Wang
  • 14. How to do Incremental Computation? 14 Sales id profit o1 100 o2 100 o3 100 Returns id loss o1 10 o2 20 id income o1 -10 o2 -20 o3 100 Left Outer Join Zuozhi Wang gross 70 Sum SELECT SUM(income) AS gross FROM (SELECT sales.id, CASE WHEN loss IS NOT NULL THEN -loss ELSE profit END AS income FROM sales LEFT OUTER JOIN returns ON sales.id = returns.id ) AS sales_status Compute gross income based on profit from sales and loss from returns.
  • 15. Retractable Incremental Computation Returns Sales Returns id profit o1 100 o2 100 o3 100 id loss o1 10 id loss o2 20 id income o1 100 -10 o2 100 o3 100 id income o1 -10 o2 100 -20 o3 100 id income o1 -10 o2 -20 o3 100 t1 t2 t3 t4 15 Zuozhi Wang id income o1 100 o2 100 o3 100 gross 300 gross 190 gross 70 gross 70
  • 16. Non-Retractable Incremental Computation Returns Sales Returns id profit o1 100 o2 100 o3 100 id loss o1 10 id loss o2 20 id income o1 -10 id income o1 -10 o2 -20 id income o1 -10 o2 -20 o3 100 t1 t2 t3 t4 16 Zuozhi Wang id income gross gross -10 gross -30 gross 70
  • 17. Retractable vs Non-Retractable Algorithm • Retractable Incremental Computation • Needs to retract output whenever new return orders arrive. • Better when return orders are rare. (Less computation in the end) • Non-Retractable Incremental Computation • Holds more data to ensure no retractions. (Less computation overhead) • Better when return orders are frequent. • Let an optimizer automatically finds the best algorithm! Zuozhi Wang 17
  • 18. Tempura: Contributions 18 Zuozhi Wang • Propose a New Model for Incremental Computation • Provide a Rewrite-Rule Framework • Describes and unifies many incremental computation techniques • Integrate with a Volcano/Cascades-style Optimizer
  • 19. TVR-Based Incremental Processing • Time-Varying Relation (TVR) • Mapping from a time domain to relations • Snapshot and Delta id income 𝑜1 100 𝑜2 100 𝑜3 100 id income 𝑜1 -10 𝑜2 100 𝑜3 100 𝑜4 170 Snapshot(𝑡1) Snapshot(t2) id income # 𝑜1 100 -1 𝑜1 -10 +1 𝑜4 170 +1 Delta(t1, t2) t1 t2 +# → Merge Operation 19 Zuozhi Wang
  • 20. Query Optimization on TVR 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S 20 Zuozhi Wang Σ Σ(R ⋈ 𝑙𝑜 S) SELECT SUM(income) AS gross FROM (SELECT sales.id, CASE WHEN loss IS NOT NULL THEN -loss ELSE profit END AS income FROM sales LEFT OUTER JOIN returns ON sales.id = returns.id ) AS sales_status Each horizontal line is a TVR.
  • 21. TVR-Generating Rules 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S Snapshot(2) 21 Zuozhi Wang Σ Σ(R ⋈ 𝑙𝑜 S) Snapshot(1) Delta(1,2) 𝑆1 ⋈ 𝑙𝑜 𝑅1 Σ 𝑆2 𝑅2 ? ? ? ? ? ? With 2 time points: Expand operator tree into 3 trees: Snapshot(1), Delta(1,2), and Snapshot(2)
  • 22. TVR-Generating Rules 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S Snapshot(2) 22 Zuozhi Wang Σ Σ(R ⋈ 𝑙𝑜 S) Snapshot(1) Delta(1,2) 𝑆1 ⋈ 𝑙𝑜 𝑅1 Σ 𝑆2 𝑅2 Δ ⋈ 𝑙𝑜 ? ? ? Compute the delta of left outer join.
  • 23. TVR-Generating Rules 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S Snapshot(2) 23 Zuozhi Wang Σ Σ(R ⋈ 𝑙𝑜 S) Snapshot(1) Delta(1,2) 𝑆1 ⋈ 𝑙𝑜 𝑅1 Σ 𝑆2 𝑅2 Σ Δ ⋈ 𝑙𝑜 Compute the delta of aggregation.
  • 24. Intra-TVR Rules 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S Snapshot(2) 24 Zuozhi Wang Σ Σ(R ⋈ 𝑙𝑜 S) Snapshot(1) Delta(1,2) 𝑆1 ⋈ 𝑙𝑜 𝑅1 Σ 𝑆2 𝑅2 Σ Δ ⋈ 𝑙𝑜 +𝑈𝑛𝑖𝑜𝑛 How to merge snapshot and delta?
  • 25. Intra-TVR Rules 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S Snapshot(2) 25 Zuozhi Wang Σ Σ(R ⋈ 𝑙𝑜 S) Snapshot(1) Delta(1,2) 𝑆1 ⋈ 𝑙𝑜 𝑅1 Σ 𝑆2 𝑅2 Σ Δ ⋈ 𝑙𝑜 +𝑈𝑛𝑖𝑜𝑛 +𝑆𝑢𝑚 How to merge snapshot and delta?
  • 26. Inter-TVR Rules: Non-Retractable Algorithm 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S Snapshot(2) 26 Zuozhi Wang Σ Σ(R ⋈ 𝑙𝑜 S) Snapshot(1) Delta(1,2) ⋈ ⋈ 𝑙𝑎 𝑅 ⋈ 𝑆 𝑅 ⋈ 𝑙𝑎 𝑆 𝑈𝑛𝑖𝑜𝑛 𝑆1 ⋈ 𝑙𝑜 𝑅1 Σ ⋈ ⋈ 𝑙𝑎 𝑈𝑛𝑖𝑜𝑛 Decompose Left Outer Join into: Left Anti Join - Retractable Inner Join - Insertion Only
  • 27. Full Search Space 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S Snapshot(2) 27 Zuozhi Wang Σ Σ(R ⋈ 𝑙𝑜 S) Snapshot(1) Delta(1,2) ⋈ ⋈ 𝑙𝑎 𝑈𝑛𝑖𝑜𝑛 𝑅 ⋈ 𝑆 𝑅 ⋈ 𝑙𝑎 𝑆 Σ(R ⋈ 𝑙a S) Σ(R ⋈ S) Σ Σ 𝑆1 ⋈ 𝑙𝑜 𝑅1 Σ 𝑆2 𝑅2 Σ ⋈ ⋈ 𝑙𝑎 Δ ⋈ Δ ⋈ 𝑙𝑜 𝑈𝑛𝑖𝑜𝑛 Σ Σ 𝑈𝑛𝑖𝑜𝑛 Σ 𝑈𝑛𝑖𝑜𝑛 +𝑆𝑢𝑚 +𝑈𝑛𝑖𝑜𝑛 Any path that can reach the final output is a valid execution plan.
  • 28. Plan: Retractable Algorithm 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S Snapshot(2) 28 Zuozhi Wang Σ(R ⋈ 𝑙𝑜 S) Snapshot(1) Delta(1,2) ⋈ ⋈ 𝑙𝑎 𝑈𝑛𝑖𝑜𝑛 𝑅 ⋈ 𝑆 𝑅 ⋈ 𝑙𝑎 𝑆 Σ(R ⋈ 𝑙a S) Σ(R ⋈ S) Σ Σ 𝑆1 ⋈ 𝑙𝑜 𝑅1 Σ 𝑆2 𝑅2 Σ ⋈ ⋈ 𝑙𝑎 Δ ⋈ Δ ⋈ 𝑙𝑜 𝑈𝑛𝑖𝑜𝑛 Σ Σ 𝑈𝑛𝑖𝑜𝑛 Σ Σ 𝑈𝑛𝑖𝑜𝑛 +𝑆𝑢𝑚 +𝑈𝑛𝑖𝑜𝑛
  • 29. Plan: Non-Retractable Algorithm 𝑆2 ⋈ 𝑙𝑜 𝑅2 𝑆 𝑅 R ⋈ 𝑙𝑜 S Snapshot(2) 29 Zuozhi Wang Σ(R ⋈ 𝑙𝑜 S) Snapshot(1) Delta(1,2) ⋈ ⋈ 𝑙𝑎 𝑈𝑛𝑖𝑜𝑛 𝑅 ⋈ 𝑆 𝑅 ⋈ 𝑙𝑎 𝑆 Σ(R ⋈ 𝑙a S) Σ(R ⋈ S) Σ 𝑆1 ⋈ 𝑙𝑜 𝑅1 Σ 𝑆2 𝑅2 Σ ⋈ ⋈ 𝑙𝑎 Δ ⋈ Δ ⋈ 𝑙𝑜 𝑈𝑛𝑖𝑜𝑛 Σ Σ 𝑈𝑛𝑖𝑜𝑛 Σ Σ 𝑈𝑛𝑖𝑜𝑛 +𝑆𝑢𝑚 +𝑈𝑛𝑖𝑜𝑛 Σ
  • 30. Tempura: More Details in the Paper • Integration with Volcano/Cascades-style Optimizer • Speed up Optimization Process • How to choose optimal plan? • Dynamic re-optimization • Statistics Estimation • …… 30 Zuozhi Wang
  • 31. Experimental Study • TPC-DS • 4 basic incremental computation algorithms: • IM1 (Retractable Incremental Computation) • IM2 (Non-retractable Incremental Computation) • OJV (Outer-Join View Maintenance) • HOV (Higher-Order View Maintenance) • Tempura • Unify all 4 algorithms. 31 Zuozhi Wang
  • 32. Effectiveness 32 • 5 queries, 4 data arrival patterns, and 2 cost functions. • Different methods are good at different scenarios. • Tempura is always the best. Zuozhi Wang
  • 33. Query Optimization Performance • For 80% TPC-DS query: optimization finished within 3 seconds • Slower than traditional optimizers but can generate much better plans. 33 Zuozhi Wang
  • 34. Tempura • Open Source • Built on top of Apache Calcite • https://github.com/alibaba/cost-based-incremental-optimizer • https://issues.apache.org/jira/browse/CALCITE-4568 34 Zuozhi Wang

Editor's Notes