0
我正在兩臺不同的服務器上運行同一組數據的SQL查詢。相同的查詢使用相同的數據,不同的性能
服務器1:MySQL的版本14.14 DISTRIB 73年5月1日,對於使用的readline 5.1
服務器2未知-Linux的GNU(x86_64的):MySQL的版本15.1 DISTRIB 10.0.12-MariaDB的,用於osx10.10(x86_64的),使用的readline 5.1
查詢是:
SELECT
*
FROM
`user`
WHERE
user_id IN (SELECT user_id FROM reader_detail)
AND `user`.type <> 4
AND `user`.type <> 11
AND user_id NOT IN (
SELECT
`user_id`
FROM
reader_log
WHERE
reader_log.`date` > DATE_SUB(CURDATE(), INTERVAL 6 MONTH)
GROUP BY
user_id
ORDER BY
user_id ASC
)
AND username IS NOT NULL;
EXPLAIN SELECT服務器1上:
+----+--------------------+---------------+-----------------+---------------+---------+---------+------+-------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+---------------+-----------------+---------------+---------+---------+------+-------+--------------------------+
| 1 | PRIMARY | user | ALL | NULL | NULL | NULL | NULL | 29865 | Using where |
| 3 | DEPENDENT SUBQUERY | reader_log | index | NULL | PRIMARY | 7 | NULL | 17 | Using where; Using index |
| 2 | DEPENDENT SUBQUERY | reader_detail | unique_subquery | PRIMARY | PRIMARY | 4 | func | 1 | Using index |
+----+--------------------+---------------+-----------------+---------------+---------+---------+------+-------+--------------------------+
EXPLAIN SELECT服務器2上:
+------+--------------------+---------------+----------------+----------------------+---------+---------+----------------------------------------+-------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+--------------------+---------------+----------------+----------------------+---------+---------+----------------------------------------+-------+--------------------------+
| 1 | PRIMARY | reader_detail | index | PRIMARY | PRIMARY | 4 | NULL | 17682 | Using where; Using index |
| 1 | PRIMARY | user | eq_ref | PRIMARY | PRIMARY | 4 | rklocaldbmigrate.reader_detail.user_id | 1 | Using where |
| 3 | DEPENDENT SUBQUERY | reader_log | index_subquery | PRIMARY,user_id_date | PRIMARY | 4 | func | 16 | Using index; Using where |
+------+--------------------+---------------+----------------+----------------------+---------+---------+----------------------------------------+-------+--------------------------+
的查詢接受小於1秒到在服務器2上運行:5894點的行中的組(0.09秒)。然而,我不得不中止對服務器1之後查詢跑了1分鐘。
這裏發生了什麼?是因爲服務器2使用MariaDB,而它是服務器1上的MySQL?我在這裏無能爲力。再次,它是同一組數據(我從服務器1運行mysqldump到服務器2)。