May 25, 2012

Post: Join Optimizations in MySQL 5.6 and MariaDB 5.5

… before MySQL has only supported one join algorithm and that is Nested Loop Join. MariaDB has introduced a new join algorithm Hash Join. This join algorithm… – l_discount)) as revenue, o_orderdate, o_shippriority from customer, orders, lineitem FORCE INDEX (i_l_orderkey) where c_mktsegment = ‘AUTOMOBILE’ and… size 6M (Hash Join and Key-ordered Scan disabled) You can see that the lowest query time is for MySQL 5.6 which…

Post: ORDER BY ... LIMIT Performance Optimization

… leading table. If ORDER BY is going by field from the table which is not first in the join order index can’t be used. Sometimes it means breaking normalization and duplicating column(s) you’re going to use in ORDER… indexes so MySQL Optimizer does not have to chose between better sort or better lookup or use FORCE INDEX to force it to…

Post: The MySQL optimizer, the OS cache, and sequential versus random I/O

…. Let’s start with the MySQL query optimizer. The optimizer tries to choose the best join order based on its cost metric; it… two dimension tables. MySQL doesn’t want to choose this join order, so we’ll force it with STRAIGHT_JOIN: explain select STRAIGHT_JOIN …. +——-+———–+———–+———————————+ | table | type…

Post: Be careful when joining on CONCAT

…(11) column. No matter what I did – forced it to use key, forced a different join order, it did not want to use tb1… number of rows analyzed was really huge: mysql> EXPLAIN -> SELECT -> tb1.* -> FROM tb2 -> STRAIGHT_JOIN tb1 -> WHERE -> ( -> tb1.vid LIKE ‘prefix-%’ AND…, let’s check if that really helps: mysql> EXPLAIN -> SELECT -> tb1.* -> FROM tb2 -> STRAIGHT_JOIN tb1 -> WHERE -> ( -> tb1.vid LIKE ‘prefix-%’ AND…

Post: High-Performance Click Analysis with MySQL

…-loop joins on large data sets are very expensive.  If MySQL supported sort-merge or hash joins, you’…Data clustering. InnoDB’s primary keys define the physical order rows are stored in.  That lets you …But beware of falling into the trap of brute-forcing a solution that really needs to be solved …

Post: MySQL Session variables and Hints

MySQL has two ways to find tune execution of particular query. First is MySQL Hints, such as SQL_BIG_RESULT, STRAIGHT_JOIN, FORCE INDEX… how query is executed for example SELECT STRAIGHT_JOIN * FROM A FORCE INDEX(A) JOIN B The other part is session variable. If…: SELECT SQL_SORT_BUFFER_SIZE=50000000 NAME FROM LARGE_TABLE ORDER BY NAME DESC LIMIT 10 This would also make it…

Comment: How to find wrong indexing with glance view

… out with optimizer hints like straight_join to have it look at tables in the right order and come up with a… single column indexes generally aren’t a good idea, well MySQL forces this upon you if you actually implement a proper database… presently, 3 currencies and 20 operators. MySQL will create the following indexes: unique index on order_id index on item_type_id…

Post: MySQL caching methods and tips

… for MySQL. Popular cache methods The MySQL query cache When the query cache is enabled, MySQL examines… a possible solution to the problem. This forces one query to do the computation while…sorting, aggregation and join operations are still CPU intensive and single threaded. In order to avoid these …

Comment: FusionIO 320GB MLC benchmarks

… too. And while an SSD can improve join performance remember that all queries on MySQL are essentially single threaded (excluding for a… in joins such that denormalization will still almost always buy more performance. Also don’t forget that the optimizer may be forced to pick non-optimal join orders because of outer joins or hints, so just about any database which uses any joins can…

Comment: ORDER BY ... LIMIT Performance Optimization

….* FROM posts force index (idx_post_date) INNER JOIN follow ON follow.followuserid = posts.userid WHERE follow.userid=’61585′ ORDER BY date DESC… mysql> explain SELECT posts.* FROM posts force index (idx_post_date) INNER JOIN follow ON follow.followuserid = posts.userid WHERE follow.userid=’61585′ ORDER