I'm not a performance expert so I wasn't able to give Peter much of an answer other than to confirm what he was seeing. Anybody have any idea why there is such a dramatic difference?
For those looking to test here are the details Peter was using.
Two tables:
CREATE TABLE `first` (
`id` smallint(5) unsigned NOT NULL,
`name` varchar(20) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT
CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `second` (
`id` int(10) unsigned NOT NULL auto_increment,
`firstid` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `firstid` (`firstid`)
) ENGINE=MyISAM DEFAULT
CHARSET=utf8 COLLATE=utf8_unicode_ci;
Table `first` holds 14,000 rows, table `second` holds 79994 with
`second.firstid` a forgien key to `first.id`. Now to execute a query
to return rows from `first` that are not referenced in `second`.
SELECT `first`.*
FROM `first` LEFT JOIN `second`
ON (`first`.id = `second`.firstid)
WHERE (`second`.firstid IS NULL)
Then delete the index on second.firstid.
This was ggreat to read
ReplyDelete