This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Help Improve Query Performance  RSS feed

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a query which counts the amount of work that some workers have done in a given day. In its most simple form the query is



The actual query has even more joins than I have shown here but this is the core of it.

The problem is that this query is really slow. Can anyone offer suggestions to speed it up?

One idea is to create a seperate table with only 2 columns (workCount,workDate), and to have a trigger update this table. Is this feasible? Is there a better way?

Thanks.
 
author & internet detective
Posts: 39129
723
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jehan,
Since there are no where conditions, there it it's harder to tune the query. If you are joining on something that isn't a key, there might still be scope to add an index.

Your idea to create a calculation summary table is a good one though. Presuming that updates are a lot less frequent than reads, that sounds like the way to go.
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,

Thanks for taking the time to help me, I appreciate it.

So if I were to create a calculation summary table, I would probably need a trigger to update it from the source table right?

Can you please offer some suggestions on how I can write this trigger based on the query I provided? Because I have the count, group by and joins the trigger syntax is not clear for me based on the simple examples I found online. I am using a MySQL DB.

Thanks.
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to advise how to optimize a query we haven't seen. Besides ensuring that all joins happen on indexed columns (as Jeanne already suggested), you may want to take a look at the query plan MySQL executes to make sure there are few (or no) table scans involved: http://dev.mysql.com/doc/refman/5.1/en/execution-plan-information.html
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!