|
|
|
|
|
by nh2
2835 days ago
|
|
I found that the full-text search on JSON worked remarkably well with Postgres 10 -- surprisingly this was the least of all problems. The issue with slow counting is this from the wiki page: > PostgreSQL will take advantage of available indexes against the restricted field(s) to limit how many records must be counted, which can greatly accelerate such queries. PostgreSQL will still need to read the resulting rows to verify that they exist; other database systems may only need to reference the index in this situation. Typical scenario: If you make a trivial query that matches a lot of rows (even when using an index). You want to count the number of results in order to tell the user how much they probably have to scroll through (quite important when digging through logs, to know whether you'll have to scroll through doable 3 pages, or impossible 3000 pages). SELECT COUNT(*) FROM logs WHERE object->>environment == 'production'
Then the WHERE will match 100 million rows, and postgres will scan them all for existence (due to reason quoted above), no matter if `object->>environment` has an index on it or not.This will take many minutes, even on SSDs, just for showing a COUNT. |
|
I suspect that to make a fast-counting time series mechanism for Postgres, you'd need to create a new index type that used a columnar approach (or even used Lucene unerneath). I don't know much about what optimization options are available to Postgres extensions, but it doesn't sound like it would be impossible.