Memory-Efficient Search Trees for Database Management Systems
Total Page:16
File Type:pdf, Size:1020Kb
Memory-Ecient Search Trees for Database Management Systems Huanchen Zhang CMU-CS-20-101 Febuary 2020 Computer Science Department School of Computer Science Carnegie Mellon University Pisburgh, PA 15213 esis Committee: David G. Andersen, Chair Michael Kaminsky Andrew Pavlo Kimberly Keeton, Hewle-Packard Labs Submied in partial fulllment of the requirements for the degree of Doctor of Philosophy. Copyright © 2020 Huanchen Zhang is research was sponsored by the National Science Foundation under grant number CNS-1314721, Intel ISTC-CC, Intel ISTC-VCC, and the VMware University Research Fund. e views and conclusions con- tained in this document are those of the author and should not be interpreted as representing the ocial policies, either expressed or implied, of any sponsoring institution, the U.S. government or any other entity. Keywords: search tree, memory-eciency, database management system, indexing, range ltering, succinct data structure, key compression To my son. iv Abstract e growing cost gap between DRAM and storage together with increas- ing database sizes means that database management systems (DBMSs) now operate with a lower memory to storage size ratio than before. On the other hand, modern DBMSs rely on in-memory search trees (e.g., indexes and l- ters) to achieve high throughput and low latency. ese search trees, how- ever, consume a large portion of the total memory available to the DBMS. is dissertation seeks to address the challenge of building compact yet fast in-memory search trees to allow more ecient use of memory in data pro- cessing systems. We rst present techniques to obtain maximum compres- sion on fast read-optimized search trees. We identied sources of memory waste in existing trees and designed new succinct data structures to reduce the memory to the theoretical limit. We then introduce ways to amortize the cost of modifying static data structures with bounded and modest cost in performance and space. Finally, we approach the search tree compression problem from an orthogonal direction by building a fast string compressor that can encode arbitrary input keys while preserving their order. Together, these three pieces form a practical recipe for achieving memory-eciency in search trees and in DBMSs. vi Acknowledgments I feel very fortunate for having the opportunity to work with the “Big Four” of my advising team: David G. Andersen, Michael Kaminsky, Andrew Pavlo, and Kimberly Keeton. is thesis would not have been possible without them. I thank my advisor Dave for believing in me when I stumbled during the journey. His constant support in and beyond research has helped me overcome the hard times. Dave taught me not only the knowledge necessary for writing this thesis but also the mindset of being a qualied researcher. e best part of my time in graduate school was to gure out fun data structure problems with Dave on the whiteboard. Dave introduced me to the eld of Succinct Data Structures, which eventually becomes a core component of this thesis. I am also thankful to Michael for shepherding my research with rigorousness. e quality of this thesis would be much compromised without his thoughtful questions and suggestions. I am very grateful to Andy for leading me to the lovely database community where I nd my research passion. I thank Andy for giving me countless pieces of useful advice on research and career, as well as leing me kick a yoga ball to his crotch. My debt to Kim goes beyond her being an excellent internship and research mentor. I view her as a role model, and I cherish our friendship. Many collaborators have contributed to the content of this thesis. I thank Lin Ma and Rui Shen for their eort in evaluating the Hybrid Index. I thank Hyeontaek Lim and Viktor Leis for oering valuable input on the SuRF project. I thank Xiaoxuan Liu for implementing the ALM algorithm in HOPE and for being the coolest master student I have ever mentored. I would like to thank my colleagues at CMU for making my graduate school experience enriching and fun. I thank Greg Ganger, Rashmi Vinayak, Justine Sherry, and Bryan Parno for helping me with my writing and speaking skills. I thank Anuj Kalia, Conglong Li, Prashanth Menon, and Jack Kosaian for making our oce “legendary”. I thank the members and friends of the FAWN group – Hyeontaek Lim, Dong Zhou, Anuj Kalia, Conglong Li, Sol Boucher, Angela Jiang, omas Kim, Chris Canel, Giulio Zhou, Daniel Wong, and Charlie Garrod – and other fellow students in PDL– Abutalib Aghayev, Joy Arulraj, Ma Butrovich, Dominic Chen, Andrew Chung, Henggang Cui, Aaron Harlap, Kevin Hsieh, Saurabh Kadekodi, Rajat Kateja, Michael Kuchnik, Yixin Luo, Charles McGuey, Jun Woo Park, Kai Ren, Dana Van Aken, Ziqi Wang, Jinliang Wei, Lin Xiao, Jason Yang, Michael Zhang, and Qing Zheng. I thank Deb Cavlovich, Angy Malloy, Karen Lindenfelser, and Joan Digney for their greatest administrative support throughout my Ph.D. study. I also want to thank my good friends Zhuo Chen, Ziqiang Feng, Yan Gu, Wenlu Hu, Han Lai, Conglong Li, Danyang Li, Julian Shun, Yihan Sun, Junjue Wang, Xiaocheng Zhang and many others for making my life in Pisburgh colorful. I am especially grateful to my wife Yingjie Zhang who has always stood by my side, shar- ing my laughter and tears. My parents Suping Zhu and Jiming Zhang have made great sacri- ces to help me get this far. I could not have asked for a beer family. Finally, I am excited to have a wonderful new life coming and joining my journey. I dedicate this thesis to him. viii Contents 1 Introduction 1 1.1 Existing Solutions: Performance vs. Space . .2 1.2 A Pareto Improvement . .3 1.3 esis Statement and Contributions . .6 2 Guidelines for Structural Compression: e Dynamic-to-Static Rules 9 2.1 Example Data Structures . 10 2.2 Rule #1: Compaction . 12 2.3 Rule #2: Structural Reduction . 14 2.4 Rule #3: Compression . 16 2.5 Evaluation . 16 3 Reducing Space to the eoretical Limit: Fast Succinct Tries 21 3.1 Background: Succinct Trees and LOUDS . 22 3.2 LOUDS-Dense . 23 3.3 LOUDS-Sparse . 25 3.4 LOUDS-DS and Operations . 26 3.5 Space and Performance Analysis . 28 3.6 Optimizations . 29 3.7 Evaluation . 31 3.7.1 FST vs. Pointer-based Indexes . 32 3.7.2 FST vs. Other Succinct Tries . 33 ix 3.7.3 Performance Breakdown . 35 3.7.4 Trade-os between LOUDS-Dense and LOUDS-Sparse . 36 4 Application: Succinct Range Filters 37 4.1 Design . 38 4.1.1 Basic SuRF . 38 4.1.2 SuRF with Hashed Key Suxes . 40 4.1.3 SuRF with Real Key Suxes . 40 4.1.4 SuRF with Mixed Key Suxes . 41 4.1.5 Operations . 41 4.2 Example Application: RocksDB . 42 4.3 Microbenchmarks . 46 4.3.1 False Positive Rate . 46 4.3.2 Performance . 49 4.3.3 Build Time . 50 4.3.4 Scalability . 50 4.3.5 Comparing ARF and SuRF . 51 4.4 System Evaluation . 52 4.5 e eory-Practice Gaps . 56 5 Supporting Dynamic Operations Eciently: e Hybrid Index 59 5.1 e Dual-Stage Architecture . 60 5.2 Merge . 62 5.2.1 Merge Algorithm . 63 5.2.2 Merge Strategy . 64 5.3 Microbenchmark . 66 5.3.1 Experiment Setup & Benchmarks . 66 5.3.2 Hybrid Indexes vs. Originals . 67 5.3.3 Merge Strategies & Overhead . 71 5.3.4 Auxiliary Structures . 73 x 5.3.5 Secondary Indexes Evaluation . 74 5.4 Full DBMS Evaluation . 75 5.4.1 H-Store Overview . 75 5.4.2 Benchmarks . 76 5.4.3 In-Memory Workloads . 77 5.4.4 Larger-than-Memory Workloads . 79 6 Compressing Input Keys: e High-Speed Order-Preserving Encoder 83 6.1 Compression Model . 84 6.1.1 e String Axis Model . 84 6.1.2 Exploiting Entropy . 86 6.1.3 Compression Schemes . 88 6.2 HOPE . 91 6.2.1 Overview . 91 6.2.2 Implementation . 93 6.3 Integration . 96 6.4 HOPE Microbenchmarks . 99 6.4.1 Sample Size Sensitivity Test . 100 6.4.2 Performance & Ecacy . 102 6.4.3 Dictionary Build Time . 104 6.4.4 Batch Encoding . 105 6.4.5 Updates and Key Distribution Changes . 105 6.5 Search Tree Evaluation . 106 6.5.1 Workload . 108 6.5.2 YCSB Evaluation . 109 7 Related Work 115 7.1 Succinct Tree Representations . 116 7.2 Range Filtering . 117 7.3 Log-Structured Storage . 118 xi 7.4 Hybrid Index and Other Compression Techniques for Main-memory Databases . 118 7.5 Key Compression in Search Trees . 121 8 Conclusion and Future Work 123 Bibliography 127 xii List of Figures 1.1 A Pareto Improvement – e goal of this thesis is to advance the state of the art in the performance-space trade-o when building in-memory search trees. .4 1.2 Steps Towards Memory-Eciency – e main contribution of this thesis is a new recipe for designing memory-eciency yet high- performance search trees from existing solutions. e body of the thesis is organized according to these steps. .6 2.1 Masstree – Masstree adopts a multi-structure design, where a group of xed-height B+trees conceptually forms a trie. 11 2.2 ART Node Layouts – Organization of the ART index nodes. In Layout 1, the key and child arrays have the same length and the child pointers are stored at the corresponding key positions. In Layout 2, the current key byte is used to index into the child array, which contains osets/indexes to the child array. e child array stores the pointers.