3

Assuming there's field of key-value data stored in jsonb format, that might not exist for some (few) records, what is preferable, performance wise for that case - null field or empty json object?

Data is to be queried by some key-value criteria not much more difficult than:

SELECT * FROM table WHERE id = :id AND jsondata @> '{"key1":"value1"}

and possibly indexed in future, so the concern is about querying - are null fields about to be skipped faster that ones with empty object?

1 Answer 1

2

NULLs are stored as a bitset in the row header, so they can be skipped slightly faster, but if you only have a "few" records with NULL values, the difference is unlikely to be noticeable.

You can also create a partial index to exclude the NULLs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.