【SQL开源代码栏目提醒】:本文主要为网学会员提供“MySQL源码剖析 - 技术总结”,希望对需要MySQL源码剖析 - 技术总结网友有所帮助,学习一下!
Understanding MySQL Internals Other resources from O’ReillyRelated titles The Art of SQL Optimizing Oracle Database in Depth Performance High Performance MySQL The Relational Database Learning MySQL Dictionary Learning SQL SQL Cookbook MySQL Cookbook SQL Tuning MySQL Stored Procedure Understanding the Linux Programming Kernel oreilly.com oreilly.com is more than a complete catalog of O’Reilly books. You’ll also find links to news events articles weblogs sample chapters and code examples. oreillynet.com is the essential portal for developers interested in open and emerging technologies including new platforms pro- gramming languages and operating systems. Conferences O’Reilly brings diverse innovators together to nurture the ideas that spark revolutionary industries. We specialize in document- ing the latest tools and systems translating the innovator’s knowledge into useful skills for those in the trenches. Visit conferences.oreilly.com for our upcoming events. Safari Bookshelf safari.oreilly.com is the premier online refer- ence library for programmers and IT professionals. Conduct searches across more than 1000 books. Subscribers can zero in on answers to time-critical questions in a matter of seconds. Read the books on your Bookshelf from cover to cover or sim- ply flip to the page you need. Try it today for free. Understanding MySQL Internals Sasha PachevBeijing Cambridge Farnham Kln Paris Sebastopol Taipei TokyoUnderstanding MySQL Internalsby Sasha PachevCopyright 2007 O’Reilly Media Inc. All rights reserved.Printed in the United States of America.Published by O’Reilly Media Inc. 1005 Gravenstein Highway North Sebastopol CA 95472.O’Reilly books may be purchased for educational business or sales promotional use. Online editionsare also available for most titles safari.oreilly.com. For more information contact ourcorporate/institutional sales department: 800 998-9938 or corporateoreilly.com.Editor: Andy Oram Indexer: Johnna VanHoose DinseProduction Editor: Rachel Monaghan Cover Designer: Karen MontgomeryCopyeditor: Derek Di Matteo Interior Designer: David FutatoProofreader: Rachel Monaghan Illustrators: Robert Romano and Jessamyn ReadPrinting History: April 2007: First Edition.Nutshell Handbook the Nutshell Handbook logo and the O’Reilly logo are registered trademarks ofO’Reilly Media Inc. Understanding MySQL Internals the image of a banded broadbill and related tradedress are trademarks of O’Reilly Media Inc.Many of the designations used by manufacturers and sellers to distinguish their products are claimed astrademarks. Where those designations appear in this book and O’Reilly Media Inc. was aware of atrademark claim the designations have been printed in caps or initial caps.While every precaution has been taken in the preparation of this book the publisher and author assumeno responsibility for errors or omissions or for damages resulting from the use of the informationcontained herein. This book uses RepKover a durable and flexible lay-flat binding. ISBN-10: 0-596-00957-7ISBN-13: 978-0-596-00957-1CThis book is dedicated to my wife Sarah and my children Benjamin Jennifer Julia Joseph and Jacob. Table of ContentsPreface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. MySQL History and Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 MySQL History 1 MySQL Architecture 4 2. Nuts and Bolts of Working with the MySQL Source Code . . . . . . . . . . . . . . . . 19 Unix Shell 19 BitKeeper 19 Preparing the System to Build MySQL from BitKeeper Tree 22 Building MySQL from BitKeeper Tree 24 Building from Source Distribution 25 Installing MySQL into a System Directory 26 Source Code Directory Layout 27 Preparing the System to Run MySQL in a Debugger 28 Debugger-Guided Source Tour 29 Basics of Working with gdb 30 Finding Things in the Source 33 Interesting Breakpoints and Variables 34 Making a Source Modification 36 Coding Guidelines 37 Keeping Your BitKeeper Repository Up to Date 39 Submitting a Patch 40 vii 3. Core Classes Structures Variables and APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 THD 41 NET 46 TABLE 48 Field 51 Utility API Calls 54 Preprocessor Macros 57 Global Variables 59 4. Client/Server Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Protocol Overview 62 Packet Format 62 Relationship Between MySQL Protocol and OS Layer 63 Authenticating Handshake 64 Command Packet 69 Server Responses 74 5. Conguration Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Configuration Variables Tutorial 80 Interesting Aspects of Specific Configuration Variables 88 6. Thread-Based Request Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Threads Versus Processes 107 Implementation of Request Handling 109 Thread Programming Issues 113 7. The Storage Engine Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 The handler Class 120 Adding a Custom Storage Engine to MySQL 136 8. Concurrent Access and Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Table Lock Manager 162 9. Parser and Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Parser 167 Optimizer 170viii Table of Contents 10. Storage Engines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 Shared Aspects of Architecture 195 InnoDB 202 Memory Heap 204 MyISAM Merge 205 NDB 205 Archive 206 Federated 207 11. Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 Overview of Transactional Storage Engine Implementation 208 Implementing the handler Subclass 209 Defining the handlerton 212 Working with the Query Cache 213 Working with the Replication Binary Log 214 Avoiding Deadlocks 214 12. Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Overview 216 Statement-Based Versus Row-Based Replication 217 Two-Threaded Slave 218 Multi-Master 219 SQL Commands to Help Understand Replication 220 Binary Log Format 223 Creating a Custom Replication Utility 227Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Table of Contents ix Preface 1In the summer of 2003 somebody on the MySQL mailing list proposed a book aboutMySQL internals. As I read the email I realized that I had the background to writesuch a book but I had just finished writing my first book and was not looking for-ward to writing another. I tried to talk myself out of the responsibility saying tomyself nobody would ever publish a book so technical and specialized. There simplywould not be enough of an audience for it.Then I thought of Understanding the Linux Kernel and Linux Device Drivers byO’Reilly. That took away my excuse. I realized the door was open and I was stand-ing in the doorway but my inertia was keeping something good from happening. Ithought about a passage in the Book of Mormon that says “a natural man is anenemy to God” and the principle behind it. If you drift along seeking only the plea-sure of the moment and staying safely within your natural comfort zone you do notaccomplish much. Good things happen when you push yourself outside of yourcomfort zone doing what is difficult but what you know deep inside is the rightthing to do. I wrote an email with a proposal to O’Reilly.Interestingly enough my editor happened to be Andy Oram who also participatedin the publication of Understanding the Linux Kernel and Linux Device Drivers. Heand I worked together on this book and I appreciate his help very much. I felt thathis strengths very well compensated for my weaknesses.The book presented a number of challenges. Writing about the internals of an appli-cation means approaching it as a developer rather than just a user or an administra-tor. It requires a deeper level of understanding. Although I had worked on theMySQL source code extensively I found myself doing a lot of research to figure outthe gory details of algorithms the purposes of functions and classes the reasons forcertain decisions and other matters relevant to this book. In addition as I was writ-ing the book MySQL developers were writing new code. It was not easy to keep up.And while the book was being written I had to do other .上一篇:几种注册ODBC数据源的方法