cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

pgwire: add encoding for JSON arguments

Open rafiss opened this issue 3 years ago • 3 comments
trafficstars

fixes https://github.com/cockroachdb/cockroach/issues/88355

This adds pgwire decoding support for JSON (oid=114). This does not add oid=114 to the OidToType map in types.go since that introduces many other assumptions about the type; namely that the type can be used as the type of a column descriptor. That change would mean that existing tables that were defined with JSON would be inconsistent with new tables defined with a JSON column.

Release note (sql change): The pgwire protocol implementation can now accept arguments of the JSON type (oid=114). Previously, it could only accept JSONB (oid=3802). Internally, JSON and JSONB values are still identical, so this change only affects how the values are received over the wire protocol.

rafiss avatar Sep 21 '22 19:09 rafiss

This change is Reviewable

cockroach-teamcity avatar Sep 21 '22 19:09 cockroach-teamcity

hmm, i did miss the test failures though:

[TestCleanupDoesNotDeleteParentsWithChildObjects/clean-up-database-with-schema] === RUN   TestCleanupDoesNotDeleteParentsWithChildObjects/clean-up-database-with-schema
panic: oid 0 couldn't be mapped to array oid [recovered]
	panic: oid 0 couldn't be mapped to array oid

goroutine 22090 [running]:
github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).recover(0xc0046863f0, {0x6012450, 0xc008552690})
	github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:248 +0xa5
panic({0x47ebd80, 0xc000af9950})
	GOROOT/src/runtime/panic.go:884 +0x212
github.com/cockroachdb/cockroach/pkg/sql/types.CalcArrayOid(0x87bf7a0?)
	github.com/cockroachdb/cockroach/pkg/sql/types/pkg/sql/types/oid.go:231 +0x10e
github.com/cockroachdb/cockroach/pkg/sql.addPGTypeRow({{0x6042c10?, 0xc008484000?}}, {0x606eb88?, 0xc007da75e0}, {0x606f508?, 0x8b87820}, 0x87bf7a0, 0xc001ecd380)
	github.com/cockroachdb/cockroach/pkg/sql/pg_catalog.go:3035 +0x3b5
github.com/cockroachdb/cockroach/pkg/sql.glob..func235.1({0x6099b80, 0xc0056b2d80})
	github.com/cockroachdb/cockroach/pkg/sql/pg_catalog.go:3120 +0x13e
github.com/cockroachdb/cockroach/pkg/sql.forEachDatabaseDesc({0x6012450, 0xc008552690}, 0xc004cc3dd0, {0x6099b80?, 0xc0056b2d80?}, 0x0, 0xc00544fd50)
	github.com/cockroachdb/cockroach/pkg/sql/information_schema.go:2349 +0x232
github.com/cockroachdb/cockroach/pkg/sql.glob..func235({0x6012450, 0xc008552690}, 0xc004cc3dd0, {0x6099b80, 0xc0056b2d80}, 0xc001ecd380)
	github.com/cockroachdb/cockroach/pkg/sql/pg_catalog.go:3114 +0x105
github.com/cockroachdb/cockroach/pkg/sql.(*virtualDefEntry).getPlanInfo.func1.1({0x6012450, 0xc008552690}, {0x5fe28c0?, 0xc007da7580})
	github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:572 +0x156
github.com/cockroachdb/cockroach/pkg/sql.setupGenerator.func3({0x6012450, 0xc008552690})
	github.com/cockroachdb/cockroach/pkg/sql/virtual_table.go:127 +0x114
github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunAsyncTaskEx.func2()
	github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:489 +0x146
created by github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunAsyncTaskEx
	github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:480 +0x43b

that seems ... undesirable. let me know if this turns out to have a surprise change and i'll review it again.

by the looks of it you "just" need an entry in oidToArrayOid

otan avatar Sep 21 '22 21:09 otan

@otan could you give it another review? i ended up taking the type out of the OidToType map since that would be too invasive. there are some smaller special cases now when decoding in pgwire. (see commit message too.)

rafiss avatar Sep 22 '22 20:09 rafiss

tftr!

bors r=ZhouXing19

rafiss avatar Sep 23 '22 14:09 rafiss

Build succeeded:

craig[bot] avatar Sep 23 '22 16:09 craig[bot]