Hi guys
I've got two tables
contacts (id,name,mobile_no,etc) (20,000 rows)
inbox (id,mobile_no,msg,etc) (50,000 rows of messages )
I'm trying to load all inbox messages with contact names coming from the contacts table..However the only contact identifier I have in the message table is the mobile_no .. this is because some messages do not necessarily have a record in the contacts table (they're loosely relational so to speak)
obviously the mobile_no in the inbox table is NOT UNIQUE....
The task is to select and display the messages with their CONTACT NAMES if available on the contacts table...
This would be a simple LEFT join:
SELECT
inbox.*,
contacts.coid,
sms_contacts.name
FROM
inbox
LEFT JOIN contacts ON contacts.mobile_no = inbox.mobile_no
ORDER BY receivedtime DESC
LIMIT 50
This works fine but querying just 50 rows takes soooooo long (almost a minute) ..
I have tried to INDEXED/Key the CONTACTS.mobile_no to UNQUE
and also Indexed (Normal) the INBOX.mobile_no (non unique)
But i didnt notice any performance increase at all.
Any other ideas?
I've already developed a PLAN B to this, where I first load all the messages, used an array to store the 1 copy of each mobile_no involved in this query, then build and run a separate single SELECT query.
it's really fast.. but im still curious to know out how to improve that JOIN thing.
Regards to all