개인 메시지 데이터베이스가 커지면서 다음 쿼리에 상당한 속도 저하가 있음을 알 수 있습니다.OR 연산자를 사용하면 MySQL 쿼리 속도가 느려집니다
쿼리 :
CREATE TABLE `privatemessages` (
`id` int(11) NOT NULL auto_increment,
`recipient` int(11) NOT NULL,
`sender` int(11) NOT NULL,
`time` int(11) NOT NULL,
`readstatus` int(11) NOT NULL,
`message` varchar(255) NOT NULL,
`messagetype` int(11) NOT NULL,
`rdeleted` int(11) NOT NULL,
`sdeleted` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `recipient` (`recipient`),
KEY `sender` (`sender`),
KEY `read` (`readstatus`),
KEY `time` (`time`),
KEY `openmessagingpanel` (`recipient`,`readstatus`),
KEY `openpmthreadrev` (`recipient`,`sender`),
KEY `openpmthread` (`sender`,`recipient`)
) ENGINE=InnoDB AUTO_INCREMENT=8650153 DEFAULT CHARSET=latin1
MySQL을 설명해
,536SELECT * FROM privatemessages WHERE sender='940' OR recipient='940' ORDER BY id DESC LIMIT 1000;
이
의 표 (940은 어떤 사용자 ID 될 수 있습니다)
+----+-------------+-----------------+-------------+------------------------------------------------------------------+------------------+---------+------+-------+--------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-----------------+-------------+------------------------------------------------------------------+------------------+---------+------+-------+--------------------------------------------+ | 1 | SIMPLE | privatemessages | index_merge | recipient,sender,openmessagingpanel,openpmthreadrev,openpmthread | sender,recipient | 4,4 | NULL | 26100 | Using union(sender,recipient); Using where | +----+-------------+-----------------+-------------+------------------------------------------------------------------+------------------+---------+------+-------+--------------------------------------------+ 1 row in set (0.00 sec)
누구나이 쿼리를 다시 수행하려면 어떻게해야하는지 알고 있습니까? 대략 8 백만 건의 기록이 있습니다.
감사합니다.
찾은 행 ('SELECT *')에 대한 모든 필드를 실제로 가져와야합니까? –
이 테이블에서 보낸 사람과받는 사람을 위해 결합 된 다른 인덱스를 정의 했습니까? 방금 테이블 정의를 할 때 훨씬 깨끗한 계획을 세웁니다. – Wes
미안 해요, 제 사본과 붙여 넣기를 엉망으로 만들었습니다. 원본 게시물은 데이터베이스가 현재의 방법으로 수정되었지만 이전의 일부 테스트에서 상당히 엉망이되었습니다. – Brian