Which is faster, PHP traversal query or mysql connected table query?

I would like to ask the gods, the speed of unwritten-out writing is fast, or the speed of logged-out is fast, why?
now it is a joint check of two tables, and the amount of data is small. If there is a large amount of data, which method is more advantageous? Why?

clipboard.png

Mar.03,2021

comparing the two methods, the operation of concatenating tables must be better, and never write sql, in a loop using IN in mysql instead of


depends on the amount of data in the table. In the case of a small amount of data, the connected table query will not cause performance problems; if the amount of data is large, do not consider using the connected table associated query.
Index the table appropriately and split the connected table query sql into two single table queries.


federated query is not a problem for a small amount of data query, but in the case of large amount of data, and subsequent table structure changes, or sub-database sub-table is not conducive to optimization


this question should be compared according to the order of magnitude of your data.
if the order of magnitude is very large, the mysql original sql statement is faster


.

the so-called performance is for a large amount of data, if you do not build a database index, both methods are very slow, if you build an index, both methods are about the same.

in real development, which writing method to use is based on whether it is easy to implement, and as for execution efficiency, index is established.


generally speaking, the join table is faster, but it should be noted that the index of the join table should be done well, otherwise the large amount of data will be slower than the circular query

.
Menu