-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: Add INET column type and IPAddr datum #18171
Conversation
4e253bc
to
c45b288
Compare
You also need to test the comparison of |
Yep, those comparisons are tested at a few levels but there aren't too many in the logic tests (or they are incorrect). I haven't made the logic tests thorough because storing and retrieving the values isn't working. |
CIDR has nothing to do with compound types. I think what you should be looking at to find something to reuse is the difference between DName and DString. |
Also, talk to Jordan. |
8809939
to
e27eed7
Compare
@jordanlewis @knz please take a look :). This PR is done and working 🎉 . I've left comments in for places to add the CIDR column, which I can remove before merging if desired as I'll defer that to another PR. A few questions I had:
|
@LEGO Postgres's wire protocol is documented in Chapter 51 of the PostgreSQL docs. The morpheme "pgwire" is a Cockroachism, which is why Googling it is so useless. The rest of the internet calls pgwire the "Postgres protocol" or similar. All that said, the Postgres docs will usually just direct you to the source to determine the encoding for a particular datum.
https://www.postgresql.org/docs/current/static/protocol-overview.html I think the file you want to look at here is https://github.com/postgres/postgres/blob/81c5e46c490e2426db243eada186995da5bb0ba7/src/backend/utils/adt/network.c. |
6cfefd7
to
f77bff3
Compare
Was that the Review status: 44 of 48 files reviewed at latest revision, 5 unresolved discussions. c-deps/rocksdb, line 1 at r9 (raw file): Previously, knz (kena) wrote…
Okay, got it after the gitmodules were being tricky :) (It keeps auto-changing even when it was reset, but the proper one was getting staged and the other wasn't but I kept adding it. pkg/cli/dump_test.go, line 61 at r11 (raw file): Previously, knz (kena) wrote…
Done. Comments from Reviewable |
f77bff3
to
e827dfa
Compare
Reviewed 4 of 4 files at r12. Comments from Reviewable |
you forgot to run Review status: all files reviewed at latest revision, 3 unresolved discussions, some commit checks pending. Comments from Reviewable |
e827dfa
to
6ca8545
Compare
👍 thanks. Also realized where the Review status: 47 of 48 files reviewed at latest revision, 3 unresolved discussions. Comments from Reviewable |
81ebc8f
to
3bd6de6
Compare
Ah something I left as a TODO, currently, the encoding is using 16-bytes for an IPv4 address. I'm going to swap that back to being more optimal for IPv4. I dropped that when I first made the switch to uint128. I reckon it's no easy matter to change this after the initial feature. Review status: 42 of 48 files reviewed at latest revision, 3 unresolved discussions, all commit checks successful. Comments from Reviewable |
Okay let's do that. Let me know when it's ready. |
3bd6de6
to
d183262
Compare
👍 just pushed it up Review status: 37 of 48 files reviewed at latest revision, 3 unresolved discussions, some commit checks pending. Comments from Reviewable |
Reviewed 2 of 21 files at r5, 11 of 11 files at r13. pkg/util/ipaddr/ipaddr.go, line 65 at r13 (raw file):
Period missing at end of sentence. pkg/util/ipaddr/ipaddr.go, line 73 at r13 (raw file):
appendTo = append(appendTo, 0, 0, 0, 0)
binary.BigEndian.PutUint32(tmp[len(tmp)-5:len(tmp)], ...) pkg/util/ipaddr/ipaddr.go, line 78 at r13 (raw file):
ditto no need to copy the data twice. Comments from Reviewable |
4347fc2
to
9039c48
Compare
Review status: 47 of 48 files reviewed at latest revision, 6 unresolved discussions, all commit checks successful. pkg/util/ipaddr/ipaddr.go, line 65 at r13 (raw file): Previously, knz (kena) wrote…
Done. pkg/util/ipaddr/ipaddr.go, line 73 at r13 (raw file):
pkg/util/ipaddr/ipaddr.go, line 78 at r13 (raw file): Previously, knz (kena) wrote…
Done. Comments from Reviewable |
Reviewed 1 of 21 files at r5, 1 of 1 files at r14. pkg/util/ipaddr/ipaddr.go, line 73 at r13 (raw file): Previously, lego (Joey Pereira) wrote…
Yes append of these zeros will allocate the extra space. Comments from Reviewable |
This introduces upport for the PostgreSQL column type, INET, which can be found at https://www.postgresql.org/docs/9.6/static/datatype-net-types.html.
9039c48
to
060e60b
Compare
This is an implementation for the
INET
postgres column type, found at Network Address Types. Related to #6981. At the moment this PR does not contain functions or operators found on Network Address Functions and Operators, but this is being done in another PR.I've added
pkg/util/ipaddr/ipaddr.go
to provide utility functions as a wrapper aroundnet.IPNet
. This includes marshaling to/from binary and parsing INET addresses (and in the future parsing CIDR).The parsing functions were made as Go's
net.ParseIP
andnet.ParseCIDR
don't suffice for postgres compatibility. Postgres INET values can have partial octets and a trailing.
. For example these values are valid,Another key factor is that under Go an IPv4-mapped IPv6 address is equal to it's mapped IPv4 address, while in postgres this is not the case. This presents a problem, so we need to differentiate between the families explicitly. This is also important for ordering properties seen below.
Go
Postgres
Encoding
The encoding scheme is
The family can be 4 or 6, and the mask can be 1-32 for IPv4, or 1-128 for IPv6.
If the IP is IPv6, it will be 16-bytes. This falls close to Postgres, where they will use 1 additional byte in total[1].
[1]: I've yet to figure out why they have one extra byte. See their Network Address Types