# Selects with multiple categories

**URL:** <https://forums.percona.com/t/selects-with-multiple-categories/675>\
**Category:** Other MySQL® Questions\
**Created:** [March 14, 2008, 9:23am UTC](https://forums.percona.com/t/selects-with-multiple-categories/675 "2008-03-14T09:23:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marki](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Marki](https://forums.percona.com/u/Marki)\
**Post date:** [March 14, 2008, 9:23am UTC](https://forums.percona.com/t/selects-with-multiple-categories/675/1 "2008-03-14T09:23:57Z")

</div>

We are using application (which is quite optimized, but not in this particular case) which stores posts in various categories.  
The category field contains comma-separated list of category-ids and so the select query looks like this:

which of course can’t use any indexes.

Is it somehow possible to optimize/rewrite this query without changing the table structure? I know the best would be to have special table with multiple rows of post\_id+categ\_id, but that would require a lot of work.

---

<div class="post-metadata">

**Author:** ![debug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/debug/32/772_2.png) [@debug](https://forums.percona.com/u/debug)\
**Post date:** [March 15, 2008, 3:16am UTC](https://forums.percona.com/t/selects-with-multiple-categories/675/2 "2008-03-15T03:16:58Z")

</div>

Yes, it’s better to have another table which stores information about post matching with category.

But there is a trick, which could increase performance of such queries. What MySQL version and what storage engine are you using? In 5.1 there is a MyISAM mmap feature. Please see details here

---

<div class="post-metadata">

**Author:** ![Marki](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Marki](https://forums.percona.com/u/Marki)\
**Post date:** [March 17, 2008, 5:03am UTC](https://forums.percona.com/t/selects-with-multiple-categories/675/3 "2008-03-17T05:03:39Z")

</div>

I’m using Mysql 5.0.45 (debian package from dotdeb) and this table is MyISAM (it has fulltext index also).  
I’ll by adding more RAM (this server has now only 1 GB) and that should help also with the filesystem cache (those tables are about 2x 300 MB + about the same for indexes).  
That mmap feature looks interesting, but I didn’t find any debian package for etch (only in experimental).
