I have this query in mysql and I wanted to be indexed, what is the best index composition?
SELECT cometchat.id, cometchat.from, cometchat.to, cometchat.message, cometchat.sent, cometchat.read, cometchat.direction
FROM cometchat
WHERE (
(
cometchat.to = '30411'
AND cometchat.direction <>2
)
OR (
cometchat.from = '30411'
AND cometchat.direction <>1
)
)
I've tried these indexes but they didn't work:
ALTER TABLE `cometchat` ADD INDEX ( `from`,`to`,`direction`)
ALTER TABLE `cometchat` ADD INDEX ( `from`,`to`)
ALTER TABLE `cometchat` ADD INDEX ( `to`,`direction`)
ALTER TABLE `cometchat` ADD INDEX ( `from`,`direction`)
Any help would be much appreciated.