SlideShare uma empresa Scribd logo
1 de 53
Baixar para ler offline
© Ibuildings 2014/2015 - All rights reserved
#DrupalDaysEU
Optimizing MariaDB
for Drupal
and other Web Applications
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Gold Sponsors
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Media Sponsors
Silver Sponsors
© Ibuildings 2014/2015 - All rights reserved
Speaker Info
Federico Razzoli
Database Engineer
federico@ibuildings.it
© Ibuildings 2014/2015 - All rights reserved
MariaDB Essentials
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
MySQL fork
●
Created by Monty Widenius
●
Protected and promoted by the MariaDB Foundation
●
Supported by the community
●
"Community" includes Google, Facebook, Twitter...
●
Compatible with MySQL
What is MariaDB?
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Monty Widenius has two daughters called
●
My
●
Maria
Incidentally, he created two DBMSs with the same names :)
Genesis of a name
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
mysql is the command-line client. To run it:
mysql -uroot -p
●
Any MySQL GUI will work with MariaDB. Recommended ones are:
●
SQLyog on Linux
●
HeidiSQL on Windows
●
phpMyAdmin is ok if you can't run a GUI locally
MariaDB clients
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Configuration file:
●
/etc/mysql/my.cnf (on Debian, Ubuntu, etc)
●
my.cnf (on Windows)
Setting a variable at runtime:
SET GLOBAL variable_name = 'value';
Starting the server with a particular setting:
mysql --variable-name=value
Configuring MariaDB
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
datadir = /var/mysql
max_connections = 200
lock_wait_timeout = 60
max_packet_size = 2M
For most variables, default parameters work fine.
Configuring more than 10 variables is generally wrong.
Basic Configuration
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Clients connect to MariaDB server and send queries.
The workflow of a query processing is:
●
Connection manager
●
Query Cache
●
Parser
●
Optimizer
●
Storage engines
MariaDB architecture
© Ibuildings 2014/2015 - All rights reserved
Drivers (connectors)
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Generic truths:
●
MySQL drivers work with MariaDB
●
MySQL drivers do not support some MariaDB specific features:
●
Non-blocking API
●
Progress reporting
●
ODBC drivers work with MariaDB
Drivers (connectors)
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
PHP doesn't have a specific MariaDB driver
●
PHP has 3 modules for MySQL:
●
mysql (not supported anymore)
●
mysqli (most performant)
●
PDO (abstract layer)
●
Drupal uses PDO; it's ok
PHP drivers
© Ibuildings 2014/2015 - All rights reserved
Connection Methods
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
Thread per connection
●
Pool of threads
Connection methods:
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
Traditional method, used by MySQL; still the default one
●
When a connection is opened, a new thread is created
●
When a connection is closed, the thread is destroyed
●
On a simple web page, 1 click opens needs a connection
●
With AJAX, an open page can periodically create many connections
●
With Drupal, more plugins = more connections
Constantly creating and destroying threads cause an overhead.
Therefore this connection method well suites to desktop applications, not to web
applications.
Thread per connection
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
Connections are handled by one or more pools
●
Usually, one pool per core
●
No need to often create / destroy threads
●
Doesn't suite to environments where some long queries could be executed together
●
root will still be able to connect with the traditional method to kill long running queries
Perfect for web applications, as long as we don't "lock" the cores with long running
queries.
Pool of threads
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
To use Thread per connection... do nothing. It's the default method.
To use Pool of threads:
connection_method = pool-of-threads
Choosing a connection method
© Ibuildings 2014/2015 - All rights reserved
Query Cache
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
Can be disabled
●
When a query is issued, MariaDB looks in the cache for in an identical way
●
If the query is found, MariaDB returns the whole resultset
●
Otherwise, it executes the query and caches it
●
While doing so, it probably has to evict an old query from the cache
Query Cache
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Short answer: NONO.
Should I use Query Cache?
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Long answer:
●
Query Cache needs a lot of memory
●
Whole resultsets are stored. Rows returned by 10 queries are stored 5 times.
●
Data invalidation
●
Every time a table is modified, all queries that mention that tables are invalidated.
●
Overhead
●
Looking for a query in the cache has a cost.
Should I use Query Cache?
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
query_cache_type = OFF
query_cache_size = 0
Disabling Query Cache
© Ibuildings 2014/2015 - All rights reserved
Storage Engines
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Storage Engines are a particular type of plugins.
They implement data access:
●
data format (compression level, etc)
●
indexing
●
caching
●
special features, like transactions, foreign keys..
Storage Engines: an overview
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
If you are uncertain, just use InnoDB. It's impressive for most workloads.
MySQL is only focusing on InnoDB, ignoring the other Storage Engines.
But:
●
Each storage engine is optimized for some types of workload.
●
Storage Engines can do special things.
Why don't we have only one Storage Engine?
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
InnoDB - Fast, reliable for OLTP.
MEMORY - Data are written in memory, not on disk
MyISAM - Simple. Doesn't support transactions.
Aria - A crash-safe MyISAM
ARCHIVE - Compressed append-only tables
TokuDB - Reduces I/O; great compression level
BLACKHOLE - A Black Hole that makes data disappear
SPIDER - Connects to remote servers
CONNECT - Reads data files or remote DBMS's as if they were local tables
OQGRAPH - Handles trees and graphs
...and others.
Which Storage Engines exist?
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
InnoDB is faster for a typical workload.
MyISAM does not support transactions: rows are written immediately.
A MyISAM table can be compressed (it becomes read-only).
Aria is crash-safe: if tables are damaged, you can always recover data.
Drupal uses InnoDB for most table, and MyISAM for:
●
Logs
●
Caches
InnoDB vs. MyISAM vs. Aria
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
innodb_buffer_pool_size = <a_lot_of_memory>
innodb_log_buffer_size = 64M (at least)
innodb_lock_wait_timeout = 30
InnoDB basic configuration
© Ibuildings 2014/2015 - All rights reserved
Optimizer
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
Receives a request and (tries to) find the best execution strategy
●
For simple applications, it usually succeeds
●
But if s query is slow, the optimizer probably failed to elaborate a good query plan
MariaDB Optimizer
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
Slow Query Log
slow_query_log = ON
long_query_time = 5
log_queries_not_using_indexes = ON
min_examined_row_limit = 100
Restart MariaDB and run your application.
Then, just open the slow query log file and see which queries are slow.
One step behind...
how do I know which queries are slow?
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Imagine you are searching a book for a specific information.
Reading the whole book wouldn't be an efficient method.
Fortunately, books start with an index. The index allows us to read a small amount of text
to find information.
Table indexes are similar to book indexes: they allow MariaDB to quickly find the rows we
are looking for.
What are those index things you mentioned?
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
An index can consist of one or more columns
●
An index can be built on whole columns or prefix (for text columns)
●
There are no ascending/descending indexes (MariaDB/MySQL limitation)
Index essentials
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
Almost all operators in the WHERE clause:
●
=, <, >, >=, <=, IN, BETWEEN, LIKE
●
JOIN
●
GROUP BY
●
ORDER BY
Supported operations:
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
A sufficient number of rows will be examined
●
Index has a sufficient number of unique values
●
MariaDB can use whole index or the leftmost part
(yes, columns order matters)
●
With functions, indexes cannot be used:
SELECT * FROM my_table WHERE CHAR_LENGTH(indexed_column) = 1;
When are indexes used?
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Indexes:
CREATE INDEX idx_user ON username (username);
CREATE INDEX idx_userpass ON username (username, password);
CREATE INDEX idx_birthdate_user ON username (birth_date, username);
Queries:
SELECT username, password FROM users WHERE username = 'batman';
SELECT username FROM users WHERE username LIKE 'batman%';
SELECT username FROM users WHERE username LIKE '%batman%';
Leftmost part?
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
CREATE INDEX idx_a ON my_table (a);
CREATE INDEX idx_b ON my_table (b);
CREATE INDEX idx_abc ON my_table (a, b, c);
SELECT * FROM my_table WHERE a = 1 AND c = 1;
SELECT * FROM my_table WHERE a = 1 AND b = 1;
SELECT * FROM my_table WHERE a = 1 OR b = 1 OR c = 1;
SELECT * FROM my_table WHERE a = 1 OR b = 1;
Indexes: AND, OR
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Sometimes, we think that an index can be used to speedup a query,
but we are wrong.
Sometimes an index can be used, but the optimizer chooses to discard it.
There could be a good reason for this, but the optimizer can be wrong.
If a query is slow, we need to check if it uses a good index:
EXPLAIN EXTENDED SELECT …
The output of EXPLAIN can optionally be included in the Slow Query Log.
EXPLAIN statement
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
EXPLAIN returns a row for each table that is read by the query.
The rows are sorted.
There are several columns. The most important are:
●
table_name: Name of a table read by the query.
●
possible_keys: List of indexes that could be used.
●
key: The index choosen by the optimizer.
●
extra: Extra information; for example, wether
an internal temporary table is used.
EXPLAIN statement
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Everyone knows/remembers JOIN?
JOIN "links" two tables.
SELECT u.username, p.title
FROM users u
JOIN posts p
ON u.id = p.author;
SELECT u.username, p.title, c.text
FROM users u
JOIN posts p
ON u.id = p.author
LEFT JOIN comments c
ON p.id = c.post_id;
JOIN optimization
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Suppose that we have the following tables:
users: 30 rows
posts: 2,000 rows
comments: 10,000 rows
●
SELECT … FROM users JOIN posts JOIN comments
This query is completely non-optimized.
●
SELECT … FROM comments JOIN posts JOIN comments
will read 10,000 rows; for each row: 2,000; for each match: 10
The optimizer will determine the best JOIN order.... maybe.
JOIN optimization
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
The optimzer will choose a bad JOIN order if it doesn't know the number of rows in a
table, or the number of unique values in a column.
Solutions:
●
ANALYZE TABLE comments;
●
use_stat_tables = complementary
●
SELECT STRAIGHT_JOIN … FROM t1 JOIN t2
JOIN optimization
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
GROUP BY and ORDER BY can take advantage of indexes.
CREATE INDEX idx_a ON my_table (a, b);
SELECT * FROM my_table GROUP BY a;
SELECT * FROM my_table ORDER BY a;
SELECT * FROM my_table GROUP BY a ORDER BY a;
SELECT * FROM my_table WHERE a < 100 GROUP BY a ORDER BY a;
SELECT * FROM my_table WHERE a > b GROUP BY a ORDER BY a;
SELECT * FROM my_table WHERE b < 100 GROUP BY a ORDER BY a;
Optimization of grouping and ordering
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
If WHERE, GROUP BY and ORDER BY use different columns,
MariaDB creates a temporary table, in memory or on disk,
CREATE INDEX idx_a ON my_table (a, b, c);
SELECT * FROM my_table WHERE a < 100 GROUP BY b ORDER BY b;
SELECT * FROM my_table WHERE a > b GROUP BY a ORDER BY b;
SELECT * FROM my_table WHERE c < 100 GROUP BY a ORDER BY a;
Try to avoid this when a big amount of data is examined!
Optimization of grouping and ordering
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Some queries can only be executed by using temporary tables:
SELECT c.id, u.users_num
FROM (
SELECT city_id, COUNT(*) AS users_num
FROM users
GROUP BY city) u
JOIN city c ON u.city_id = c.id;
Often, these queries can be rewritten to avoid using a temp table:
SELECT c.id, COUNT(u.id) AS users_num
FROM city c
JOIN user u
ON c.id = u.city_id
GROUP BY c.id;
Internal temporary tables
© Ibuildings 2014/2015 - All rights reserved
Debugging problems
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
error_log = <file_name>
If not specified, errors are written:
●
to the console (on Linux)
●
on a file with a default name (onWindows)
Error Log
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
To start logging SQL errors:
INSTALL SONAME 'sql_errlog';
To rotate the log:
SET GLOBAL sql_error_log_rotate = 1;
To stop logging:
UNINSTALL SONAME 'sql_errlog';
FLUSH TABLES;
SQL Error Log
© Ibuildings 2014/2015 - All rights reserved
General Advices
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
●
Don't assume that something will work in practice just because it works in theory
●
Don't assume that theory is useless just because it doesn't work
●
In MariaDB, things always happen for a reason
●
.Well, a complex set of reasons, in fact
●
When you don't understand, investigate. Read the docs. Experiment.
●
Dirty solutions won't save time. Especially if you're sure they will.
General advices
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Search the web for:
●
MariaDB Knowledge Base (KB)
●
MySQL documentation (for information missing in the KB)
●
MySQL Performance Blog (Percona)
●
planet.mysql.com
●
MariaDB mailing lists on Launchpad
Good resources

