Menu

1 / 3

JSONB performance: declare access patterns to PostgreSQL query planner

DEV Community: postgres·Franck Pachot·10 days ago
#4LsSTH0j
#devtopostgresql#devto#dev#rows#record
Long article (3813 words) — no AI summary yet.
Reading 0:00
15s threshold

A common drawback of storing data in JSON fields is limited planner visibility: the optimizer doesn't automatically inspect documents, so selectivity estimates for JSON (or JSONB or BSON) predicates are often weak when useful statistics aren’t available. That’s expected—if you choose JSON to avoid defining the full application schema in the database upfront, the database can’t infer everything about those fields.

But this isn’t an all-or-nothing tradeoff. Even in MongoDB, you still declare part of the schema in practice—especially filter fields—through indexes. PostgreSQL, gives you two levers:

expression indexes (which provide both access paths and statistics)

extended statistics (which improve estimates even without adding an index).

I'm using an example from an old article by Dan Robinson on the Heap blog: When To Avoid JSONB In A PostgreSQL Schema .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.