Where,on and order by specify fields to be indexed
The result of a complex calculation should be written after the build rather than every read, unless the cost of writing is greater than the read
In addition to avoiding the occurrence of count (*) outside of paging, count data is added with a count field when writing to determine if there is a exists () function with a short-circuit mechanism
Avoid cases where sum () is used, and the corresponding results should be accumulated when a separate table is written
In any case, do not use not in (), use in (), exists (), not exists (), and union queries instead
In () can not contain SQL query, if need to include query, use exists () function and equivalent condition instead
In any case, you should avoid using an outer-connected query, instead of using an inline query + multiple SQL queries.
MariaDb SQL query Performance considerations