This is the query that I'm looking to optimize:
SELECT Id, Title, Text,
(SELECT count(*) from ReaderFeedback as b
where b.EmailAddress=ReaderFeedback.EmailAddress) AS totalPosts
FROM ReaderFeedback FORCE INDEX (ParentFeedbackId)
WHERE ParentFeedbackId = 123 AND Approved=1 ORDER BY Date ASC
Below is the Mysql explain query results:
id: 1
select_type: PRIMARY
table: ReaderFeedback
Type: ref
possible_keys :ParentFeedbackId
Key: ParentFeedbackId
key_len: 7
ref: const,const
rows: 2
Extra: Using where; Using filesort
id: 2
DEPENDENT SUBQUERY
b
ALL
NULL
NULL
NULL
NULL
101369
Using where
Show create table freader feedback if below:
CREATE TABLE `ReaderFeedback` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ParentFeedbackId` int(11) DEFAULT NULL,
`Text` text NOT NULL,
`Title` varchar(75) NOT NULL DEFAULT '',
`EmailAddress` varchar(75) NOT NULL DEFAULT '',
`Date` date NOT NULL DEFAULT '0000-00-00',
`Approved` tinyint(4) DEFAULT '1',
PRIMARY KEY (`Id`),
KEY `ParentFeedbackId` (`ParentFeedbackId`,`Approved`),
KEY `Title` (`Title`),
KEY `Id` (`Id`),
KEY `Approved` (`Approved`),
) ENGINE=MyISAM AUTO_INCREMENT=142781 DEFAULT CHARSET=utf8
Please help out a fellow developer.
Thanks!
EXPLAIN EXTENDED SELECT ...) Also show us yourshow create table ReaderFeedback