May 24, 2012

Post: Join Optimizations in MySQL 5.6 and MariaDB 5.5

… one join algorithm and that is Nested Loop Join. MariaDB has introduced a new join algorithm Hash Join. This join algorithm only works with equi-joins…)) as revenue, o_orderdate, o_shippriority from customer, orders, lineitem FORCE INDEX (i_l_orderkey) where c_mktsegment = ‘AUTOMOBILE’ and c_custkey…

Post: MySQL Session variables and Hints

…_JOIN, FORCE INDEX etc. You place these directly into the query to change how query is executed for example SELECT STRAIGHT_JOIN * FROM A FORCE INDEX(A) JOIN B The other part is session variable. If…

Post: Troubleshooting MySQL Upgrade Performance Regressions

… hints such as STRAIGHT_JOIN, FORCE INDEX, BIG_RESULT/SMALL_RESULT. Check whatever stats are the same (run SHOW INDEXES FROM for tables involved… plan no matter how you try and you might be forced to change your application by changing how query is written…

Post: ORDER BY ... LIMIT Performance Optimization

… field from the table which is not first in the join order index can’t be used. Sometimes it means breaking normalization… long as it is indexed) Force index if needed In some cases MySQL Optimizer may prefer to use different index, which has better selectivity… between better sort or better lookup or use FORCE INDEX to force it to use appropriate index. One more note about ORDER BY … LIMIT…

Comment: Using delayed JOIN to optimize count(*) and LIMIT queries

…-%d-%y’ ) As EDate, EHC.Hits FROM Entries E FORCE INDEX (DPrivate) LEFT JOIN EntryHitCounters EHC ON (EHC.EntryID=E.EntryID) WHERE E… from Entries FORCE INDEX (DPrivate) where DiaryID=11693 and Private=0 Order By Date DESC LIMIT 1235,20) D LEFT JOIN Entries E USING (EntryID) LEFT JOIN EntryHitCounters EHC USING (EntryID) I wish the force index wasn’t needed.

Post: Be careful when joining on CONCAT

… of a rather simple join. It was a join on tb1.vid = CONCAT(‘prefix-’, tb2.id) with tb1.vid – indexed varchar(100) and tb2.id – int(11) column. No matter what I did – forced it to use key, forced a different join order, it did not want to use tb1.vid index for it. And…

Comment: ORDER BY ... LIMIT Performance Optimization

… 14 seconds to execute: SELECT posts.* FROM posts force index (idx_post_date) INNER JOIN follow ON follow.followuserid = posts.userid WHERE follow… | | BTREE | | +——-+————+——————+————–+————-+———–+————-+———-+——–+——+————+———+ mysql> explain SELECT posts.* FROM posts force index (idx_post_date) INNER JOIN follow ON follow.followuserid = posts.userid WHERE follow…

Comment: Why Index could refuse to work ?

… why FORCE INDEX is ignored? I have a table with 100 columns which about 25% are integers and most of those have indexes on them. A varchar column is being used as to left join to another table which also has an (btree) index

Comment: ANALYZE: MyISAM vs Innodb

… these queries could be fixed with manually hinting with STRAIGHT_JOIN or FORCE INDEX. But of course it would have been much nicer…

Post: High-Performance Click Analysis with MySQL

…What can we improve here? Especially assuming that there are indexes other than the primary key, we can shrink … workload.  The nested-loop joins are not all that fast on big joins; the query optimizer can …But beware of falling into the trap of brute-forcing a solution that really needs to be solved…