jsonb / json / hstore
jsonb = rails 4.2+, psql 9.4+
hstore = psql 9.2+
JSONb & JSON
JSON:
stores an exact copy of the text
only expression index (rails 5)
must be re-parsed (same key ordering)
JSONb:
store as a binary
index(rails4.2) & expression index(rails 5)
no need to re-parse (key ordering is not guaranteed)
hStore vs JSONb & JSON
hstore:
no nested
only string format -> type coercion on both db & app layers -> Virtus gem helper for type coercion.
JSONb & JSON
no type coercion
can be nested
expression index
add_index :table_name, "(field-'array_key')", using: :gin, name: 'index_table_name_on_field_array_keys'
GiST and GIN
GIN(>100K unique terms) indexes are faster to search, but they take more time to index & process.
GiST(< 100K unique terms) - indexes are slower than GIN indexes, but faster to update.
Last updated
Was this helpful?