Hi there,
I have some troubles understanding what happens with one of my queries.
Here is the table structures.
There is a tiny dataset within (less than 5000 entries in each).
CREATE TABLE `tracker_artifact` ( `id` int(11) NOT NULL auto_increment, `tracker_id` int(11) NOT NULL, `last_changeset_id` int(11) NOT NULL, `submitted_by` int(11) NOT NULL, `submitted_on` int(11) NOT NULL, `use_artifact_permissions` tinyint(1) NOT NULL default '0', PRIMARY KEY (`id`), KEY `idx_tracker_id` (`tracker_id`), KEY `idx_my` (`submitted_by`,`tracker_id`,`last_changeset_id`), KEY `idx_last_changeset_id` (`last_changeset_id`,`id`)) ENGINE=MyISAM AUTO_INCREMENT=2842 DEFAULT CHARSET=utf8;CREATE TABLE `tracker_changeset` ( `id` int(11) NOT NULL auto_increment, `artifact_id` int(11) NOT NULL, `submitted_by` int(11) default NULL, `submitted_on` int(11) NOT NULL, `email` varchar(255) default NULL, PRIMARY KEY (`id`), KEY `artifact_id` (`artifact_id`,`id`)) ENGINE=MyISAM AUTO_INCREMENT=3342 DEFAULT CHARSET=utf8;
Then I have a query that looks like that:
SELECT c.idFROM tracker_changeset AS c INNER JOIN tracker_artifact AS a ON (a.id = c.artifact_id)WHERE a.id IN (928,933,934,...) AND c.id IN (1398,1432,...);
But the 2 ranges are quite big (~1900 values in each) and the query is taking a lot of time (8s) but I don't undestand why.
Even explain is taking ages:
+----+-------------+-------+-------+---------------------+-------------+---------+--------------+------+--------------------------+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+-------+-------+---------------------+-------------+---------+--------------+------+--------------------------+| 1 | SIMPLE | a | range | PRIMARY | PRIMARY | 4 | NULL | 1909 | Using where; Using index | | 1 | SIMPLE | c | ref | PRIMARY,artifact_id | artifact_id | 4 | a.id | 1 | Using where; Using index | +----+-------------+-------+-------+---------------------+-------------+---------+--------------+------+--------------------------+2 rows in set (3.33 sec)
2 questions arise:
-> What I'm doing wrong there
-> What is the impact of huge IN() statements?
I have some troubles understanding what happens with one of my queries.
Here is the table structures.
There is a tiny dataset within (less than 5000 entries in each).
CREATE TABLE `tracker_artifact` ( `id` int(11) NOT NULL auto_increment, `tracker_id` int(11) NOT NULL, `last_changeset_id` int(11) NOT NULL, `submitted_by` int(11) NOT NULL, `submitted_on` int(11) NOT NULL, `use_artifact_permissions` tinyint(1) NOT NULL default '0', PRIMARY KEY (`id`), KEY `idx_tracker_id` (`tracker_id`), KEY `idx_my` (`submitted_by`,`tracker_id`,`last_changeset_id`), KEY `idx_last_changeset_id` (`last_changeset_id`,`id`)) ENGINE=MyISAM AUTO_INCREMENT=2842 DEFAULT CHARSET=utf8;CREATE TABLE `tracker_changeset` ( `id` int(11) NOT NULL auto_increment, `artifact_id` int(11) NOT NULL, `submitted_by` int(11) default NULL, `submitted_on` int(11) NOT NULL, `email` varchar(255) default NULL, PRIMARY KEY (`id`), KEY `artifact_id` (`artifact_id`,`id`)) ENGINE=MyISAM AUTO_INCREMENT=3342 DEFAULT CHARSET=utf8;
Then I have a query that looks like that:
SELECT c.idFROM tracker_changeset AS c INNER JOIN tracker_artifact AS a ON (a.id = c.artifact_id)WHERE a.id IN (928,933,934,...) AND c.id IN (1398,1432,...);
But the 2 ranges are quite big (~1900 values in each) and the query is taking a lot of time (8s) but I don't undestand why.
Even explain is taking ages:
+----+-------------+-------+-------+---------------------+-------------+---------+--------------+------+--------------------------+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+-------+-------+---------------------+-------------+---------+--------------+------+--------------------------+| 1 | SIMPLE | a | range | PRIMARY | PRIMARY | 4 | NULL | 1909 | Using where; Using index | | 1 | SIMPLE | c | ref | PRIMARY,artifact_id | artifact_id | 4 | a.id | 1 | Using where; Using index | +----+-------------+-------+-------+---------------------+-------------+---------+--------------+------+--------------------------+2 rows in set (3.33 sec)
2 questions arise:
-> What I'm doing wrong there
-> What is the impact of huge IN() statements?
Comment