mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.22k stars 2.53k forks source link

Question: Will the results still be streamed if individual columns are selected? #2523

Closed marnixhoh closed 2 years ago

marnixhoh commented 2 years ago

The documentation says that rows will always be buffered entirely, whether individual columns are selected or not.

My question is, how should this be interpreted?

Will selecting individual columns like below, result in the entire stream to be buffered first? (I.e. making the streaming mechanism useless). Or does it mean that even though individual columns are selected, the entire row will always be included in the stream? (Some unnecessary bandwidth, but not the end of the world)

SELECT table1.field AS field1, table2.field AS field2
FROM table1
LEFT JOIN table2 ON table1.fk = table2.id
WHERE table1.id > 10

Please let me know if I should clarify anything :)

Thanks!

dougwilson commented 2 years ago

For each row, all of the column data is buffered and then the event is emitted for each row. This behavior is the same no matter how many columns are in your data set. The SQL server only sends the column selected over the network, and this module will always emit to the code all the data received over the network; no additional filtering of the data is performed by this library.

marnixhoh commented 2 years ago

@dougwilson Thank you for clarifying! I misinterpreted the docs. The docs are talking about it not being possible to stream individual fields. But selecting specific columns is of course possible.