In MySQL, how to choose between “multiple queries of 100 pieces” and “one query of 100 pieces of data”?

  mysql, question

If you consider the network environment, it is certainly faster to query 100 pieces of data at a time, but what if you don’t consider the network environment? Considering only the query speed of MySQL, is it faster to query 100 times one at a time, or is it faster to query 100 times at a time?

Generally speaking, it is faster to query 100 items at a time. It mainly explains the cost of sql statements, planning query methods, index addressing, etc. In addition, the difference is more obvious for queries that do not use indexes to scan tables. One scans from beginning to end to find the data, and the other scans from beginning to end 100 times …