Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 为什么streamingresult的执行效率比 cursor fetch的执行效率高?底层实现上有什么不同呢。

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 为什么streamingresult的执行效率比 cursor fetch的执行效率高?底层实现上有什么不同呢。
Cursor fetch: The client initiates a request (for N records), the server receives the request and returns N records to the client, then saves the current state. When the client completes and requests N records again, the server recognizes the same connection and stmtid, and continues to send N records to the client based on the previously saved state. This way, the client and server keep interacting, and the amount of data transferred each time is not large, leading to slower efficiency. However, when the number of returned records is relatively small, the performance is not bad because there is not much network interaction. Additionally, since a single connection can be reused by multiple threads in the application, it may be more efficient for small data sets.
Therefore, streaming is more suitable for handling scenarios with larger result sets, while cursor fetch (greater than 0) is suitable for handling high concurrency, connection reuse, and smaller result sets.
The execution efficiency of streaming results is not necessarily higher than that of cursor fetch. In the case of large result sets, streaming results can retrieve data in a streaming manner without needing to fetch all the data at once. This allows for processing and analysis while retrieving data. On the other hand, cursor fetch needs to fetch all the data at once, which is less flexible than streaming results and puts more pressure on the database’s memory. Therefore, streaming results are more suitable than cursor fetch. In the case of small result sets, cursor fetch can avoid the delay caused by streaming data transmission, making it more efficient to fetch all the data at once.
Doesn’t streaming read also require setting fetchsize and min_value? I understand that it also returns data to the client in batches. Both methods require batching, so why is streaming read better?
Do you mean that streaming reads fetch data as it is sent, while cursor fetch retrieves all data first and then returns it in batches? Is the data that has not yet been returned stored in memory?
When the cursor fetch size is greater than 0, it does not query all the results at once and store them. After obtaining the required records, all operators are blocked, and the execution continues when the next request comes in.
Streaming without batching, the database continuously sends data into the network until completion.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.