Sergey Vojtovich Software MariaDB Foundation

Slides:



Advertisements
Similar presentations
Parallel Universe Fast Parallel MySQL Server. Target Markets Database Servers Data Warehouse Servers Data Analytics Servers.
Advertisements

Drop in replacement of MySQL. Agenda MySQL branch GPL licence Maria storage engine Virtual columns FederatedX storage engine PBXT storage engine XtraDB.
Project Management Database and SQL Server Katmai New Features Qingsong Yao
Data - Information - Knowledge
CSCI 4550/8556 Computer Networks Comer, Chapter 7: Packets, Frames, And Error Detection.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Oracle Database Administration Database files Logical database structures.
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 9 Index Management.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
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.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
The HDF Group HDF5 Datasets and I/O Dataset storage and its effect on performance May 30-31, 2012HDF5 Workshop at PSI 1.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
1 HDF5 Life cycle of data Boeing September 19, 2006.
© All rights reserved. U.S International Tech Support
Advanced Web 2012 Lecture 3 Sean Costain What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
GLOBEX INFOTEK Copyright © 2013 Dr. Emelda Ntinglet-DavisSYSTEMS ANALYSIS AND DESIGN METHODSINTRODUCTORY SESSION EFFECTIVE DATABASE DESIGN for BEGINNERS.
MySQL Gubbins Richard Sinclair HepSysMan – 11/05/2012.
MySQL Importing and creating a database. CSV (Comma Separated Values) file CSV = Comma Separated Values – they are simple text files containing data which.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
NTFS Filing System CHAPTER 9. New Technology File System (NTFS) Started with Window NT in 1993, Windows XP, 2000, Server 2003, 2008, and Window 7 also.
IMPACT OF ORC COMPRESSION BUFFER SIZE Prasanth Jayachandran Member of Technical Staff – Apache Hive.
Copyright © 2010 The HDF Group. All Rights Reserved1 Data Storage and I/O in HDF5.
Notice: MySQL is a registered trademark of Sun Microsystems, Inc. MySQL Conference & Expo 2011 Michael “Monty” Widenius Oleksandr “Sanja”
Partitioning Sheeri K. Cabral Database Administrator The Pythian Group, January 12, 2009.
Hadoop file format studies in IT-DB Analytics WG meeting 20 th of May, 2015 Daniel Lanza, IT-DB.
3 A Guide to MySQL.
CPSC-310 Database Systems
Module 11: File Structure
WWW and HTTP King Fahd University of Petroleum & Minerals
Managing Tables, Data Integrity, Constraints by Adrienne Watt
INLS 623– Database Systems II– File Structures, Indexing, and Hashing
Data Definition and Data Types
CHP - 9 File Structures.
Stored Procedures.
Updating SF-Tree Speaker: Ho Wai Shing.
Module 2: Creating Data Types and Tables
System Programming and administration
Importing and Exporting Data with MySQL
Dynamic SQL: Writing Efficient Queries on the Fly
Introduction to Web programming
Data Definition and Data Types
Database Management Systems (CS 564)
Data Modeling and Database Design
Features of TMySQL/TSpider port into MariaDB
C++ for Engineers and Scientists Second Edition
Lecture 10: Buffer Manager and File Organization
Instant Add Columns in MySQL
DATABASE MANAGEMENT SYSTEM
CS222P: Principles of Data Management Lecture #2 Heap Files, Page structure, Record formats Instructor: Chen Li.
Database systems Lecture 2 – Data Types
Dynamic SQL: Writing Efficient Queries on the Fly
The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited)
File Storage and Indexing
CS222/CS122C: Principles of Data Management Lecture #2 Storing Data: Disks and Files Instructor: Chen Li.
Large Object Datatypes
Real-World File Structures
An introduction to systems programming
Database Instructor: Bei Kang.
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

