php - Indexing Mysql Group BY Query -


hi have table called train_stop have ~1 million rows.

i have following query-

select * (select * train_stop code='xyz' , active=1 union select * train_stop code='abc' union select * train_stop code='stu'...... ) t3 group t3.number order departs 

this query uses same table train_stop. first select rows based upon code , group number. have tried indexing different columns above query uses using temporary, using filesort. execution time of order of seconds. please tell if there better way write above query , indexing strategy optimize , results in milliseconds. useful.

create statement `create table `train_stop` (   `number` varchar(1000) not null,   `stop_number` int(11) not null,   `code` varchar(1000) not null,   `station name` varchar(1000) not null,   `arrives` time not null,   `departs` time not null,   `halt` varchar(1000) not null,   `pf` varchar(1000) not null,   `day` int(11) not null,   `km` varchar(1000) not null,   `speed` varchar(1000) not null,   `elev` varchar(1000) not null,   `zone` varchar(1000) not null,   `address` varchar(1000) not null,   `active` int(11) default '1',   key `index_1` (`number`(767),`code`(767)),   key `pindex` (`number`(767),`stop_number`),   key `three_columns_idx` (`code`(767),`active`,`departs`),   key `two_columns_idx` (`code`(767),`active`),   key `two_columns_group_idx` (`number`(767),`departs`),   key `one_columns_group_idx` (`departs`) ) engine=innodb default charset=latin1` 

i think query traverse whole table 1 time each subquery , bottleneck. please try one

select * train_stop (code='xyz' , active=1) or (code='abc') or (code='stu') ... group number order departs 

and regard query uses group by statement, think cannot write select * please narrow selection phrase!!!


Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

java - Incorrect order of records in M-M relationship in hibernate -