I'm a web developer (not DB admin!) having performance problems processing a 1.7m record table on MySQL. Here is that table :
CREATE TABLE `bbcmapimp_pc_raw` ( `postcode` char(8) NOT NULL, `pc_sector` char(6) DEFAULT NULL, `pc_district` char(4) DEFAULT NULL, `pc_area` char(2) DEFAULT NULL, `parliamentary_constituency_code` char(9) DEFAULT NULL, `parliamentary_constituency` varchar(255) DEFAULT NULL, `mp_name` varchar(255) DEFAULT NULL, `district_code` char(4) DEFAULT NULL, `district` varchar(45) DEFAULT NULL, `country` varchar(255) DEFAULT NULL, `suffix` char(5) DEFAULT NULL, PRIMARY KEY (`postcode`), KEY `pcc` (`parliamentary_constituency_code`), KEY `suffix_index` (`pc_area`,`suffix`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
I just need to iterate the table, but in my first attempt I used OFFSET which was horrendous! I've since learned what MySQL was doing under the bonnet, and understood why it was getting slower and slower.
So, I'm trying to modify my query to use a WHERE clause instead, but the issue is that I'm ordering the query by two fields (the table has a composite index defined).
One solution would be to add an ID field that's in the correct order and use that; but I was wondering if there was any way I could specify both fields of the composite index in a single greater than WHERE clause?