sql - Simple query: mysql - very slow , mariadb - good performance -
simple query:
select * data.staff staff left join data.contact workphones on staff.id = workphones.staff_with_work_phone_id
mysql run time: 5.3 sec.
mariadb run time: 0.016 sec.
contact has ~50000 rows.
staff has ~600 rows.
what reason?
possible achieve same result on mysql?
thank you!
explain mysql (v5.7.14):
+----+-------------+------------+------------+------+--------------------------------+------+---------+------+-------+----------+---------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | | +----+-------------+------------+------------+------+--------------------------------+------+---------+------+-------+----------+---------------------------------------+ | 1 | simple | staff | null | | null | null | null | null | 606 | 100.00 | null | +----+-------------+------------+------------+------+--------------------------------+------+---------+------+-------+----------+---------------------------------------+ | 2 | simple | workphones | null | | fk_2f7824065c2c4b0fbe5c00da271 | null | null | null | 49180 | 100.00 | using where. | | | | | | | | | | | | | using join buffer (block nested loop) | +----+-------------+------------+------------+------+--------------------------------+------+---------+------+-------+----------+---------------------------------------+
explain mariadb (v10.0.28):
+----+-------------+------------+------+--------------------------------+--------------------------------+---------+--------------------+-------+----------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | | +----+-------------+------------+------+--------------------------------+--------------------------------+---------+--------------------+-------+----------+-------+ | 1 | simple | staff | | | | | | 602 | 100.00 | | +----+-------------+------------+------+--------------------------------+--------------------------------+---------+--------------------+-------+----------+-------+ | 2 | simple | workphones | | fk_1249f6bc1d68495090691f3ce02 | fk_1249f6bc1d68495090691f3ce02 | 9 | user_data.staff.id | 25476 | 100.00 | | +----+-------------+------------+------+--------------------------------+--------------------------------+---------+--------------------+-------+----------+-------+
the rest of verification conditions identical. test conducted many times.
your 2 query plans show why mysql slower. both find possible keys, foreign key.
mariadb use fk: fk_1249f6bc1d68495090691f3ce02 in both columns possible_keys
, keys
in row 2.
mysql see fk, not use it. mysql tells you, use
using join buffer (block nested loop)
in extra
table.
mysql not use foreign key.
foreign key joins have index on foreign key in both database systems? if mariadb has it, cannot blame mysql, because cannot use, not have.
Comments
Post a Comment