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

sql/pgwire: fix encoding of int4 and bpchar in tuples #61013

Merged
merged 4 commits into from
Feb 24, 2021

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented Feb 23, 2021

fixes #58069

This includes 3 commits:

sql/pgwire: make PGTest pass against PostgresSQL

There are a few minor differences: dataTypeSize is different for tuples,
and PG does not show seconds offset for times if it is zero.

sql/pgwire: fix binary encoding of ints in tuples

sql/pgwire: fix text encoding of bpchar in tuples

sql/pgwire: fix encoding of collated strings

Release note (bug fix): Integers inside of tuples were not being encoded
properly when using the binary format for retrieving data. This is now
fixed, and the proper integer width is reported.

Release note (bug fix): Blank-padded chars (e.g. CHAR(3)) were not being
encoded correctly when returning results to the client. Now they
correctly include blank-padding when appropriate.

Release note (bug fix): Collated strings were not encoded with the
proper type OID when sending results to the client if the OID was
for the char type. This is now fixed.

There are a few minor differences: dataTypeSize is different for tuples,
and PG does not show seconds offset for times if it is zero.

Release note: None
Release note (bug fix): Integers inside of tuples were not being encoded
properly when using the binary format for retrieving data. This is now
fixed, and the proper integer width is reported.
@rafiss rafiss requested review from otan and a team February 23, 2021 17:45
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Release note (bug fix): Blank-padded chars (e.g. CHAR(3)) were not being
encoded correctly when returning results to the client. Now they
correctly include blank-padding when appropriate.
@rafiss rafiss force-pushed the tuple-binary-encoding branch from 98df18a to f970cac Compare February 23, 2021 18:23
@@ -422,7 +410,7 @@ func (b *writeBuffer) writeBinaryDatum(
b.writeLengthPrefixedString(v.LogicalRep)

case *tree.DString:
b.writeLengthPrefixedString(resolveBlankPaddedChar(string(*v), t))
b.writeLengthPrefixedString(tree.ResolveBlankPaddedChar(string(*v), t))

case *tree.DCollatedString:
b.writeLengthPrefixedString(v.Contents)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to resolve blank padded chars for collated strings too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i think i should add it

@blathers-crl blathers-crl bot requested a review from otan February 23, 2021 22:10
Release note (bug fix): Collated strings were not encoded with the
proper type OID when sending results to the client if the OID was
for the `char` type. This is now fixed.
@rafiss rafiss force-pushed the tuple-binary-encoding branch from e561c73 to 837efef Compare February 23, 2021 23:30
Copy link
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. are we backporting this?

@@ -184,6 +184,11 @@ func TestEncodings(t *testing.T) {
case *tree.DTuple:
// Unsupported.
continue
case *tree.DCollatedString:
// Decoding collated strings is unsupported by this test. The encoded
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

treating collated strings differently to postgres has truly been a pain :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the gift that keeps giving

@rafiss
Copy link
Collaborator Author

rafiss commented Feb 24, 2021

tftr!

bors r=otan

@craig
Copy link
Contributor

craig bot commented Feb 24, 2021

Build failed (retrying...):

@rafiss
Copy link
Collaborator Author

rafiss commented Feb 24, 2021

bors r=otan

@craig
Copy link
Contributor

craig bot commented Feb 24, 2021

Already running a review

@craig
Copy link
Contributor

craig bot commented Feb 24, 2021

This PR was included in a batch that was canceled, it will be automatically retried

@craig
Copy link
Contributor

craig bot commented Feb 24, 2021

Build succeeded:

@craig craig bot merged commit 7f4c550 into cockroachdb:master Feb 24, 2021
@rafiss rafiss deleted the tuple-binary-encoding branch February 26, 2021 04:51
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.

sql/pg_wire: Binary encoding of int4 in tuple doesn't match Postgres
3 participants