I have a fair sized table now (1,955,041 rows) and it currently has two indexes:
PRIMARY is the ID number
and
Keywords is a FULLTEXT index of the Keywords column (Text).
Expand|Select|Wrap|Line Numbers
- +----------------------+------------------+------+-----+---------+----------------+
- | Field | Type | Null | Key | Default | Extra |
- +----------------------+------------------+------+-----+---------+----------------+
- | ID | int(20) unsigned | | PRI | NULL | auto_increment |
- | Disabled | char(2) | | | 0 | |
- | Keywords | text | | | | |
- | Category | varchar(100) | | | | |
- | Category2 | varchar(20) | | | | |
- | Category3 | varchar(20) | | | | |
- | Category4 | varchar(20) | | | | |
In my first query type I check to see it isn't Disabled and then check the Keywords:
Expand|Select|Wrap|Line Numbers
- SELECT * FROM files WHERE Disabled='0' AND MATCH (Keywords)
- AGAINST ('+tree' IN BOOLEAN MODE) ORDER by ID;
Expand|Select|Wrap|Line Numbers
- SELECT * FROM files WHERE Disabled='0' AND (Category='Food'
- OR Category2='Food' OR Category3='Food' OR Category4='Food') ORDER by ID
For the first query I have a feeling self-joining the table might help but it rather makes my head spin trying to figure out how that works. (I guess I really should take a course if I have to do much more of this stuff lol!)
I was playing with the UNION command for the second query and came up with this:
Expand|Select|Wrap|Line Numbers
- (SELECT * FROM files WHERE Disabled='0' AND Category='Food')
- UNION
- (SELECT * FROM files WHERE Disabled='0' AND Category2='Food')
- UNION
- (SELECT * FROM files WHERE Disabled='0' AND Category3='Food')
- UNION
- (SELECT * FROM files WHERE Disabled='0' AND Category4='Food')
- ORDER by ID;
Any help you can give me would be greatly appreciated!
Thanks,
Alison