Skip to content
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

Add support for retrieving multiple results. #2

Merged
merged 2 commits into from
Feb 22, 2016

Conversation

petermattis
Copy link

If the special \next query is executed, the driver looks for another
set of results on the connection. If no such results are found,
ErrNoMoreResults is returned. Also accessible via the conn.Next()
method, though this later interface requires direct interaction with
lib/pq instead of going through the database/sql package.

Reworked how the msg-ready command (`Z`) is processed. Previously
execution of a query would look for the msg-ready command before
completing the operation. Now, when executing a query, the driver places
the connection into a state where it knows there may be more results. If
another query is subsequently executed, the driver waits for the
msg-ready command to arrive, discarding any other commands, before
sending the new query.
@tamird
Copy link

tamird commented Feb 22, 2016

heh, this was confusing. I guess you force pushed master here.

Is this the same as #1?

@petermattis
Copy link
Author

Yeah, I forced-pushed master to reset us to the upstream state. Then realized the error of my ways.

It is almost the same as #1, modulo the conn.Next() interface.

@bdarnell
Copy link

Before we merge this I'd like to have a plan for cockroachdb/cockroach#3993. I think that issue is going to require a larger refactoring and a more generic interface on pq.conn, and we might be able to implement next-result fetching without a special query.

My thinking for cockroachdb/cockroach#3993 is that we'd take all of the recv loops that currently exist in the code and replace them with one method that reads until it gets a Z, returning a list of "result" objects (which could be either a sql.Result or an sql.Rows). simpleExec, simpleQuery and friends could be implemented in terms of this method, and our CLI would call it directly.

@petermattis
Copy link
Author

My plan for cockroachdb/cockroach#3993 is less invasive. Currently pq.rows.Next ignores the "command complete" tag (C). I think what we need to do is to give to have it parse the command complete tag (using parseComplete) and provide an API for retrieving the rows affected info.

I'd like to avoid returning a list (slice?) of result or row objects from a single method call. Doing so requires buffering all of the results in memory instead of streaming them off the wire. Is there a particular problem with the conn.Next() interface.

@bdarnell
Copy link

There's not a particular problem with Next; it's just a little ugly that it's implemented with a magic query string under the hood. Good point about the buffering; that rules out returning a sequence of results.

I still think it would be a little cleaner if the recv() loop were in Next() and simpleQuery were implemented in terms of Next rather than the other way around. I'm imagining that simpleExec (and the more complex versions) could be unified into Next but maybe that would be tougher than it looks.

LGTM

@petermattis
Copy link
Author

The only purpose of the magic query now is for conn_test.go changes. I could make the magic query string an implementation detail (there is no need to export it).

@bdarnell
Copy link

I'm less concerned about exporting the query string than the direction of the relationship between simpleQuery and Next. But let's leave it unexported so we have the option of changing the implementation in the future.

If the special `\next` query is executed, the driver looks for another
set of results on the connection. If no such results are found,
ErrNoMoreResults is returned. Also accessible via the `conn.Next()`
method, though this later interface requires direct interaction with
lib/pq instead of going through the database/sql package.
@petermattis petermattis force-pushed the pmattis/multiple-results2 branch from d6104a2 to f24e08a Compare February 22, 2016 22:00
@petermattis
Copy link
Author

Ok, unexported the magic query string and renamed to nextResultQuery to avoid some confusion with the nextResult variable in conn.simpleQuery.

petermattis added a commit that referenced this pull request Feb 22, 2016
Add support for retrieving multiple results.
@petermattis petermattis merged commit 7789309 into master Feb 22, 2016
@petermattis petermattis deleted the pmattis/multiple-results2 branch February 22, 2016 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants