Instant Add Columns in MySQL

Slides:



Advertisements
Similar presentations
Data Definition Language (DDL)
Advertisements

Module 2: Database Architecture
5 Copyright © 2005, Oracle. All rights reserved. Managing Database Storage Structures.
Physical Database Design Chapter 5 G. Green 1. Agenda Purpose Activities Fields Records Files 2.
Lecture 10: The FAT, VFAT, and NTFS Filesystems 6/17/2003 CSCE 590 Summer 2003.
Backup and Recovery Part 1.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Database Administration TableSpace & Data File Management
Lecture 8 Index Organized Tables Clusters Index compression
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 9 Index Management.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
MySQL. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn The main subsystems in MySQL architecture The different storage.
Architecture Rajesh. Components of Database Engine.
1099 Why Use InterBase? Bill Todd The Database Group, Inc.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
CS4432: Database Systems II Record Representation 1.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents.
5 Copyright © 2005, Oracle. All rights reserved. Managing Database Storage Structures.
Week 4 Lecture 2 Advanced Table Management. Learning Objectives  Create tables with large object (LOB) columns and tables that are index-organized 
1/14/2005Yan Huang - CSCI5330 Database Implementation – Storage and File Structure Storage and File Structure II Some of the slides are from slides of.
6 Copyright © 2007, Oracle. All rights reserved. Managing Database Storage Structures.
Oracle 10g Database Administrator: Implementation and Administration Chapter 5 Basic Storage Concepts and Settings.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Chapter 3: Relational Databases
Physical Database Structure .
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
1 11g NEW FEATURES ByVIJAY. 2 AGENDA  RESULT CACHE  INVISIBLE INDEXES  READ ONLY TABLES  DDL WAIT OPTION  ADDING COLUMN TO A TABLE WITH DEFAULT VALUE.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
SQL Basics Review Reviewing what we’ve learned so far…….
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Notice: MySQL is a registered trademark of Sun Microsystems, Inc. MySQL Conference & Expo 2011 Michael “Monty” Widenius Oleksandr “Sanja”
1 Copyright 2008 Sun The World’s Most Popular Open Source Database Maria Engine Oscon, Michael Widenius MySQL Fellow.
Katowice,
Module 11: File Structure
The Basics of Data Manipulation
Database structure and space Management
MongoDB Er. Shiva K. Shrestha ME Computer, NCIT
Physical Database Design and Performance
Finding more space for your tight environment
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Database Management Systems (CS 564)
COMP 430 Intro. to Database Systems
B+ Tree.
Features of TMySQL/TSpider port into MariaDB
Oracle 10g Database Administrator: Implementation and Administration
Introduction of Week 6 Assignment Discussion
Sergey Vojtovich Software MariaDB Foundation
Lecture 10: Buffer Manager and File Organization
DATABASE MANAGEMENT SYSTEM
Traveling in time with SQL Server 2017
CS222P: Principles of Data Management Lecture #2 Heap Files, Page structure, Record formats Instructor: Chen Li.
The Relational Model Relational Data Model
SQL OVERVIEW DEFINING A SCHEMA
The Basics of Data Manipulation
Physical Database Structure .
Introduction to Database Systems
A Simple Two-Pass Assembler
Contents Preface I Introduction Lesson Objectives I-2
CS222/CS122C: Principles of Data Management Lecture #2 Storing Data: Disks and Files Instructor: Chen Li.
Data Definition Language
Charles Severance Single Table SQL.
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Lecture #2 Storing Data: Record/Page Formats Instructor: Chen Li.
SQL NOT NULL Constraint
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #03 Row/Column Stores, Heap Files, Buffer Manager, Catalogs Instructor: Chen Li.
SQL (Structured Query Language)
Presentation transcript:

Instant Add Columns in MySQL Vin Chen Tencent Game

Who I am Tencent Game DBA Team Profiles Contributor to Oracle MySQL Our Team has been serving game business for a few years. The mission of the DBA Team is to provide stable and efficient online storage services for Tencent Games. As the storage requirements from game business evolve, we keep extending features of our database and improving its performance. We spared no effort to provide reliable, scalable and performant database solutions. Profiles Team leader of Tencent DBA Developer Team Senior engineer of Tencent More than 7 years MySQL development Focus on open source storage solutions(MySQL, MongoDB, Redis, etc.) Contributor to Oracle MySQL Author of instant add columns

Background Why we need instant add columns High Frequency of Adding columns to BIG Table in Production Env Expensive operation with Adding columns to BIG table Causing downtime in the Game business “Instant add columns” in Tencent Game First released in July 2012, TenDB Based on mysql 5.5.24, and 5.6.24, 5.7.20 Contribution to Oracle MySQL in 2017 Merged and RELEASED in 8.0.12 dated July 2018

Implementation Row Format Dictionary DDL & DML Redo