Mais conteúdo relacionado

Destaque

Destaque (11)

Deploying an Open Source DAM in SAAS Mode (European Drupal Days 2015)
Deploying an Open Source DAM in SAAS Mode (European Drupal Days 2015)Deploying an Open Source DAM in SAAS Mode (European Drupal Days 2015)
Deploying an Open Source DAM in SAAS Mode (European Drupal Days 2015)
 
Sponsorship Opportunities European Drupal Days & Dutch PHP Conference 2015
Sponsorship Opportunities European Drupal Days & Dutch PHP Conference 2015Sponsorship Opportunities European Drupal Days & Dutch PHP Conference 2015
Sponsorship Opportunities European Drupal Days & Dutch PHP Conference 2015
 
Secure Drupal, from start to finish (European Drupal Days 2015)
Secure Drupal, from start to finish (European Drupal Days 2015)Secure Drupal, from start to finish (European Drupal Days 2015)
Secure Drupal, from start to finish (European Drupal Days 2015)
 
The multilingual Drupal 8 experience (European Drupal Days 2015)
The multilingual Drupal 8 experience (European Drupal Days 2015)The multilingual Drupal 8 experience (European Drupal Days 2015)
The multilingual Drupal 8 experience (European Drupal Days 2015)
 
Bridging the gap between business and technology - Behaviour Driven Developme...
Bridging the gap between business and technology - Behaviour Driven Developme...Bridging the gap between business and technology - Behaviour Driven Developme...
Bridging the gap between business and technology - Behaviour Driven Developme...
 
Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)
 
