I've got a performance related question. I've got...
# sql
e
I've got a performance related question. I've got a fairly large object of data I'd like to store in each row. Previously I extracted out the data into their own columns, but since I can query
jsonb
, I technically don't need to do this anymore. Question is; are queries slower / costly when using jsonb vs querying a single value in a column?
b
You can index items in JSONB to make it perform just as fast as any other column.
There's nothing inherently slow about JSONB, and more so than a TEXT field, I think. If you need to query something contained in a JSONB, and you need it to be fast, just index that data.
e
Right thanks - would indexing work if the data was a different structure in some rows?
b
Yes, it'll work, but if you're indexing something and it doesn't exist in the JSONB for a row, it'll be
null
.
So if I have a JSONB and I put
firstname
lastname
and
age
in the JSONB, and some records only have
firstname
in them, then
lastname
and
age
would be null (think of them as empty columns if you had stored it as regular columns)
e
Oh sweet, and would that work (indexing) with a deeply nested structure too?
b
It should, yes.
e
Very cool, thanks for the help.