?
Solved

Calculate Run time Query not Working

Posted on 2010-01-08
4
Medium Priority
?
338 Views
Last Modified: 2012-08-13
hi experts

I m working at GPS project and i want to calculate the total vehicle working time . The time selected by client or user.

I m using below query and its working but its very slow it is taking 3-4 minutes to calculate only 1 day vehicle driven time....

please help me to improve this query performance and time ...
SELECT SQL_CALC_FOUND_ROWS Lat,Longi, ID, Speed,ObjectId,GpsTime   , MAX(StopTime) as mx, MIN(StartTime) AS mn, SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(StopTime, StartTime)))) AS TotalWorkTime  FROM ( sELECT Lat,Longi, ID, Speed,ObjectId,GpsTime    , GpsTime AS StopTime    , COALESCE((  SELECT MAX(b.GpsTime)   FROM xydata b   WHERE ObjectId='" + Objectid + "' and ClientId='" + id + "'  AND GpsTime > '" + from+"  " +result + "' AND  GpsTime < '" + to+"  " +result1 + "' AND  b.ObjectId = a.ObjectId  AND b.GpsTime < a.GpsTime  ),GpsTime) AS StartTime  fROM xydata a where ObjectId='" + Objectid + "' and ClientId='" + id + "' AND GpsTime > '01-08-2010 00:00:01' AND  GpsTime < '01-08-2010 11:59:59' AND Speed >  '3' ) derived Group by Lat  order by GpsTime asc  limit 1,700

Open in new window

0
Comment
Question by:Sachin_Ajmani
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Zlatko Kuzmanovski earned 2000 total points
ID: 26210072
Hi,

This should work:

Add an index on xydata table, on these fields:
-ObjectId
-ClientId

Please preserve the column ordering in the index.
Please let me know...

Note: If such index is already present, please add column: GpsTime. last to the above.

Regards,
Zlatko.
0
 

Author Comment

by:Sachin_Ajmani
ID: 26210492
hi ZLATKO:

ObjectId and GpsTime is already indexes and they both present in  xydata table but ClientId is not index ...

i will check my query after changes ClientId into Index and i will tell you and please reply me about your note...

Note: If such index is already present, please add column: GpsTime. last to the above.

I m not getting this...


Thanks for reply....
0
 
LVL 3

Assisted Solution

by:Zlatko Kuzmanovski
Zlatko Kuzmanovski earned 2000 total points
ID: 26211875
Hi,

In order to have your query fastened, multi-column index must be present, not separate index on ObjectId, and/or GpsTime. The index should include the two (or three) columns in itself.

Regards,
Zlatko.
slika.JPG
0
 

Author Comment

by:Sachin_Ajmani
ID: 26254925
hi ZLATKO:

Thank you so much...
now my query is executing very fast ....

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this article, we’ll look at how to deploy ProxySQL.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question