Add CopyOut! interface for >5x faster data queries #241
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! I tend to do
SELECT
queries that return a large dataset for which the standard method takes a few seconds:PostgreSQL supports the
COPY TO
API and I found it to be faster, so I implemented it! Use] add https://github.com/cmey/LibPQ.jl#copy-out
to try it out!(we already support the
COPY FROM
API for fast ingestion which I took heavy inspiration from)Both methods return equal outputs:
The new API expects the user to pass a "string builder" type of construct in the form of a
IOBuffer
that, during execution, gets filled with the text of the CSV returned by the database.I found this didn't fit well with the table-style of
Result
, since this is just a text blob.Note that CSV API changed from CSV version 0.8 to 0.9, and that Julia <1.3.0-1 loads the old CSV, that's why there is the VERSION check in the test code, to support the test run on Julia 1.0.
I hope others will find this helpful! I certainly found this helped me, as I see >10x speed improvement in real-life use cases.