Hi there,
When i execute this query it seems to cause the mysqld.exe process to use 50-100% of my cpu.
Any ideas why.
SELECT m.draw_id , m.mobile, m.fly_buys, m.signup_date,
IF(m.club = 1, 'Yes', 'No') AS club,
IF(w.code != '', w.code,
IF(f.code != '', f.code,
IF(t.code != '', t.code, 'Unknown') ) ) AS code,
IF(w.code != '', 'General',
IF(f.code != '', '5 pt',
IF(t.code != '', '10 pt', 'Unknown') ) ) AS code_type
FROM action_6_members m
LEFT JOIN action_6_5pts f ON f.member_id = m.id
LEFT JOIN action_6_10pts t ON t.member_id = m.id
LEFT JOIN action_6_weekly w ON w.member_id = m.id
WHERE `draw_id` = '3' ORDER BY m.id DESC limit 0, 20;
Note: this does not return a massive amount of data (10 rows).
Note: although there are only 10 rows returned
action_6_5pts contains 40k rows
action_6_10_pts contains 25k rows
action_6_weekly contains 3.5million rows.
Update
So i have added an index and it is now working better.
Here is the basic table schematics.
action_6_5pts/10pts/weekly are all
code | member_id
CREATE TABLE `action_6_5pts` (
`code` varchar(255) NOT NULL,
`member_id` int(11) NOT NULL,
PRIMARY KEY (`code`),
KEY `member_id` (`member_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
action_6_members is id | flybuys | bla | bla | bla
CREATE TABLE `action_6_members` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`draw_id` int(11) NOT NULL,
`mobile` varchar(255) NOT NULL,
`fly_buys` varchar(255) NOT NULL,
`signup_date` datetime NOT NULL,
`club` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=latin1
so,
i need to return the code type for the member, and the actual code.
This information is not stored anywhere and the only way i can see to get it is to do a join on the tables based on the member_id of each user.
Is there a faster/better way of doing this without altering the table structure?