Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6854635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:39:29+00:00 2026-05-27T01:39:29+00:00

I got this query. It take ~ 0.0854 seconds to excutes. I find it

  • 0

I got this query. It take ~0.0854 seconds to excutes. I find it a little slow. Below see my explain

SELECT
    stops.stop_number,
    stops.stop_name_1,
    stops.stop_name_2
FROM
    tranzit.stops_times

INNER JOIN 
    tranzit.stops
ON
    (
        stops_times.stop_id = stops.stop_id
    )

INNER JOIN 
    tranzit.trips
ON
    (
        stops_times.trip_id = trips.trip_id
    )   
WHERE
    trips.route_id = 109 AND
    trips.trip_direction = 1 AND
    trips.trip_period_start <= "2011-11-24" AND
    trips.trip_period_end >= "2011-11-24"

GROUP BY
    stops.stop_id
ORDER BY
    stops_times.time_sequence ASC
LIMIT 
    0, 200

Explain

id  select_type     table           type            possible_keys                                           key                         key_len     ref                             rows    Extra
1   SIMPLE          trips           index_merge     trip_id,trip_period_start,trip_period_end,trip_dir...   route_id,trip_direction     3,1         NULL                            271     Using intersect(route_id,trip_direction); Using wh...
1   SIMPLE          stops_times     ref             stop_id,trip_id                                         trip_id                     16          tranzit.trips.trip_id           24   
1   SIMPLE          stops           ref             stop_id                                                 stop_id                     3           tranzit.stops_times.stop_id     1       Using where

And I have indexe on trips :

Table   Non_unique  Key_name    Seq_in_index    Column_name     Collation   Cardinality     Sub_part    Packed  Null    Index_type  Comment
trips   1   agency_id   1   agency_id   A   2   NULL    NULL        BTREE    
trips   1   trip_id     1   trip_id     A   9361    NULL    NULL        BTREE    
trips   1   trip_period_start   1   trip_period_start   A   2   NULL    NULL        BTREE    
trips   1   trip_period_end     1   trip_period_end     A   2   NULL    NULL        BTREE    
trips   1   trip_direction  1   trip_direction  A   2   NULL    NULL        BTREE    
trips   1   route_id    1   route_id    A   106     NULL    NULL        BTREE    
trips   1   shape_id    1   shape_id    A   520     NULL    NULL        BTREE    
trips   1   trip_terminus   1   trip_terminus   A   301     NULL    NULL        BTREE    

Indexes on stops

stop_number BTREE   Non Non stop_number 4626    A       
agency_id   BTREE   Non Non agency_id   1   A       
stop_id BTREE   Non Non stop_id 4626    A       

Thanks for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:39:29+00:00Added an answer on May 27, 2026 at 1:39 am

    I found something that work like a charm. My results number are :

    • 0.0011
    • 0.0008
    • 0.0017 (highest)
    • 0.0006 (lowest)
    • 0.0013

    These result aren’t from the cache. I switch all the WHERE in t (trips.agency_id, trips.route_id, trips.trip_direction, trips.trip_period_start, trips.trip_period_end) and it is working very good ! I can’t explain why but if someone can, i’d like to see why. Thanks a lot everyone !

    PS : Even without trips.agency_id it is working great.

    SELECT
        stops.stop_number, 
        stops.stop_name_1, 
        stops.stop_name_2
    FROM 
        tranzit.stops_times,
        tranzit.stops,
        (
            SELECT 
                trips.trip_id
            FROM
                tranzit.trips
            WHERE
                trips.agency_id = 5 AND
                trips.route_id = 109 AND
                trips.trip_direction = 0 AND
                trips.trip_period_start <= "2011-12-01" AND
                trips.trip_period_end >= "2011-12-01"
            LIMIT 1
        ) as t
    
    WHERE 
        stops_times.stop_id = stops.stop_id AND
        stops_times.trip_id in (t.trip_id)
    GROUP BY
        stops_times.stop_id
    ORDER BY
        stops_times.time_sequence ASC
    LIMIT 
        0, 200
    
    
    id  select_type     table           type        possible_keys       key         key_len     ref                             rows    Extra
    1   PRIMARY         <derived2>      system      NULL                NULL        NULL        NULL                            1       Using temporary; Using filesort
    1   PRIMARY         stops_times     ref         trip_id,stop_id     trip_id     16          const                           33      Using where
    1   PRIMARY         stops           ref         stop_id             stop_id     3           tranzit.stops_times.stop_id     1       Using where
    2   DERIVED         trips           ref         testing             testing     4                                           275     Using where
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this query that works ok, select * from Materia where Cursar_Cursada=0 and
i got this SQL query where post_title taken from $_GET $sql = SELECT ID
I got this Sql Query declare @ProductNo int set @ProductNo = 123 select o.OrderNo,
Right, so I've got a query that looks like this: $bestof_query = SELECT *
I've got a mysql query like this: SELECT A.ID, A.NAME, B.ID, B.NAME FROM table1
I got a linq query. I wanna take this query results to a dataset.
Hello I've got this query to get users by email, which is an unique
So I need to make 3 tabs with query (got this part down), but
Got this error on a big $_GET query in size ~9 000 symbols (they
I got this error running a query that goes against 2 tables with combined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.