0

I have been collecting different information and storing it in one MySql table. The table data is refreshed daily and contains percentages, totals, listed by locations or by "all" for combined totals. Around 800 records.

On my status hud I want to display all this information in different viewers.

My question is for performance, should I use one query, and use conditional statements and loops to display the data. Or should I have multiple very specific queries?

Eddie B
  • 57
  • 7
  • This really depends on the table structure. – Uueerdo Feb 22 '18 at 18:44
  • My table structure seems to be well thought out. Every record has a unique id, description, location...I could build it either way, I just wondered which method was preferred. – Eddie B Feb 22 '18 at 18:48
  • 1
    Yeah it's very much depended on you design. Usually reading the data from DB is more expensive than in-memory operations if the dataset is not so large. – Vinit Sarvade Feb 22 '18 at 18:50
  • If you try multiple querys make sure you don't end up with an [N+1 problem](https://stackoverflow.com/questions/97197/what-is-n1-select-query-issue) – Twillen Feb 22 '18 at 19:00
  • @EddieB it is not a matter of "well thought out" or not; that helps whether one query is used or ten; different data can call for different tactics. _(Not to mention the least "well thought out" design, a single table for all data, would probably not require more than one query.)_ – Uueerdo Feb 22 '18 at 19:09
  • 2
    I guess trying different methods and see which works best with you is way better than asking without providing the appropriate requirements to the community. So, Try then Share what you've tried, your opinions, results, anything that would help both teams to achieve your goal. OR better yet, you might not need us at all!. – iSR5 Feb 22 '18 at 19:53
  • Sounds good. First I'll try multiple small and specific queries since I read that MySQL does better with small queries than with more complex ones and it should be easier to manage. I'll let the "SO" community know what I find out after testing. – Eddie B Feb 22 '18 at 19:58
  • Is it a lot of data? If not, I'd go with just one query. It's very expensive (relatively) to make multiple small queries. What does your network look like? What types of drives are in your database? Multiple queries means multiple connections to your database and multiple read/writes. I'm usually in favor of making as few trips to the database as possible. – Shawn Feb 23 '18 at 14:51

0 Answers0