Sergey Vojtovich Software Engineer @ MariaDB Foundation The Foundation exists to secure the long-term success and sustainability of the MariaDB project, and the foundation's mission includes being a hub for collaboration around MariaDB. The foundation also has the necessary governance in place so that it can facilitate collaboration, even of parties that have conflicting interests. Column compression Sergey Vojtovich Software Engineer @ MariaDB Foundation * *

Implementations Alibaba Percona Tencent MariaDB

Syntax Alibaba Percona Tencent MariaDB CREATE TABLE t1(a BLOB COLUMN_FORMAT COMPRESSED) Percona CREATE TABLE t1(a BLOB COLUMN_FORMAT COMPRESSED [WITH COMPRESSION_DICTIONARY dict]) CREATE COMPRESSION_DICTIONARY [IF NOT EXISTS] dict(text|variable) DROP COMPRESSION_DICTIONARY [IF EXISTS] dict Tencent CREATE TABLE t1(a BLOB COMPRESSED) MariaDB CREATE TABLE t1(a BLOB COMPRESSED[=compression_method])

Availability All implementations have column compression available by default, no special compilation flags or runtime configuration needed.

Data types All implementations support: BLOB and TEXT VARCHAR and VARBINARY MariaDB> CREATE TABLE t1(a BLOB COMPRESSED); MariaDB> CREATE TABLE t1(a INT COMPRESSED); ERROR 42000: Incorrect column specifier for column 'a'

Storage engines MariaDB: storage engine independent Note: CSV stores data uncompressed MariaDB> CREATE TABLE t1(a BLOB COMPRESSED) ENGINE=InnoDB; MariaDB> CREATE TABLE t1(a BLOB COMPRESSED) ENGINE=MyISAM; ... AliSQL, Percona and Tencent: InnoDB only Tencent> CREATE TABLE t1(a BLOB COMPRESSED) ENGINE=InnoDB; Tencent> CREATE TABLE t1(a BLOB COMPRESSED) ENGINE=MyISAM; ERROR HY000: Field 'a' can not have compressed property in this enginess

Compression methods All implementations support only one compression method: deflate (zlib).

Indexes All implementations do not support indexes over compressed columns. MariaDB> CREATE TABLE t1(a BLOB COMPRESSED, KEY(a(10))); ERROR HY000: Compressed column 'a' can't be used in key specification

Status variables Alibaba Percona Tencent MariaDB Innodb_column_compressed // incremented when compressed data is written Innodb_column_decompressed // or read, global counters (scalability?) Percona Create_compression_dictionary Drop_compression_dictionary Tencent N/A MariaDB Column_compressions // similar to Alibaba, but only incremented if data Column_decompressions // is actually compressed/decompressed, status counter

System variables Alibaba Percona Tencent MariaDB innodb_rds_column_zip_threshold=1-ULONG_MAX (default: 96) Percona innodb_compressed_columns_threshold=1-ULONG_MAX (default: 96) Tencent field_compress_min_len=1-ULONG_MAX (default: 128) MariaDB column_compression_threshold=0-UINT_MAX (default: 100) Data shorter than threshold is stored uncompressed. Affects compression only.

System variables Alibaba Percona Tencent MariaDB innodb_rds_column_compression_level=0-9 (default: 6) Percona innodb_compressed_columns_zip_level=0-9 (default: 6) Tencent N/A MariaDB column_compression_zlib_level=0-9 (default: 6) zlib compression level (1 gives best speed, 9 gives best compression). Affects compression only.

System variables Alibaba Percona Tencent MariaDB innodb_rds_column_zlib_wrap=ON|OFF (default: ON) Percona N/A Tencent N/A MariaDB column_compression_zlib_wrap=ON|OFF (default: OFF) Generate zlib header and trailer and compute adler32 check value. Affects compression only.

System variables Alibaba Percona Tencent MariaDB innodb_rds_column_zlib_strategy=0-4 (0) Percona N/A Tencent N/A MariaDB column_compression_zlib_strategy=DEFAULT_STRATEGY|FILTERED|HUFFMAN_ONLY|RLE|FIXED (DEFAULT_STRATEGY) The strategy parameter is used to tune the compression algorithm. Affects compression only.

System variables Alibaba Percona Tencent MariaDB innodb_rds_column_zip_mem_use_heap=ON|OFF (default: OFF) Percona N/A Tencent N/A MariaDB N/A Allocate memory from prebuilt->compress_heap for zlib.

System variables In all implementations it is possible to adjust compression settings for individual rows MariaDB> CREATE TABLE t1(a BLOB COMPRESSED); MariaDB> SET column_compression_threshold=2000; MariaDB> INSERT INTO t1 VALUES(REPEAT('a', 1000)); MariaDB> SET column_compression_threshold=200;

Field length All implementations set field length limit on uncompressed data (not compressed) MariaDB> CREATE TABLE t1(a TINYBLOB COMPRESSED); MariaDB> INSERT INTO t1 VALUES(REPEAT('a', 1000)); ERROR 1406 (22001): Data too long for column 'a' at row 1 MariaDB> SELECT LENGTH(COMPRESS(REPEAT('a', 1000))); 21

length(compress(a)) > length(a) All implementations store data uncompressed if compressed data is bigger than uncompressed.

Blob storage requirement MariaDB reserves 1 byte for compressed blobs MariaDB> CREATE TABLE t1(a TINYBLOB COMPRESSED); MariaDB> INSERT INTO t1 VALUES(REPEAT('a', 255)); ERROR 1406 (22001): Data too long for column 'a' at row 1 MariaDB> INSERT INTO t1 VALUES(REPEAT('a', 254)); Percona and Tencent don’t and somehow it works well Percona> CREATE TABLE t1(a TINYBLOB COLUMN_FORMAT COMPRESSED); Percona> SET GLOBAL innodb_compressed_columns_threshold=1000; Percona> INSERT INTO t1 VALUES(REPEAT('a', 255)); Percona> SELECT LENGTH(a) FROM t1; 255 AliSQL doesn’t, but crashes on SELECT AliSQL> CREATE TABLE t1(a TINYBLOB COLUMN_FORMAT COMPRESSED); AliSQL> SET GLOBAL innodb_rds_column_zip_threshold=1000; AliSQL> INSERT INTO t1 VALUES(REPEAT('a', 255)); AliSQL> SELECT LENGTH(a) FROM t1; ERROR HY000: Lost connection to MySQL server during query

VARCHAR storage requirement MariaDB adds 1 byte for compressed varchars MariaDB> CREATE TABLE t1(a VARBINARY(255) COMPRESSED); MariaDB> SET column_compression_threshold=1000; MariaDB> INSERT INTO t1 VALUES(REPEAT('a', 255)); MariaDB> SELECT LENGTH(a) FROM t1; 255 Percona works correct too Percona> CREATE TABLE t1(a VARBINARY(255) COLUMN_FORMAT COMPRESSED); Percona> SET GLOBAL innodb_compressed_columns_threshold=1000; Percona> INSERT INTO t1 VALUES(REPEAT('a', 255)); Percona> SELECT LENGTH(a) FROM t1; 255 AliSQL and Tencent crash on INSERT AliSQL> CREATE TABLE t1(a VARBINARY(255) COLUMN_FORMAT COMPRESSED); AliSQL> SET GLOBAL innodb_rds_column_zip_threshold=1000; AliSQL> INSERT INTO t1 VALUES(REPEAT('a', 255)); ERROR HY000: Lost connection to MySQL server during query

