我有一个在 MySQL 中运行的查询。如您所见,查询的每个部分都在索引字段上。然而,查询需要很长时间(几十分钟,比我愿意等待的时间长)。Connect 表由两个整数和两个索引组成(一个字段一,字段二,另一个字段二,字段一)。源和目标是具有单个索引 int 字段的表。鉴于所有索引,我希望此查询在几秒钟内完成。关于 1 的任何建议:为什么需要这么长时间,以及 2:如何让它更快?
谢谢!
mysql> explain
SELECT DISTINCT geneConnect.geneSymbolID FROM SNPEffectGeneConnector AS geneConnect
JOIN IndelSNPEffectConnector AS snpEConnect ON geneConnect.snpEffectID = snpEConnect.snpEffectID
JOIN InDels2 AS source ON source.id = snpEConnect.indelID
WHERE geneConnect.geneSymbolID NOT IN (
SELECT geneConnect.geneSymbolID FROM SNPEffectGeneConnector AS geneConnect
JOIN IndelSNPEffectConnector AS snpEConnect ON geneConnect.snpEffectID = snpEConnect.snpEffectID
JOIN InDels3 AS target ON target.id = snpEConnect.indelID);
+----+--------------------+-------------+-------+-------------------+----------+---------+-----------------------------------------------------------------------+------+--------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------------+-------+-------------------+----------+---------+-----------------------------------------------------------------------+------+--------------------------------+
| 1 | PRIMARY | source | index | id | id | 4 | NULL | 5771 | Using index; Using temporary |
| 1 | PRIMARY | snpEConnect | ref | snpEList | snpEList | 4 | treattablebrowser.source.id | 2 | Using index |
| 1 | PRIMARY | geneConnect | ref | snpEList | snpEList | 4 | treattablebrowser.snpEConnect.snpEffectID | 1 | Using where; Using index |
| 2 | DEPENDENT SUBQUERY | geneConnect | ref | snpEList,geneList | geneList | 4 | func | 1 | Using index |
| 2 | DEPENDENT SUBQUERY | target | index | id | id | 4 | NULL | 6297 | Using index; Using join buffer |
| 2 | DEPENDENT SUBQUERY | snpEConnect | ref | snpEList | snpEList | 8 | treattablebrowser.target.id,treattablebrowser.geneConnect.snpEffectID | 1 | Using index |
+----+--------------------+-------------+-------+-------------------+----------+---------+-----------------------------------------------------------------------+------+--------------------------------+
6 行(0.01 秒)