Verifying Drupal modules with OWASP ASVS 2014 (European Drupal Days 2015)
Verifying Drupal modules with OWASP ASVS 2014 (European Drupal Days 2015)Verifying Drupal modules with OWASP ASVS 2014 (European Drupal Days 2015)
Verifying Drupal modules with OWASP ASVS 2014 (European Drupal Days 2015)
 
Drupal for Big Data - is it ready? (European Drupal Days 2015)
Drupal for Big Data - is it ready? (European Drupal Days 2015)Drupal for Big Data - is it ready? (European Drupal Days 2015)
Drupal for Big Data - is it ready? (European Drupal Days 2015)
 
Drupal Continuous Integration (European Drupal Days 2015)
Drupal Continuous Integration (European Drupal Days 2015)Drupal Continuous Integration (European Drupal Days 2015)
Drupal Continuous Integration (European Drupal Days 2015)
 
UN World Food Programme Standards & Best Practises (European Drupal Days 2015)
UN World Food Programme Standards & Best Practises (European Drupal Days 2015)UN World Food Programme Standards & Best Practises (European Drupal Days 2015)
UN World Food Programme Standards & Best Practises (European Drupal Days 2015)
 
A Practical Introduction to Symfony (European Drupal Days 2015)
A Practical Introduction to Symfony (European Drupal Days 2015)A Practical Introduction to Symfony (European Drupal Days 2015)
A Practical Introduction to Symfony (European Drupal Days 2015)
 

