New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: database/sql: add a sync.RWLock to Rows so we can invoke .Next() concurrently #21329
Comments
@pjebs thanks for the issue! I've updated the title a bit to try to reflect your intent, but the body could use some examples in order to make it a proposal that can be reviewed easily. You showed how rows are processed sequentially right now, what will the processing look like if the sync.RWLock is added and then rows can be processed concurrently? |
I don't necessarily have a good idea. I just know that the key to doing it is a In this example: https://stackoverflow.com/questions/33661442/how-to-concurrently-iterate-through-an-sql-result-set-in-golang It shows that the best we can do is process the stuff inside the loop concurrently instead of doing everything concurrently. |
Do the locking in your client code instead of slowing down all non-concurrent clients. |
And why is that not good enough? Ultimately the SQL database is handing back results one at a time. Even if we went through the effort of allowing concurrent calls to Next, they'd have to coordinate with a Mutex (not an RWMutex) to get access to the actual rows. Doing that in your code is going to run just as well, without having to introduce API complexity for all users. |
Closed in absence of a reason this must be inside database/sql (as opposed to outside, as I outlined in the last message). |
Can we put a sync.RWLock inside
Rows
so we can callrows.Next
concurrently?That way we can process the results in separate goroutines instead of processing them sequentially.
Sample code of how it's done now:
The text was updated successfully, but these errors were encountered: