MariaDB index chosen differs on ARM and x64 based procesors

Posted on

Question :

When I have been using mariaDB on apple M1 chip, I discovered some diference between index chosen in select statement versus x64 server linux system with this query:

explain 
SELECT z.id_hlavni AS id_zbozi, p.id AS parametry_id, pl.hodnota_id
FROM parametry_zbozi AS pz
JOIN parametry_vyplneni AS pl ON pz.vyplneni_id = pl.id
JOIN parametry_vazby AS pv  ON pl.vazby_id = pv.id
JOIN parametry AS p ON pv.parametry_id = p.id
JOIN ( SELECT IFNULL(s.id_zbozi, h.id_zbozi) AS id_zbozi, h.id_zbozi AS id_hlavni 
       FROM zbozi AS h
       LEFT JOIN zbozi AS s ON h.id_zbozi = s.id_nadrazeneho_zbozi
       WHERE h.id_nadrazeneho_zbozi = 0 ) AS z ON pz.id_zbozi IN (z.id_zbozi, z.id_hlavni)
WHERE z.id_hlavni IN (605, 609, 610, 612, 616, 618, 621, 623, 630, 636, 
 648, 654, 664, 665, 673, 675, 682, 684, 688, 692, 698,
 707, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731,
 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745,
 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759,
 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773,
 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787,
 788, 789, 790, 791, 792, 793, 794, 795, 796) 
GROUP BY id_zbozi, parametry_id, hodnota_id

The result on Apple M1 chip is:
enter image description here

The result on x64 Intel chip on Linux is:
enter image description here

When I run the select statement without EXPLAIN, then on the M1 chipset the duration is about 100 seconds. But on the Linux x64 system is the duration only under 1 second.

The version of MariaDB is the same on both systems (10.6.5-MariaDB-1:10.6.5)

I have been looking for some explanation on Mysql/mariadb servers, but nothing found.

Strange, that this scenerio is the same with using MySQL version of database. On M1 chipset is the result same as on MariaDB.

Have somebody an explanation for this?

Answer :

Suggested indexes:

parametry_zbozi:  INDEX(vyplneni_id,  id_zbozi)
zbozi:  INDEX(id_nadrazeneho_zbozi, id_zbozi)

A likely reason for a difference is the number of rows in some of the tables. Or SHOW VARIABLES. Notice how one of the Explains used "BNL" but the other did not. This is partially controlled by join_buffer_size`.

Is any of those tables a “many-to-many” table?

ON pz.id_zbozi IN (z.id_zbozi, z.id_hlavni) is especially hard to Optimize. Maybe a UNION would help.

For further discussion, please provide SHOW CREATE TABLE for each table.

Leave a Reply

Your email address will not be published. Required fields are marked *