optimizing simple mysql query
I have a very simple query:

    SELECT cp.`id_connections`
	FROM `connections_page` cp
	WHERE cp.`time_end` IS NULL
	AND TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
	GROUP BY cp.`id_connections`

for a very simple table:

    CREATE TABLE IF NOT EXISTS `ps_connections_page` (
    `id_connections` int(10) unsigned NOT NULL,
    `id_page` int(10) unsigned NOT NULL,
    `time_start` datetime NOT NULL,
    `time_end` datetime DEFAULT NULL,
    PRIMARY KEY (`id_connections`,`id_page`,`time_start`),
    KEY `time_end` (`time_end`),
    KEY `id_connections` (`id_connections`),
    KEY `id_page` (`id_page`),
    KEY `time_start` (`time_start`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;


with about **2.5 millions rows**, and it **takes between 2 and 6 seconds** to execute (mysql 5.1.54-log)


 and **EXPLAIN EXTENDED** says:

    id	    select_type    table	type	possible_keys	key	        key_len	ref	    rows	filtered	Extra
    1	    SIMPLE    	   cp	    ref	    time_end	    time_end    9	    const	1497890	100.00	    Using where; Using temporary; Using filesort


Looking at execution plan, there is something wrong with index usage, but I can't figure it out. So: how can I do to speed up this query **witohut changing data structure** (I can change query and / or indexes, but not columns)?





optimizing simple mysql query
===

I have a very simple query:

    SELECT cp.`id_connections`
	FROM `connections_page` cp
	WHERE cp.`time_end` IS NULL
	AND TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
	GROUP BY cp.`id_connections`

for a very simple table:

    CREATE TABLE IF NOT EXISTS `ps_connections_page` (
    `id_connections` int(10) unsigned NOT NULL,
    `id_page` int(10) unsigned NOT NULL,
    `time_start` datetime NOT NULL,
    `time_end` datetime DEFAULT NULL,
    PRIMARY KEY (`id_connections`,`id_page`,`time_start`),
    KEY `time_end` (`time_end`),
    KEY `id_connections` (`id_connections`),
    KEY `id_page` (`id_page`),
    KEY `time_start` (`time_start`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;


with about **2.5 millions rows**, and it **takes between 2 and 6 seconds** to execute (mysql 5.1.54-log)


 and **EXPLAIN EXTENDED** says:

    id	    select_type    table	type	possible_keys	key	        key_len	ref	    rows	filtered	Extra
    1	    SIMPLE    	   cp	    ref	    time_end	    time_end    9	    const	1497890	100.00	    Using where; Using temporary; Using filesort


Looking at execution plan, there is something wrong with index usage, but I can't figure it out. So: how can I do to speed up this query **witohut changing data structure** (I can change query and / or indexes, but not columns)?




