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

  • SEARCH
  • Home
  • 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 6380997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:20:21+00:00 2026-05-25T02:20:21+00:00

Whet are things to look for when trying to optimize a mysql query that

  • 0

Whet are things to look for when trying to optimize a mysql query that joins 7 tables?

select trips.tripid as tripid
     , stops.stopdescrption as "perron"
     , DATE_FORMAT(segments.segmentstart, "%H:%i") as "time"
     , DATE_FORMAT( trips.tripend, "%H:%i") as "arrival"
     , UPPER(routes.routepublicidentifier) as "lijn"
     , plcend.placedescrption as "destination" 
from calendar
                join trips on calendar.vsid=trips.vsid
                join routes on routes.routeid=trips.routeid
                join places plcstart on plcstart.placeid=trips.placeidstart
                join places plcend on plcend.placeid=trips.placeidend
                join segments on segments.tripid = trips.tripid
                join stops on segments.stopid = stops.stopid 
where ( stops.stopid = :perrons0
     OR stops.stopid = :perrons1  OR stops.stopid = :perrons2 
     OR stops.stopid = :perrons3  OR stops.stopid = :perrons4 
     OR stops.stopid = :perrons5  OR stops.stopid = :perrons6 
     OR stops.stopid = :perrons7  OR stops.stopid = :perrons8 
     OR stops.stopid = :perrons9  OR stops.stopid = :perrons10 
     OR stops.stopid = :perrons11 OR stops.stopid = :perrons12 
     OR stops.stopid = :perrons13 OR stops.stopid = :perrons14 
      ) 
  AND calendar.vscdate = DATE(DATE_ADD(now(), INTERVAL "07:00" HOUR_MINUTE)) 
  AND segments.segmentstart >= TIME(DATE_ADD(now(), INTERVAL "07:00" HOUR_MINUTE))   
  AND routes.routeservicetype = 0 
  AND segments.segmentstart > "00:00:00" 
ORDER BY segments.segmentstart

There’s the query, I can’t seem to think of anything to change that’ll optimize this… it timeouts….

any tips are welcome!

  • 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-25T02:20:22+00:00Added an answer on May 25, 2026 at 2:20 am

    What about using the IN keyword instead of multiple OR. Also, you dont need to specify AND segments.segmentstart > "00:00:00" since you have already provided a condition segments.segmentstart >= TIME(DATE_ADD(now(), INTERVAL "07:00" HOUR_MINUTE)) which is greater than "00:00:00". Lastly, indexing your keys will be a good idea to optimize execution.

    select trips.tripid as tripid
     , stops.stopdescrption as "perron"
     , DATE_FORMAT(segments.segmentstart, "%H:%i") as "time"
     , DATE_FORMAT( trips.tripend, "%H:%i") as "arrival"
     , UPPER(routes.routepublicidentifier) as "lijn"
     , plcend.placedescrption as "destination" 
    from calendar
                join trips on calendar.vsid=trips.vsid
                join routes on routes.routeid=trips.routeid
                join places plcstart on plcstart.placeid=trips.placeidstart
                join places plcend on plcend.placeid=trips.placeidend
                join segments on segments.tripid = trips.tripid
                join stops on segments.stopid = stops.stopid 
    where  stops.stopid IN (:perrons0,
     :perrons1,:perrons2, 
     :perrons3, :perrons4, 
     :perrons5, :perrons6, 
     :perrons7,:perrons8, 
     :perrons9, :perrons10, 
     :perrons11, :perrons12, 
     :perrons13, :perrons14 
      ) 
    AND calendar.vscdate = DATE(DATE_ADD(now(), INTERVAL "07:00" HOUR_MINUTE)) 
    AND segments.segmentstart >= TIME(DATE_ADD(now(), INTERVAL "07:00" HOUR_MINUTE))   
    AND routes.routeservicetype = 0 
    
    ORDER BY segments.segmentstart
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whet I need to do is in my menu I would like to add
This is a design question, to whet the guru's appetite. In a previous version,
whet i am starting new Activity using this way below Intent edit = new
There are reams of info out there about things causing InProc session to drop
I am trying to add calendar event using the below code in my android
I've asked a question about changing the version of .Net sites in the IIS.
I have a small problem with jQuery $.ajax() function. I have a form where
The code #!/usr/bin/env python import MySQLdb print Content-Type: text/html print print <html><head><title>Books</title></head> print <body>
When i set to some view weight or height in dpi on others screen
I just installed Casandra on my windows machine. When I run cassandra.bat everything seems

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.