Leanpub Header

Skip to main content

How Query Engines Work

An Introductory Guide

This book provides an introduction to the high-level concepts behind query engines and walks through all aspects of building a fully working SQL query engine in Kotlin.

Please note that this is a short introductory book (around 100 pages). Around 4% of readers ask for a refund because they were expecting something far more comprehensive.

Minimum price

$19.99

$29.99

You pay

$29.99

Author earns

$23.99
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
815
Readers
105
Pages
20,188Words
About

About

About the Book

Andy Grove has worked on numerous projects that required custom query engines or integrations with existing query engines and this book provides an approachable introduction to the topic.

The book provides an introduction to the high-level concepts behind query engines and walks through every step of building a SQL query engine in Kotlin with full source code available in a companion github repository. Most of the book is programming language agnostic and Kotlin was chosen for the code examples due to its conciseness and readability. The concepts should be easily translatable to other programming languages.

Andy is a PMC member of Apache Arrow where he donated the initial Rust implementation and later donated the DataFusion query engine.

Please note that this is a short introductory book (around 100 pages). Around 4% of readers ask for a refund because they were expecting something far more comprehensive.

Author

About the Author

Andy Grove

Andy Grove is a PMC member of Apache Arrow where he donated the initial Rust implementation and also donated the DataFusion query engine.

Leanpub Podcast

Episode 194

An Interview with Andy Grove

Contents

Table of Contents

Acknowledgments

Introduction

  1. Feedback

1What Is a Query Engine?

  1. 1.1Why Are Query Engines Popular?
  2. 1.2What This Book Covers
  3. 1.3Source Code
  4. 1.4Why Kotlin?

2Apache Arrow

  1. 2.1Arrow Memory Model
  2. 2.2Inter-Process Communication (IPC)
  3. 2.3Compute Kernels
  4. 2.4Arrow Flight Protocol
  5. 2.5Arrow Flight SQL
  6. 2.6Query Engines

3Choosing a Type System

  1. Source code
  2. 3.1Row-Based or Columnar?
  3. 3.2Interoperability
  4. 3.3Type System

4Data Sources

  1. Source code
  2. 4.1Data Source Interface
  3. 4.2Data Source Examples

5Logical Plans & Expressions

  1. Source code
  2. 5.1Printing Logical Plans
  3. 5.2Serialization
  4. 5.3Logical Expressions
  5. 5.4Column Expressions
  6. 5.5Literal Expressions
  7. 5.6Binary Expressions
  8. 5.7Comparison Expressions
  9. 5.8Boolean Expressions
  10. 5.9Math Expressions
  11. 5.10Aggregate Expressions
  12. 5.11Logical Plans
  13. 5.12Scan
  14. 5.13Projection
  15. 5.14Selection (also known as Filter)
  16. 5.15Aggregate

6Building Logical Plans

  1. Source code
  2. 6.1Building Logical Plans The Hard Way
  3. 6.2Building Logical Plans using DataFrames

7Physical Plans & Expressions

  1. Source code
  2. 7.1Physical Expressions
  3. 7.2Column Expressions
  4. 7.3Literal Expressions
  5. 7.4Binary Expressions
  6. 7.5Comparison Expressions
  7. 7.6Math Expressions
  8. 7.7Aggregate Expressions
  9. 7.8Physical Plans
  10. 7.9Scan
  11. 7.10Projection
  12. 7.11Selection (also known as Filter)
  13. 7.12Hash Aggregate
  14. 7.13Joins
  15. 7.14Subqueries
  16. 7.15Creating Physical Plans

8Query Planner

  1. Source code
  2. 8.1Translating Logical Expressions
  3. 8.2Column Expressions
  4. 8.3Literal Expressions
  5. 8.4Binary Expressions
  6. 8.5Translating Logical Plans
  7. 8.6Scan
  8. 8.7Projection
  9. 8.8Selection (also known as Filter)
  10. 8.9Aggregate

9Query Optimizations

  1. Source code
  2. 9.1Rule-Based Optimizations
  3. 9.2Cost-Based Optimizations

10Query Execution

  1. 10.1Apache Spark Example
  2. Source code
  3. 10.2KQuery Examples
  4. Source code
  5. 10.3Removing The Query Optimizer

11SQL Support

  1. Source code
  2. 11.1Tokenizer
  3. 11.2Pratt Parser
  4. 11.3Parsing SQL Expressions
  5. 11.4Parsing a SELECT statement
  6. 11.5SQL Query Planner
  7. 11.6Translating SQL Expressions
  8. 11.7Planning SELECT
  9. 11.8Planning for Aggregate Queries

12Parallel Query Execution

  1. 12.1Combining Results
  2. 12.2Smarter Partitioning
  3. 12.3Partition Keys
  4. 12.4Parallel Joins

13Distributed Query Execution

  1. 13.1Embarrassingly Parallel Operators
  2. 13.2Distributed Aggregates
  3. 13.3Distributed Joins
  4. 13.4Distributed Query Scheduling
  5. 13.5Producing a Distributed Query Plan
  6. 13.6Serializing a Query Plan
  7. 13.7Serializing Data
  8. 13.8Choosing a Protocol
  9. 13.9Streaming
  10. 13.10Custom Code
  11. 13.11Distributed Query Optimizations

14Testing

  1. 14.1Unit Testing
  2. 14.2Integration Testing
  3. 14.3Fuzzing

15Benchmarks

  1. 15.1Measuring Performance
  2. 15.2Measuring Scalability
  3. 15.3Concurrency
  4. 15.4Automation
  5. 15.5Comparing Benchmarks
  6. 15.6Publishing Benchmark Results
  7. 15.7Transaction Processing Council (TPC) Benchmarks

Further Resources

  1. Open-Source Projects
  2. YouTube
  3. Sample Data

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub