我的这个查询运行了 3 分钟以上。我希望优化以在几秒钟内运行:
SELECT Count(DISTINCT l.licitatii_id) c
FROM licitatii_ue l
INNER JOIN domenii_licitatii dl
ON l.licitatii_id = dl.licitatii_id
AND dl.tip_licitatie = '2'
INNER JOIN domenii d
ON dl.domenii_id = d.domenii_id
AND d.tip_domeniu = '1'
AND d.status = 1
WHERE l.status = 1
AND l.data_limita >= '1357768800'
解释显示:
*** row 1 ***
table: d
type: ref
possible_keys: PRIMARY,key_status_tip_domeniu,ind_v1
key: key_status_tip_domeniu
key_len: 9
ref: const,const
rows: 39
Extra: Using where; Using index
*** row 2 ***
table: dl
type: ref
possible_keys: PRIMARY,licitatii_id,licitatii_id_2
key: PRIMARY
key_len: 5
ref: web1db1.d.domenii_id,const
rows: 1882
Extra: Using index
*** row 3 ***
table: l
type: eq_ref
possible_keys: PRIMARY,data_limita
key: PRIMARY
key_len: 4
ref: web1db1.dl.licitatii_id
rows: 1
Extra: Using where
架构:
合法性
PRIMARY KEY (`licitatii_id`),
UNIQUE KEY `nr_ue` (`nr_ue`),
KEY `nume` (`nume`),
KEY `tip_licitatie` (`tip_licitatie`),
KEY `surse_ue_id` (`surse_ue_id`),
KEY `data_publicarii` (`data_publicarii`),
KEY `tara_id` (`tara_id`),
KEY `creat` (`creat`),
KEY `data_limita` (`data_limita`),
FULLTEXT KEY `nume_fulltext` (`nume`,`descriere`)
) ENGINE=MyISAM
/*Index Information*/
---------------------
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
------------ ---------- --------------- ------------ --------------- --------- ----------- -------- ------ ------ ---------- ---------
licitatii_ue 0 PRIMARY 1 licitatii_id A 136456 (NULL) (NULL) BTREE
licitatii_ue 0 nr_ue 1 nr_ue A (NULL) (NULL) (NULL) YES BTREE
licitatii_ue 1 nume 1 nume A 68228 (NULL) (NULL) BTREE
licitatii_ue 1 tip_licitatie 1 tip_licitatie A 13 (NULL) (NULL) YES BTREE
licitatii_ue 1 surse_ue_id 1 surse_ue_id A 1 (NULL) (NULL) BTREE
licitatii_ue 1 data_publicarii 1 data_publicarii A 136456 (NULL) (NULL) YES BTREE
licitatii_ue 1 tara_id 1 tara_id A 41 (NULL) (NULL) YES BTREE
licitatii_ue 1 creat 1 creat A 136456 (NULL) (NULL) YES BTREE
licitatii_ue 1 data_limita 1 data_limita A 770 (NULL) (NULL) YES BTREE
licitatii_ue 1 nume_fulltext 1 nume (NULL) 1 (NULL) (NULL) FULLTEXT
licitatii_ue 1 nume_fulltext 2 descriere (NULL) 1 (NULL) (NULL) YES FULLTEXT
domenii_licitatii
PRIMARY KEY (`domenii_id`,`tip_licitatie`,`licitatii_id`),
KEY `licitatii_id` (`licitatii_id`,`tip_licitatie`),
KEY `licitatii_id_2` (`licitatii_id`)
) ENGINE=InnoDB
/*Index Information*/
---------------------
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
----------------- ---------- -------------- ------------ ------------- --------- ----------- -------- ------ ------ ---------- ---------
domenii_licitatii 0 PRIMARY 1 domenii_id A 20 (NULL) (NULL) BTREE
domenii_licitatii 0 PRIMARY 2 tip_licitatie A 228 (NULL) (NULL) BTREE
domenii_licitatii 0 PRIMARY 3 licitatii_id A 430634 (NULL) (NULL) BTREE
domenii_licitatii 1 licitatii_id 1 licitatii_id A 430634 (NULL) (NULL) BTREE
domenii_licitatii 1 licitatii_id 2 tip_licitatie A 430634 (NULL) (NULL) BTREE
domenii_licitatii 1 licitatii_id_2 1 licitatii_id A 430634 (NULL) (NULL) BTREE
多梅尼
PRIMARY KEY (`domenii_id`),
KEY `key_status_tip_domeniu` (`status`,`tip_domeniu`),
KEY `ind_v1` (`domenii_id`,`tip_domeniu`,`status`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB
/*Index Information*/
---------------------
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
------- ---------- ---------------------- ------------ ----------- --------- ----------- -------- ------ ------ ---------- ---------
domenii 0 PRIMARY 1 domenii_id A 79 (NULL) (NULL) BTREE
domenii 1 key_status_tip_domeniu 1 status A 4 (NULL) (NULL) YES BTREE
domenii 1 key_status_tip_domeniu 2 tip_domeniu A 11 (NULL) (NULL) BTREE
domenii 1 ind_v1 1 domenii_id A 79 (NULL) (NULL) BTREE
domenii 1 ind_v1 2 tip_domeniu A 79 (NULL) (NULL) BTREE
domenii 1 ind_v1 3 status A 79 (NULL) (NULL) YES BTREE
domenii 1 parent_id 1 parent_id A 79 (NULL) (NULL) BTREE