The Problem
You have a MySQL query, let's say a SELECT
and you need to identify its overall cost in all aspect (Host Resource Usage, Query speed / performance ...) so that your result can be quantified and analyzed to determine whether or not the query is too expensive or not.
This question is really about overall database management so, requires someone that knows and understand a database in a big scale, with high usage and identify the danger at glance of a query on top of a complex database system, possibly a DB Admin (I am not sure about the generic role name in the industry)
Scenario
The reason I am asking this, is because I am facing a struggle to evaluate my own query but also to prove that my query is actually well performant (that is, to other people), this is because it has some query and subquery and raised some eyebrows (but they also don't know whether this query can perform well or not), so in order to be able to show in a scientific approach with actual number and stats so that we can see with concrete numbers how well such query can do.
Let's keep in count that, is going to have a high usage with huge database data and huge amount of reads / requests, and therefore the benchmark has to push the query to the limit.
The only way I am measure it right now is the actual speed of the Query (less then 1/2 second) but I am not keeping in count, resource usage or other things it should be check in a query (hence this question).
I am checking also with the EXPLAIN SELECT ...
and set profiling=1; query...; show profile;...
combo but to be fair, is not clear what is good/bad, I'd like actual number and stats (or better read those values)
What I am currently doing to measure cost/performance
I set up the database with the target tables with a huge amount of data.
- Query speed without a
WHERE
/LIMIT
(that's just as a general guidence to create the query structure, if the query lenght is more than 3s, than I discard it) - Query speed with final query including the
WHERE
/LIMIT
, the query at its maximum allowedLIMIT
(100_000) is currently at 53ms - Checking the query with
EXPLAIN
, but I am not really good at determine whether is a good result or not. I am mainly counting the total inrows
- Checking the
show profile
withprofiling
set to true, same as point 3. I am not so good at understanding if is good or not. - Now I decided to use MySQL workbench and checking the Performance -> Dashboard tab
Question
For the questions, please keep in mind the above scenario (especially the high usage part)
- What elements/properties do we need to measure for determine a good agains a bad SQL query (speed, cpu usage, memory usage, writes etc..) and at what threshold of each elements we put, where the threshold is good -> bad.
- What tools can we use to determine the above elements?
- What as a DB Admin, would you do to determine that a query added to a project is good and won't affect performance? How do you know is going to work?
PS: I am not posting the actual query, because I don't want influence the possible answer as this is a problem that we may face for any query.