I have a query that is giving me problems and I can't understand why MySQL's query optimizer is behaving the way it is. Here is the background info:
I have 3 tables. Two are relatively small and one is large.
Table 1 (very small, 727 rows):
CREATE TABLE
ipa(
ipa_idint(11) NOT NULL AUTO_INCREMENT,
ipa_codeint(11) DEFAULT NULL,
ipa_namevarchar(100) DEFAULT NULL,
payorcodevarchar(2) DEFAULT NULL,
compidint(11) DEFAULT '2'
PRIMARY KEY (ipa_id),
KEYipa_code(ipa_code) ) ENGINE=MyISAM
Table 2 (smallish, 59455 rows):
CREATE TABLE
assign_ipa(
assignidint(11) NOT NULL AUTO_INCREMENT,
ipa_idint(11) NOT NULL,
useridint(11) NOT NULL,
usernamevarchar(20) DEFAULT NULL,
compidint(11) DEFAULT NULL,
PayorCodechar(10) DEFAULT NULL
PRIMARY KEY (assignid),
UNIQUE KEYassignid(assignid,ipa_id),
KEYipa_id(ipa_id)
) ENGINE=MyISAM
Table 3 (large, 24,711,730 rows):
CREATE TABLE
master_final(
IPAint(11) DEFAULT NULL,
MbrCtsmallint(6) DEFAULT '0',
PayorCodevarchar(4) DEFAULT 'WC',
KEYidx_IPA(IPA)
) ENGINE=MyISAM DEFAULT
Now for the query. I'm doing a 3-way join using the first two smaller tables to essentially subset the big table on one of it's indexed values. Basically, I get a list of IDs for a user, SJOnes and query the big file for those IDs.