Non-NULL Variable-Length Array Row Format Record Format Characteristic (Compact/Dynamic) Storage order is the same as definition order (except primary key) NULL field not stored. A bitmap is used to indicate which fields are NULL. Field number of a record is index->n_fields Non-NULL Variable-Length Array Nullable Bitmap Record Extra Bytes Record Header Primary Key Transaction ID Roll Ptr Other not null Fields Record Ptr n_owned+Info Bits (4Bits + 4Bits, 1 Byte) Status + Heap No (3Bits + 13Bits, 2 Bytes) Next Ptr (2 Bytes)

Row Format Record Format Changes(Compact/Dynamic) Field Count: the field count of the record(≤ index.n_fields) Forward compatibility Info Bits(higher 4 bits, 2 reserved bits) REC_INFO_MIN_REC_FLAG 0x10 REC_INFO_DELETED_FLAG 0x20 REC_INFO_INSTANT_FLAG 0x80 Only leaf pages of cluster index are affected Record Header Primary Key Transaction ID Roll Ptr Other not null Fields /* The 0x40UL can also be used in the future */ /* The instant ADD COLUMN flag. When it is set to 1, it means this record was inserted/updated after an instant ADD COLUMN. */ Record Ptr Non-NULL Variable-Length Array Nullable Bitmap Record Extra Bytes Non-NULL Variable-Length Array Nullable Bitmap Field Count Record Extra Bytes n_owned+Info Bits (4Bits + 4Bits, 1 Byte) Status + Heap No (3Bits + 13Bits, 2 Bytes) Next Ptr (2 Bytes)

Row Format Record Format Changes(Compact/Dynamic) If REC_INFO_INSTANT_FLAG is set, store the “Field count” using a variable-length encoding of 2 bytes REC_INFO_INSTANT_FLAG would be set for insert/update after instant adding columns. If REC_INFO_INSTANT_FLAG is zero, there are two possibilities: Instant adding columns have never happened in this table. The record is inserted or updated before the first time of instant adding columns. n_core_fields: The field count before the first time instant adding columns happened.

Dictionary New metadata Store n_core_fields Store default value When the first time instant adding columns happens, we need to store the original field count of a table Update sys_tables set (mix_len = mix_len | n_core_fields << 16) where table = :table_id; Store default value A new system table sys_columns_added Dictionary loading When loading a table from dictionary n_core_fields = sys_table.mix_len >> 16 cluster_index.n_core_fields = n_core_fields > 0 ? n_core_fields : cluster_index.n_fields. dict_load_sys_columns_added() after dict_load_sys_columns()

Dictionary Examples MySQL 8 TenDB Use test; create table t1(id int primary key, c1 int); insert into t1 values(1,1); alter table t1 add column d1 varchar(20) not null default 'abc‘, algorithm=‘instant’; alter table t1 alter column d1 set default 'bcd'; Examples MySQL 8 TenDB The number of columns when the table undergoes first instant ADD COLUMN and all default value of newly added columns are stored in the data dictionary. These two pieces of information are stored in se_private_data column of the data dictionary tables.

DDL Key Logic Create table: no behavior change Alter table: Instant adding column No need to copy data Insert or change the related metadata Other: no behavior change Drop/Truncate table: Delete the related metadata Update sys_tables set (mix_len = mix_len | n_core_fields << 16) where table = :table_id; (First time) Insert into sys_columns values(…); Insert into sys_columns_added values(:table_id, :pos, <default value>);

DML Key Logic insert: delete: update: Before the first time Instant adding columns happened, no behavior change Otherwise, REC_INFO_INSTANT_FLAG would be set. delete: No behavior change, just mark the delete flag; update: For updating old version record, if the added columns changed or the length of column changed, it will use non-inplace update(delete + insert) Otherwise, no behavior change.

DML Key Logic select:

Redo Redo a mix of physical and logical operations n_core_fields need to be stored in dict object of redo log default values is useless for recovery

Summary Advantage Limitations Change metadata only, very fast No need to copy data No need to take twice the space Forward compatibility with MySQL Limitations Only support adding columns in one statement, that is if there are other non-INSTANT operations in the same statement, it can’t be done instantly Only support adding columns at last, not in the middle of existing columns Not support COMPRESSED row format, which is seldom used Not support a table which already has any fulltext index Not support any table residing in DD tablespace Not support temporary table(it goes with COPY)

Mass production environment deployment MySQL Usage In Tencent Games Load Test Functional Test Grayscale deployment Mass production environment deployment 400+ Games 10,000+ Machines 20,000+ Instances 20+ FailOver Per Day 17 Table DDL Per week All instances use TenDB, which base on Oracle MySQL 5.5/5.6/5.7 Our Plan of Deploying MySQL 8.0

Thank you for your patience! vinchen@tencent.com