performance considerations of jsonb vs separate rows

From: Rob Nikander <rob(dot)nikander(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: performance considerations of jsonb vs separate rows
Date: 2017-06-19 19:29:40
Message-ID: 34B9328E-F435-4460-A877-96F61AC62CEE@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I’ve got a web app where I want to store user’s session data. The schema in this data changes a lot so it may be useful here to store the session properties in either a jsonb column, or in multiple rows. Something like:

session_id | data
100 { a: 1, bar: 2 ...
101 { a: 3, baz: 123 …

or

session_id | name | value
100 a 1
100 bar 2
101 baz 123
101 a 3
...

The app currently does something like option 1, but on an older pre-jsonb version of postgres, so the field is just text. I’m hoping to upgrade Postgres soon so jsonb is an option.

I'm wondering about the tradeoffs, specifically: is it possible to update one piece of a jsonb value without having to rewrite the entire field? There are cases where that data field was getting pretty big (500kb). Would you expect any obvious performance differences between these two options?

Yes, I’ll need to build performance tests myself, but that’s a lot of work to get two realistic situations with millions of rows, so I’m wondering about guesses or common knowledge on this.

thanks,
Rob

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Kretschmer 2017-06-19 19:51:46 Re: performance considerations of jsonb vs separate rows
Previous Message Bill Moran 2017-06-19 18:18:29 Re: autovacuum holds exclusive lock on table preventing it from to be updated