Home » Performance » MySQL » Multiple categories and index problems
Multiple categories and index problems [message #3269] Wed, 09 July 2008 19:34 Go to previous message
armakuni  is currently offline armakuni
Messages: 4
Registered: July 2008
Junior Member
Hi!

I have a following table:

CREATE TABLE items (
    id      INTEGER UNSIGNED NOT NULL,
    dt      DATETIME NOT NULL,
    title   VARCHAR(1024) NOT NULL,  

    cat1    TINYINT UNSIGNED NOT NULL,
    cat2    TINYINT UNSIGNED,
    cat3    TINYINT UNSIGNED,
    cat4    TINYINT UNSIGNED,

    ...
    PRIMARY KEY (id),
    INDEX (dt)
) ENGINE = MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_swedish_ci;


The idea is to search items from the table using the categories. There are only four possible categories from which at least category 1 exists. The results are ordered by time. The problem is that the queries can be very different like:
- SELECT ... WHERE cat1 = 10 OR cat2 = 10 OR cat3 = 10 OR cat4 = 10 ...
- SELECT ... WHERE (cat1 = 10 OR cat2 = 10 OR cat3 = 10 OR cat4 = 10) AND (cat1 <> 20 AND cat2 <> 20 ...
- SELECT ... WHERE (cat1 NOT IN (13, 14, 15)) OR (cat2 NOT IN (13, 14, 15)) ...


The combinations are very different. The problem is that I have not found any good solution for indexes so that they would limit the searched rows. If I add an own index for every category it does not help. Also using multiple-column index does not seem to help. Mostly MySQL only uses time index and if category indexes get used it results filesort.

Any help appreciated. Also table structure can be changed if there is a better solution for this kind of problem.

Read Message
Read Message
Read Message
Previous Topic:InnoDB clusterd Index databasedesign
Next Topic:Queries are well optimized but they are causing many slow queries
Goto Forum:

  


Current Time: Fri Jul 10 03:54:43 EDT 2009

Total time taken to generate the page: 0.02476 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.