1

I have the same database on 2 servers. One is with Cpanel running mysql other one its CWP with mariadb. Both databases are identical, tables have the same index, mysql variables are identical but the performance its way different:

SELECT 
    DISTINCT item_id
FROM                                                        
    site_plugin_products_cache_filters
WHERE
    value_id IN (32)

On MySql I get 1,939 rows (1.284 s) On MaridDb I get 1,939 rows (0.097 s)

Any idea why this happens ?

When i get to sub-queries the differences are way bigger ( 0.01s vs 100+ seconds )

SELECT 
    DISTINCT item_id
FROM                                                        
    site_plugin_products_cache_filters
WHERE
    value_id IN (32) AND
    item_id IN (
        SELECT item_id FROM 
            site_plugin_products_cache_cats
        WHERE
            cat_id=1
    )

Or

SELECT  DISTINCT item_id  FROM site_plugin_products_cache_cats
WHERE cat_id IN (362)  AND item_id != 2519 ORDER BY rand()
LIMIT 4    

4 rows (0.053 s) vs 4 rows (0.103 s)

3
  • Can you EXPLAIN {query} on both? For the second query, is SELECT DISTINCT site_plugin_products_cache_filters.item_id FROM site_plugin_products_cache_filters JOIN site_plugin_products_cache_cats ON site_plugin_products_cache_filters, item_id = site_plugin_products_cache_cats.item_id WHERE cat_id=1 AND value_id =32 ) the same query?
    – danblack
    Aug 30, 2018 at 1:17
  • What is the differences in the servers? It could be a simple as one server has hardware that is better setup for running a database server (or just has less work happening on it)
    – Joe W
    Nov 4, 2018 at 20:03
  • Hi, Check the answer bellow, mysql had no query_cache_size, while maria db had it enabled.
    – Emanuel
    Nov 4, 2018 at 20:04

2 Answers 2

1

Seems WHM / CPanel comes by default with query_cache_size=0 and this was killing the performance. After set to an optimal value all its normal :)

4
  • 1
    If you want to compare the performance, you should do it with with query cache completely disabled - which means, set query_cache_size=0 and query_cache_type=0 in my.cnf, and restart MySQL. Mar 10, 2018 at 14:47
  • To count all results for each combination without cache its a painn ( Asus [19] , Apple[20] etc , then Memory 8 GB [10], 16 Gb [5] etc. I have an new subquery level for each filter group. Select item_id from filters where attr in (x) and item_id in ( select item id from filters .... and item_id in ( select .... ))
    – Emanuel
    Mar 10, 2018 at 21:00
  • Keep in mind that every time the table is modify (yes, even 1 row) the cached results will be invalidated for all queries mentioning the table. But if in your case that is not a problem, ignore my suggestion. Mar 10, 2018 at 21:21
  • Yes its a filter, it will ignore cache only if someone will add a new product from cms
    – Emanuel
    Mar 10, 2018 at 22:45
0

Most of the timings above do not look like the Query cache was involved. The only one that might have used the QC is the one taking 0.01s. To avoid the QC for one SELECT, do SELECT SQL_NO_CACHE ...

MariaDB and MySQL have diverged significantly in the handling of IN ( SELECT ... ) This may explain one of the differences.

Do both machines have the same type of disk?

There is other caching that goes on. On a spinning disk (not SSD), a typical disk hit takes 0.01s. 0.05s may that 5 blocks had to be fetched from disk; 0.10s may mean that 10 were fetched. This difference may be due to whatever was going on before running the test. To avoid this issue, run each query twice, and take the second timing.

The first query would benefit from INDEX(value_id, item_id).

2nd and 3rd queries: (cat_id, item_id)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.