The difference between list and iterator in Query

1. The returned types are different, list() returns List, and iterate() returns Iterator.

2. The way to obtain data is different, list() directly queries the database, iterate() will first go to the database to retrieve the IDs, when querying non-ID data, it will first look in the cache, if not, it will be sent with the ID as the condition sql to the database for retrieval, so the number of queries is N+1.

3.iterate will query the second-level cache, and list will only query the first-level cache.

4. The entity object is returned in list(), and the proxy object is returned in iterate().

5. When list() is executed, it directly runs the required query statement, while iterator() executes the query to obtain the object ID first, and then obtains the required data according to the ID.

Summary: list() queries usually only execute one SQL statement, while iterator() queries may need to execute N+1 SQL statements (N is the number of records in the result set).

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326556602&siteId=291194637