Semelhante a Optimizing MariaDB for Web Applications (European Drupal Days 2015)

Hong kong drupal user group nov 8th - drupal 7.32 security vulnerability
Hong kong drupal user group   nov 8th - drupal 7.32 security vulnerabilityHong kong drupal user group   nov 8th - drupal 7.32 security vulnerability
Hong kong drupal user group nov 8th - drupal 7.32 security vulnerability
Ann Lam
 
01 demystifying mysq-lfororacledbaanddeveloperv1
01 demystifying mysq-lfororacledbaanddeveloperv101 demystifying mysq-lfororacledbaanddeveloperv1
01 demystifying mysq-lfororacledbaanddeveloperv1
Ivan Ma
 
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
Dave Stokes
 

Semelhante a Optimizing MariaDB for Web Applications (European Drupal Days 2015) (20)

MySql's NoSQL -- best of both worlds on the same disks
MySql's NoSQL -- best of both worlds on the same disksMySql's NoSQL -- best of both worlds on the same disks
MySql's NoSQL -- best of both worlds on the same disks
 
Secure Drupal, from start to finish
Secure Drupal, from start to finishSecure Drupal, from start to finish
Secure Drupal, from start to finish
 
Another Copernican Revolution: maintenance first, projects second (European D...
Another Copernican Revolution: maintenance first, projects second (European D...Another Copernican Revolution: maintenance first, projects second (European D...
Another Copernican Revolution: maintenance first, projects second (European D...
 
Hong kong drupal user group nov 8th - drupal 7.32 security vulnerability
Hong kong drupal user group   nov 8th - drupal 7.32 security vulnerabilityHong kong drupal user group   nov 8th - drupal 7.32 security vulnerability
Hong kong drupal user group nov 8th - drupal 7.32 security vulnerability
 
Hong Kong Drupal User Group - Nov 8th
Hong Kong Drupal User Group - Nov 8thHong Kong Drupal User Group - Nov 8th
Hong Kong Drupal User Group - Nov 8th
 
Hong kong drupal user group nov 8th - drupal 7.32 security vulnerability
Hong kong drupal user group   nov 8th - drupal 7.32 security vulnerabilityHong kong drupal user group   nov 8th - drupal 7.32 security vulnerability
Hong kong drupal user group nov 8th - drupal 7.32 security vulnerability
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
 
Verifying Drupal modules with OWASP ASVS 2014
Verifying Drupal modules with OWASP ASVS 2014Verifying Drupal modules with OWASP ASVS 2014
Verifying Drupal modules with OWASP ASVS 2014
 
Drupal 6 to Drupal 8 Migration
Drupal 6 to Drupal 8 MigrationDrupal 6 to Drupal 8 Migration
Drupal 6 to Drupal 8 Migration
 
How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?
 
01 demystifying mysq-lfororacledbaanddeveloperv1
01 demystifying mysq-lfororacledbaanddeveloperv101 demystifying mysq-lfororacledbaanddeveloperv1
01 demystifying mysq-lfororacledbaanddeveloperv1
 
Postgres Point-in-Time Recovery
Postgres Point-in-Time RecoveryPostgres Point-in-Time Recovery
Postgres Point-in-Time Recovery
 
Building an Apache Hadoop data application
Building an Apache Hadoop data applicationBuilding an Apache Hadoop data application
Building an Apache Hadoop data application
 
Intro.to.pem webinar.slides-061913
Intro.to.pem webinar.slides-061913Intro.to.pem webinar.slides-061913
Intro.to.pem webinar.slides-061913
 
Top10 list planningpostgresdeployment.2014
Top10 list planningpostgresdeployment.2014Top10 list planningpostgresdeployment.2014
Top10 list planningpostgresdeployment.2014
 
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
Scaling MySQl 1 to N Servers -- Los Angelese MySQL User Group Feb 2014
 
Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®
 
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux AdministratorsProper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
 

Mais de Eugenio Minardi

Mais de Eugenio Minardi (13)

Delphi and ExtJS (26 ottobre 2017)
Delphi and ExtJS (26 ottobre 2017)Delphi and ExtJS (26 ottobre 2017)
Delphi and ExtJS (26 ottobre 2017)
 
ExtJS: La piattaforma vincente (tools)
ExtJS: La piattaforma vincente (tools)ExtJS: La piattaforma vincente (tools)
ExtJS: La piattaforma vincente (tools)
 
ExtJS: La piattaforma vincente (multiple screens)
ExtJS: La piattaforma vincente (multiple screens)ExtJS: La piattaforma vincente (multiple screens)
ExtJS: La piattaforma vincente (multiple screens)
 
ExtJS: La piattaforma vincente (rich UI)
ExtJS: La piattaforma vincente (rich UI)ExtJS: La piattaforma vincente (rich UI)
ExtJS: La piattaforma vincente (rich UI)
 
ExtJS: La piattaforma vincente (class system)
ExtJS: La piattaforma vincente (class system)ExtJS: La piattaforma vincente (class system)
ExtJS: La piattaforma vincente (class system)
 
ExtJS: La piattaforma vincente
ExtJS: La piattaforma vincenteExtJS: La piattaforma vincente
ExtJS: La piattaforma vincente
 
Distributed Team Management: 
Pitfall, Challenges and Advantages
Distributed Team Management: 
Pitfall, Challenges and AdvantagesDistributed Team Management: 
Pitfall, Challenges and Advantages
Distributed Team Management: 
Pitfall, Challenges and Advantages
 
MongoDB: What, why, when
MongoDB: What, why, whenMongoDB: What, why, when
MongoDB: What, why, when
 
Il Web orientato al futuro: Express, Angular e nodeJS
Il Web orientato al futuro: Express, Angular e nodeJS Il Web orientato al futuro: Express, Angular e nodeJS
Il Web orientato al futuro: Express, Angular e nodeJS
 
MEAN: il nuovo stack di sviluppo per il futuro del web
MEAN: il nuovo stack di sviluppo per il futuro del webMEAN: il nuovo stack di sviluppo per il futuro del web
MEAN: il nuovo stack di sviluppo per il futuro del web
 
Gestione della configurazione in Drupal 8
Gestione della configurazione in Drupal 8Gestione della configurazione in Drupal 8
Gestione della configurazione in Drupal 8
 
Labortatorio di Information Design e UX con Drupal
Labortatorio di Information Design e UX con DrupalLabortatorio di Information Design e UX con Drupal
Labortatorio di Information Design e UX con Drupal
 
Drupal dashboard for dummies with d3
Drupal dashboard for dummies with d3Drupal dashboard for dummies with d3
Drupal dashboard for dummies with d3
 

Último

一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
ydyuyu
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
ayvbos
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Monica Sydney
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
JOHNBEBONYAP1
 

Último (20)

Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 

Optimizing MariaDB for Web Applications (European Drupal Days 2015)

  • 1. © Ibuildings 2014/2015 - All rights reserved #DrupalDaysEU Optimizing MariaDB for Drupal and other Web Applications
  • 2. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Gold Sponsors
  • 3. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Media Sponsors Silver Sponsors
  • 4. © Ibuildings 2014/2015 - All rights reserved Speaker Info Federico Razzoli Database Engineer federico@ibuildings.it
  • 5. © Ibuildings 2014/2015 - All rights reserved MariaDB Essentials
  • 6. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● MySQL fork ● Created by Monty Widenius ● Protected and promoted by the MariaDB Foundation ● Supported by the community ● "Community" includes Google, Facebook, Twitter... ● Compatible with MySQL What is MariaDB?
  • 7. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Monty Widenius has two daughters called ● My ● Maria Incidentally, he created two DBMSs with the same names :) Genesis of a name
  • 8. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● mysql is the command-line client. To run it: mysql -uroot -p ● Any MySQL GUI will work with MariaDB. Recommended ones are: ● SQLyog on Linux ● HeidiSQL on Windows ● phpMyAdmin is ok if you can't run a GUI locally MariaDB clients
  • 9. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Configuration file: ● /etc/mysql/my.cnf (on Debian, Ubuntu, etc) ● my.cnf (on Windows) Setting a variable at runtime: SET GLOBAL variable_name = 'value'; Starting the server with a particular setting: mysql --variable-name=value Configuring MariaDB
  • 10. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved datadir = /var/mysql max_connections = 200 lock_wait_timeout = 60 max_packet_size = 2M For most variables, default parameters work fine. Configuring more than 10 variables is generally wrong. Basic Configuration
  • 11. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Clients connect to MariaDB server and send queries. The workflow of a query processing is: ● Connection manager ● Query Cache ● Parser ● Optimizer ● Storage engines MariaDB architecture
  • 12. © Ibuildings 2014/2015 - All rights reserved Drivers (connectors)
  • 13. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Generic truths: ● MySQL drivers work with MariaDB ● MySQL drivers do not support some MariaDB specific features: ● Non-blocking API ● Progress reporting ● ODBC drivers work with MariaDB Drivers (connectors)
  • 14. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● PHP doesn't have a specific MariaDB driver ● PHP has 3 modules for MySQL: ● mysql (not supported anymore) ● mysqli (most performant) ● PDO (abstract layer) ● Drupal uses PDO; it's ok PHP drivers
  • 15. © Ibuildings 2014/2015 - All rights reserved Connection Methods
  • 16. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● Thread per connection ● Pool of threads Connection methods:
  • 17. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● Traditional method, used by MySQL; still the default one ● When a connection is opened, a new thread is created ● When a connection is closed, the thread is destroyed ● On a simple web page, 1 click opens needs a connection ● With AJAX, an open page can periodically create many connections ● With Drupal, more plugins = more connections Constantly creating and destroying threads cause an overhead. Therefore this connection method well suites to desktop applications, not to web applications. Thread per connection
  • 18. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● Connections are handled by one or more pools ● Usually, one pool per core ● No need to often create / destroy threads ● Doesn't suite to environments where some long queries could be executed together ● root will still be able to connect with the traditional method to kill long running queries Perfect for web applications, as long as we don't "lock" the cores with long running queries. Pool of threads
  • 19. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved To use Thread per connection... do nothing. It's the default method. To use Pool of threads: connection_method = pool-of-threads Choosing a connection method
  • 20. © Ibuildings 2014/2015 - All rights reserved Query Cache
  • 21. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● Can be disabled ● When a query is issued, MariaDB looks in the cache for in an identical way ● If the query is found, MariaDB returns the whole resultset ● Otherwise, it executes the query and caches it ● While doing so, it probably has to evict an old query from the cache Query Cache
  • 22. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Short answer: NONO. Should I use Query Cache?
  • 23. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Long answer: ● Query Cache needs a lot of memory ● Whole resultsets are stored. Rows returned by 10 queries are stored 5 times. ● Data invalidation ● Every time a table is modified, all queries that mention that tables are invalidated. ● Overhead ● Looking for a query in the cache has a cost. Should I use Query Cache?
  • 24. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved query_cache_type = OFF query_cache_size = 0 Disabling Query Cache
  • 25. © Ibuildings 2014/2015 - All rights reserved Storage Engines
  • 26. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Storage Engines are a particular type of plugins. They implement data access: ● data format (compression level, etc) ● indexing ● caching ● special features, like transactions, foreign keys.. Storage Engines: an overview
  • 27. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved If you are uncertain, just use InnoDB. It's impressive for most workloads. MySQL is only focusing on InnoDB, ignoring the other Storage Engines. But: ● Each storage engine is optimized for some types of workload. ● Storage Engines can do special things. Why don't we have only one Storage Engine?
  • 28. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved InnoDB - Fast, reliable for OLTP. MEMORY - Data are written in memory, not on disk MyISAM - Simple. Doesn't support transactions. Aria - A crash-safe MyISAM ARCHIVE - Compressed append-only tables TokuDB - Reduces I/O; great compression level BLACKHOLE - A Black Hole that makes data disappear SPIDER - Connects to remote servers CONNECT - Reads data files or remote DBMS's as if they were local tables OQGRAPH - Handles trees and graphs ...and others. Which Storage Engines exist?
  • 29. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved InnoDB is faster for a typical workload. MyISAM does not support transactions: rows are written immediately. A MyISAM table can be compressed (it becomes read-only). Aria is crash-safe: if tables are damaged, you can always recover data. Drupal uses InnoDB for most table, and MyISAM for: ● Logs ● Caches InnoDB vs. MyISAM vs. Aria
  • 30. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved innodb_buffer_pool_size = <a_lot_of_memory> innodb_log_buffer_size = 64M (at least) innodb_lock_wait_timeout = 30 InnoDB basic configuration
  • 31. © Ibuildings 2014/2015 - All rights reserved Optimizer
  • 32. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● Receives a request and (tries to) find the best execution strategy ● For simple applications, it usually succeeds ● But if s query is slow, the optimizer probably failed to elaborate a good query plan MariaDB Optimizer
  • 33. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● Slow Query Log slow_query_log = ON long_query_time = 5 log_queries_not_using_indexes = ON min_examined_row_limit = 100 Restart MariaDB and run your application. Then, just open the slow query log file and see which queries are slow. One step behind... how do I know which queries are slow?
  • 34. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Imagine you are searching a book for a specific information. Reading the whole book wouldn't be an efficient method. Fortunately, books start with an index. The index allows us to read a small amount of text to find information. Table indexes are similar to book indexes: they allow MariaDB to quickly find the rows we are looking for. What are those index things you mentioned?
  • 35. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● An index can consist of one or more columns ● An index can be built on whole columns or prefix (for text columns) ● There are no ascending/descending indexes (MariaDB/MySQL limitation) Index essentials
  • 36. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● Almost all operators in the WHERE clause: ● =, <, >, >=, <=, IN, BETWEEN, LIKE ● JOIN ● GROUP BY ● ORDER BY Supported operations:
  • 37. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● A sufficient number of rows will be examined ● Index has a sufficient number of unique values ● MariaDB can use whole index or the leftmost part (yes, columns order matters) ● With functions, indexes cannot be used: SELECT * FROM my_table WHERE CHAR_LENGTH(indexed_column) = 1; When are indexes used?
  • 38. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Indexes: CREATE INDEX idx_user ON username (username); CREATE INDEX idx_userpass ON username (username, password); CREATE INDEX idx_birthdate_user ON username (birth_date, username); Queries: SELECT username, password FROM users WHERE username = 'batman'; SELECT username FROM users WHERE username LIKE 'batman%'; SELECT username FROM users WHERE username LIKE '%batman%'; Leftmost part?
  • 39. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved CREATE INDEX idx_a ON my_table (a); CREATE INDEX idx_b ON my_table (b); CREATE INDEX idx_abc ON my_table (a, b, c); SELECT * FROM my_table WHERE a = 1 AND c = 1; SELECT * FROM my_table WHERE a = 1 AND b = 1; SELECT * FROM my_table WHERE a = 1 OR b = 1 OR c = 1; SELECT * FROM my_table WHERE a = 1 OR b = 1; Indexes: AND, OR
  • 40. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Sometimes, we think that an index can be used to speedup a query, but we are wrong. Sometimes an index can be used, but the optimizer chooses to discard it. There could be a good reason for this, but the optimizer can be wrong. If a query is slow, we need to check if it uses a good index: EXPLAIN EXTENDED SELECT … The output of EXPLAIN can optionally be included in the Slow Query Log. EXPLAIN statement
  • 41. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved EXPLAIN returns a row for each table that is read by the query. The rows are sorted. There are several columns. The most important are: ● table_name: Name of a table read by the query. ● possible_keys: List of indexes that could be used. ● key: The index choosen by the optimizer. ● extra: Extra information; for example, wether an internal temporary table is used. EXPLAIN statement
  • 42. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Everyone knows/remembers JOIN? JOIN "links" two tables. SELECT u.username, p.title FROM users u JOIN posts p ON u.id = p.author; SELECT u.username, p.title, c.text FROM users u JOIN posts p ON u.id = p.author LEFT JOIN comments c ON p.id = c.post_id; JOIN optimization
  • 43. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Suppose that we have the following tables: users: 30 rows posts: 2,000 rows comments: 10,000 rows ● SELECT … FROM users JOIN posts JOIN comments This query is completely non-optimized. ● SELECT … FROM comments JOIN posts JOIN comments will read 10,000 rows; for each row: 2,000; for each match: 10 The optimizer will determine the best JOIN order.... maybe. JOIN optimization
  • 44. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved The optimzer will choose a bad JOIN order if it doesn't know the number of rows in a table, or the number of unique values in a column. Solutions: ● ANALYZE TABLE comments; ● use_stat_tables = complementary ● SELECT STRAIGHT_JOIN … FROM t1 JOIN t2 JOIN optimization
  • 45. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved GROUP BY and ORDER BY can take advantage of indexes. CREATE INDEX idx_a ON my_table (a, b); SELECT * FROM my_table GROUP BY a; SELECT * FROM my_table ORDER BY a; SELECT * FROM my_table GROUP BY a ORDER BY a; SELECT * FROM my_table WHERE a < 100 GROUP BY a ORDER BY a; SELECT * FROM my_table WHERE a > b GROUP BY a ORDER BY a; SELECT * FROM my_table WHERE b < 100 GROUP BY a ORDER BY a; Optimization of grouping and ordering
  • 46. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved If WHERE, GROUP BY and ORDER BY use different columns, MariaDB creates a temporary table, in memory or on disk, CREATE INDEX idx_a ON my_table (a, b, c); SELECT * FROM my_table WHERE a < 100 GROUP BY b ORDER BY b; SELECT * FROM my_table WHERE a > b GROUP BY a ORDER BY b; SELECT * FROM my_table WHERE c < 100 GROUP BY a ORDER BY a; Try to avoid this when a big amount of data is examined! Optimization of grouping and ordering
  • 47. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Some queries can only be executed by using temporary tables: SELECT c.id, u.users_num FROM ( SELECT city_id, COUNT(*) AS users_num FROM users GROUP BY city) u JOIN city c ON u.city_id = c.id; Often, these queries can be rewritten to avoid using a temp table: SELECT c.id, COUNT(u.id) AS users_num FROM city c JOIN user u ON c.id = u.city_id GROUP BY c.id; Internal temporary tables
  • 48. © Ibuildings 2014/2015 - All rights reserved Debugging problems
  • 49. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved error_log = <file_name> If not specified, errors are written: ● to the console (on Linux) ● on a file with a default name (onWindows) Error Log
  • 50. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved To start logging SQL errors: INSTALL SONAME 'sql_errlog'; To rotate the log: SET GLOBAL sql_error_log_rotate = 1; To stop logging: UNINSTALL SONAME 'sql_errlog'; FLUSH TABLES; SQL Error Log
  • 51. © Ibuildings 2014/2015 - All rights reserved General Advices
  • 52. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved ● Don't assume that something will work in practice just because it works in theory ● Don't assume that theory is useless just because it doesn't work ● In MariaDB, things always happen for a reason ● .Well, a complex set of reasons, in fact ● When you don't understand, investigate. Read the docs. Experiment. ● Dirty solutions won't save time. Especially if you're sure they will. General advices
  • 53. #DrupalDaysEU © Ibuildings 2014/2015 - All rights reserved Search the web for: ● MariaDB Knowledge Base (KB) ● MySQL documentation (for information missing in the KB) ● MySQL Performance Blog (Percona) ● planet.mysql.com ● MariaDB mailing lists on Launchpad Good resources