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

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e49928-59d93.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e49928-59d93.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?