-
Notifications
You must be signed in to change notification settings - Fork 46
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
binary protocol [design] #24
Comments
If there's good upgrade story, I'm interested. Otherwise there is https://hackage.haskell.org/package/postgresql-binary (which I never used) |
I also use In the design below, my goal is that most application authors can pick up the speed improvements without changing their code. I think we should also provide some interface that gives more control, but I think most programmers won't want to think about encoding issues.
Key changes to get there: class FromField a where
fromField :: FieldParser a
fromFieldBinary :: Maybe (FieldParser a)
fromFieldBinary = Nothing
data RowParser a = RowParser
{ textRowParser :: ReaderT Row (StateT PQ.Column Conversion) a
, binaryRowParser :: Maybe (ReaderT Row (StateT PQ.Column Conversion) a)
} deriving Functor
instance Applicative RowParser where
pure a = RowParser (pure a) (Just (pure a))
f <*> (RowParser text binary) = RowParser (f <*> text) (fmap (f <*>) binary)
field :: FromField a => FromRow a
field = RowParser (fieldWith fromField) (fieldWith <$> fromFieldBinary) The binary decoder for any given field is optional. Downstream instances of What do you think? Worth turning into a PR that compiles? |
Sorry, for asking dumb questions:
That change doesn't look too intrusive. Note: there's I'd happy to see how it would look like, if it's doable in few hours. Feel free to implement only Thanks for contributing! |
I'm kind of worried, that maybe users want rather be sure that the binary protocol is used, Yet again, I wonder how something like So maybe the final design would have both Something to think about. Real use cases would help motivate. I think that guaranteed case would be important for some (many). My DB usage is usually very small data-wise, so I don't care that much. EDIT: e.g. in |
Good questions; I just didn't want my earlier comment to get too long.
I'm sure you're right that some users will really want to know that they're getting the fast path. I'm not sure how to balance that with the users who won't think to read the release notes, but should get the fast path anyway. I'd be fine having both the Thanks for the feedback! |
That's one problem. I'd prefer compile-time error. There are at least |
I found this issue, and I wanted to share that there's It's not finished yet but could be a decent alternative. You can find more context about the status of the project under the following issue: |
Hi @phadej: A few days ago I started working on a proof of concept of binary protocol support after tracking down some performance problems with a Persistent-based personal project of mine. I've taken a diametrically opposite approach, altering the core types like so:
Some parts of the existing codebase are format-agnostic, but the concrete I've got support for numeric types working and the test suite passing. There's an unavoidable semantic change between using PostgreSQL simple query and PostgreSQL extended query. Extended Query is needed in order to tell the server whether to respond using textual or binary formats, but it only accepts one command at a time. A string like There's a second unavoidable semantic change between using text and binary formats, which is that the text format is guaranteed to be stable in a way that the binary format is not -- the At least for a viable proof of concept, I'd suggest bifurcating the API is preferable. The question I've got is, is this a worthwhile approach to pursue? |
My best understanding is that having someone develop a separate When there is that, one can try to share common parts, but I don't think that |
Postgres (and libpq) support both text & binary formats in the wire protocol.
postgresql-simple
currently only uses the text format. Would you be interested in adding support for the binary format? If so, I'll post some design ideas here.I think we can upgrade many queries to the binary protocol without changes to downstream code, and fall back to the text when we don't have a binary decoder for some custom field type.
The text was updated successfully, but these errors were encountered: