dapr / dapr/components-contrib
Postgres State Store - Support GIN indexes in Query API
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 602
- Forks
- 580
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 6
Description
Describe the feature
Certain databases like CosmosDB automatically index every key of a document, and benefit from improved query times on larger tables because of it
It would be nice if we could take advantage of the similar GIN index in Postgres.
From what I can tell, it's just a matter of exposing a toggle and a slightly different translateFieldToFilter function.
The current syntax for queries generated something like
SELECT * FROM public.state WHERE value->>'somefield' = 'somevalue'
Taking advantage of a GIN index is as simple as
SELECT * FROM public.state WHERE value @> '{"somefield": "somevalue"}';
I can contribute to this, but looking for some feedback on whether we have already considered something like this, and if no is it a good idea? Seems like a simple enough change with a big enough payday to be worthwhile. In some local testing I saw upwards of 7000x better performance on the above queries and a table with 10M record.
Release Note
Enable it on the State Store component, it would be nice if we could create the GIN index as well while creating the table if the setting is enabled.
RELEASE NOTE:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Postgres State Store Query API and the translateFieldToFilter function mentioned in the issue, then inspect how the state table is created. Check how a setting could control GIN index creation and query translation, and identify the existing tests for these paths. Done means the setting enables the index and corresponding @> queries without changing the default behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100