dapr / dapr/components-contrib

Postgres State Store - Support GIN indexes in Query API

Open
#2,524 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted kind/enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.