Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql with big tables: how to optmize this query?
    primarykey
    data
    text
    <p>I have a table using InnoDB that stores all messages sent by my system. Currently the table have 40 million rows and grows 3/4 million per month.</p> <p>My query is basically to select messages sent from an user and within a data range. Here is a simplistic create table:</p> <pre>CREATE TABLE `log` ( `id` int(10) NOT NULL DEFAULT '0', `type` varchar(10) NOT NULL DEFAULT '', `timeLogged` int(11) NOT NULL DEFAULT '0', `orig` varchar(128) NOT NULL DEFAULT '', `rcpt` varchar(128) NOT NULL DEFAULT '', `user` int(10) DEFAULT NULL, PRIMARY KEY (`id`), KEY `timeLogged` (`timeLogged`), KEY `user` (`user`), KEY `user_timeLogged` (`user`,`timeLogged`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;</pre> <p>Note: I have individual indexes too because of other queries.</p> <p>Query looks like this:</p> <pre>SELECT COUNT(*) FROM log WHERE timeLogged BETWEEN 1282878000 AND 1382878000 AND user = 20</pre> <p>The issue is that this query takes from 2 minutes to 10 minutes, depending of user and server load which is too much time to wait for a page to load. I have mysql cache enabled and cache in application, but the problem is that when user search for new ranges, it won't hit cache.</p> <p>My question are:</p> <ul> <li>Would changing user_timeLogged index make any difference?</li> <li>Is this a problem with MySQL and big databases? I mean, does Oracle or other DBs also suffer from this problem?</li> </ul> <p>AFAIK, my indexes are correctly created and this query shouldn't take so long.</p> <p>Thanks for anyone who help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload