Home » Javascript » group by / distinct mysql vs javascript filter performance

group by / distinct mysql vs javascript filter performance

Posted by: admin November 1, 2017 Leave a comment

Questions:

Say I have a many to many relationship and when I query the db for the left table using a join from the right table I get duplicates because of this many to many relationship. I can use group by on the primary key to get rid of these in mysql or distinct.

However I’ve been told that distinct & group by are not good re:performance. With that said, I would also assume mysql performance would be better than javascript performance.

Should I be filtering my results in javascript or use group by in mysql? Any reason why one would be faster than the other?

Answers:

it depends on how much data and how many concurrent users:

  • if the data is reasonably low and not much concurrent users then mysql group by/distinct is the best solution.
  • if the data is reasonably low and high concurrent users then Javascript filtering is the best solution here.
  • if the data is large regardless of how many concurrent users then you should look for another solution than just group by/distinct and I’m not talking about filtering in javascript because in this case the huge data will cause low performance in user’s browser.