sql - left join done after 13 second on 7000 records - mysql -
i have table this:
create table `gps` ( `id` int(11) not null, `driver_id` int(11) not null, `trucks_drivers_id` int(11) not null, `x` varchar(100) collate utf8_persian_ci not null, `y` varchar(100) collate utf8_persian_ci not null, `speed` varchar(100) collate utf8_persian_ci not null, `time_stamp` timestamp not null default current_timestamp ) engine=myisam default charset=utf8 collate=utf8_persian_ci;
number of records 7000.
my query :
select m1.* gps m1 left join gps m2 on (m1.driver_id = m2.driver_id , m1.id < m2.id) m2.id null
but result take long time:
showing rows 0 - 4 (5 total, query took 13.1221 seconds.)
why?!
someone tell me use index
speed query. got syntax error:
select m1.* gps m1 left join gps m2 force index(m1.*) on (m1.driver_id = m2.driver_id , m1.id < m2.id) m2.id null
for query:
select m1.* gps m1 left join gps m2 on m1.driver_id = m2.driver_id , m1.id < m2.id m2.id null;
you want index on gps(driver_id, id)
. need create index before can use it:
create index idx_gps_driverid_id on gps(driver_id, id);
Comments
Post a Comment