CREATE TABLE … LIKE All implementations inherit compression attribute MariaDB> CREATE TABLE t1(a VARBINARY(255) COMPRESSED); MariaDB> CREATE TABLE t2 LIKE t1; MariaDB> SHOW CREATE TABLE t2; CREATE TABLE `t2` ( `a` varbinary(255) /*!100301 COMPRESSED*/ DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1

CREATE TABLE … SELECT MariaDB inherits compression attribute, data is transferred without recompression MariaDB> CREATE TABLE t1(a VARBINARY(255) COMPRESSED); MariaDB> CREATE TABLE t2 SELECT * FROM t1; MariaDB> SHOW CREATE TABLE t2; CREATE TABLE `t2` ( `a` varbinary(255) /*!100301 COMPRESSED*/ DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AliSQL, Percona and Tencent don’t inherit compression attribute, data is uncompressed AliSQL> CREATE TABLE t1(a VARBINARY(255) COLUMN_FORMAT COMPRESSED); AliSQL> CREATE TABLE t2 SELECT * FROM t1; AliSQL> SHOW CREATE TABLE t2; CREATE TABLE `t2` ( `a` varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1

INSERT … SELECT MariaDB transfers data without recompression MariaDB> CREATE TABLE t1(a VARBINARY(255) COMPRESSED); MariaDB> INSERT INTO t1 VALUES(REPEAT('a', 255)); MariaDB> CREATE TABLE t2 LIKE t1; MariaDB> INSERT INTO t2 SELECT * FROM t1; MariaDB> SHOW STATUS LIKE "Column_%compressions"; Column_compressions 1 Column_decompressions 0 AliSQL, Percona and Tencent perform recompression AliSQL> CREATE TABLE t1(a VARBINARY(255) COLUMN_FORMAT COMPRESSED); AliSQL> INSERT INTO t1 VALUES(REPEAT('a', 255)); AliSQL> CREATE TABLE t2 LIKE t1; AliSQL> INSERT INTO t2 SELECT * FROM t1; AliSQL> SHOW STATUS LIKE "Innodb_column_%compressed"; Innodb_column_compressed 2 Innodb_column_decompressed 1

ALTER TABLE…ALGORITHM=copy MariaDB transfers data without recompression MariaDB> CREATE TABLE t1(a VARBINARY(255) COMPRESSED); MariaDB> INSERT INTO t1 VALUES(REPEAT('a', 255)); MariaDB> ALTER TABLE t1 ADD COLUMN b INT, ALGORITHM=copy; MariaDB> SHOW STATUS LIKE "Column_%compressions"; Column_compressions 1 Column_decompressions 0 AliSQL, Percona and Tencent perform recompression AliSQL> CREATE TABLE t1(a VARBINARY(255) COLUMN_FORMAT COMPRESSED); AliSQL> INSERT INTO t1 VALUES(REPEAT('a', 255)); AliSQL> ALTER TABLE t1 ADD COLUMN b INT, ALGORITHM=copy; AliSQL> SHOW STATUS LIKE "Innodb_column_%compressed"; Innodb_column_compressed 2 Innodb_column_decompressed 1

SELECT a, LENGTH(a) MariaDB does uncompress for each reference MariaDB> CREATE TABLE t1(a VARBINARY(255) COMPRESSED); MariaDB> INSERT INTO t1 VALUES(REPEAT('a', 255)); MariaDB> SELECT a, LENGTH(a) FROM t1; ... MariaDB> SHOW STATUS LIKE "Column_%compressions"; Column_compressions 1 Column_decompressions 2 AliSQL, Percona and Tencent uncompress once AliSQL> CREATE TABLE t1(a VARBINARY(255) COLUMN_FORMAT COMPRESSED); AliSQL> INSERT INTO t1 VALUES(REPEAT('a', 255)); AliSQL> SELECT a, LENGTH(a) FROM t1; ... AliSQL> SHOW STATUS LIKE "Innodb_column_%compressed"; Innodb_column_compressed 1 Innodb_column_decompressed 1

Partitioning MariaDB has to uncompress data multiple times MariaDB> CREATE TABLE t1(a VARCHAR(1000) COMPRESSED) PARTITION BY RANGE COLUMNS (a) ( PARTITION p0 VALUES LESS THAN ('g'), PARTITION p1 VALUES LESS THAN ('m'), PARTITION p2 VALUES LESS THAN ('t'), PARTITION p3 VALUES LESS THAN ('w'), PARTITION p4 VALUES LESS THAN (MAXVALUE)); MariaDB> INSERT INTO t1 VALUES(REPEAT('k', 1000)); MariaDB> SHOW STATUS LIKE "Column_%compressions"; Column_compressions 1 Column_decompressions 3 AliSQL, Percona and Tencent don’t AliSQL> CREATE TABLE t1(a VARCHAR(1000) COLUMN_FORMAT COMPRESSED) PARTITION BY RANGE COLUMNS (a) ( PARTITION p0 VALUES LESS THAN ('g'), PARTITION p1 VALUES LESS THAN ('m'), PARTITION p2 VALUES LESS THAN ('t'), PARTITION p3 VALUES LESS THAN ('w'), PARTITION p4 VALUES LESS THAN (MAXVALUE)); AliSQL> INSERT INTO t1 VALUES(REPEAT('k', 1000)); AliSQL> SHOW STATUS LIKE "Innodb_column_%compressed"; Innodb_column_compressed 1 Innodb_column_decompressed 0

Replication In MariaDB compressed columns are binlogged and replicated compressed. It is possible to replicate compressed->uncompressed (or vise versa) with slave_type_conversions=ALL_NON_LOSSY. In AliSQL, Percona and Tencent compressed columns are binlogged and replicated uncompressed.

Normal INSERT overhead MariaDB compress(data -> record); // No extra alloc/copy compared to not compressed AliSQL, Percona buffer= mem_heap_zalloc(compress_heap); // zalloc does memset()!!! compress(record -> buffer); mem_heap_empty(compress_heap); Tencent buffer= mem_heap_alloc(compress_heap); // uses alloc instead of zalloc compress(record -> buffer); // Doesn’t reset compress_heap for each inserted row, // which can be a problem for INSERT … SELECT FROM huge_table.

Normal SELECT overhead MariaDB if (buffer_length < data_length) { free(buffer); buffer= malloc(); } uncompress(record -> buffer); AliSQL, Percona buffer= mem_heap_zalloc(compress_heap); // zalloc does memset()!!! uncompress(zdata -> buffer); mem_heap_empty(compress_heap); Tencent buffer= mem_heap_alloc(compress_heap); // uses alloc instead of zalloc uncompress(zdata -> buffer); mem_heap_free(compress_heap); // Less efficient than mem_heap_empty()

Metadata format MariaDB and Tencent AliSQL and Percona // Field info section of .frm (unireg_check) field_info[10]= (uchar) 24; AliSQL and Percona // Format section of .frm column_properties[field]|= (uchar) 24;

Data format All implementations have common structure AliSQL Percona +---+===+=====================+ |HDR|ROL|...compressed data...| AliSQL 7 bit: compressed flag (ROL is present only if this flag is set) 5-6 bit: number of bytes in "Record Original Length" minus 1 (0-3) 2-4 bit: compression method (0 means zlib) 1 bit: zlib wrapper flag 0 bit: unused Percona 11-15 bit: unused 10 bit: compressed flag (ROL is present only if this flag is set) 7-9 bit: number of bytes in "Record Original Length" minus 1 (0-3) 2-6 bit: compression method (0 means zlib) 1 bit: zlib wrapper flag 0 bit: unused

Data format Tencent MariaDB (binary compatible with Tencent) 7 bit: compressed flag (ROL is present only if this flag is set) 5-6 bit: compression method (0 means zlib) 4 bit: unused 0-3 bit: number of bytes in "Record Original Length" (1-4) MariaDB (binary compatible with Tencent) 4-7 bit: compression method (8 means zlib, ROL is present only if method>0) 3 bit: zlib wrapper flag 0-2 bit: number of bytes in "Record Original Length" (1-4)

Ideas per-column compression parameters (stored in .frm) implement more compression algorithms provide and accept compressed data to/from client needed for mysqldump to store data compressed needed for spider to transfer data compressed