3 ms·
yes re table definition. To answer your question, for indexing there's a couple of options: - if you know which fields you want to index, use an expression ind
by asah 3y ago
yes re table definition.
To answer your question, for indexing there's a couple of options:
- if you know which fields you want to index, use an expression index with a regular B-tree.
- if you don't know which fields you want to index, use a GIN index on the whole field.
Blogpost which covers both cases:
https://scalegrid.io/blog/using-jsonb-in-postgresql-how-to-effectively-store-index-json-data-in-postgresql https://scalegrid.io/blog/using-jsonb-in-postgresql-how-to-e...
That said, I generally don't bother indexing the "raw" table, but instead create a parsed+summary table that breaks out the fields I want to index into 'real' sql columns and summarizes the data to reduce the number of records. In particular, I use a partitioned table for the raw data which keeps the data-per-table tiny enough to fit in RAM, and "real time" queries just hit the latest raw table(s). For big, real-time data, I sometimes use TABLESAMPLE queries to create estimates, or triggers to do exact counting (which is what NoSQL databases do, just without the nice structure of triggers).