November 2010
M T W T F S S
« Apr   May »
1234567
891011121314
15161718192021
22232425262728
2930  

Converting queries with OR to Union to ulitize indexes

Lets say we have a table storing mail messages and we need to show user’s mailbox: messages sent “from” and “to” the specified user.

Here is our table:

CREATE TABLE `internalmail` ( `mail_id` int(10) NOT NULL AUTO_INCREMENT, `senderaddress_id` int(10) NOT NULL, `recipientaddress_id` int(10) NOT NULL, `mail_timestamp` timestamp NULL DEFAULT NULL, … message body, etc … […]