Index for range queries on JSON (user defined fields) - Mailing list pgsql-performance

From Marco Colli
Subject Index for range queries on JSON (user defined fields)
Date
Msg-id CAFvCgN7Q0Ur2Gsrejai+Qsw=iz0pWBWhgZmNeu2455SGbSZzJg@mail.gmail.com
Whole thread Raw
Responses Re: Index for range queries on JSON (user defined fields)  (Nick Cleaton <nick@cleaton.net>)
List pgsql-performance
Hello!

We have a multi-tenant service where each customer has millions of users (total: ~150M rows). Now we would like to let each customer define some custom columns for his users and then let the customer search his users efficiently based on these columns.

This problem seems really hard to solve with PostgreSQL:

In particular the easiest way would be to add a JSON field on the users table (e.g. user metadata). However the PostgreSQL GIN index only supports exact matches and not range queries. This means that a query on a range (e.g. age > 30) would be extremely inefficient and would result in a table scan.

Algorithmically it seems possible to use a GIN index (based on btree) for a range query. Also MongoDB seems to support something similar (https://docs.mongodb.com/manual/core/index-wildcard/).

Are there any plans to add support for range queries to GIN indexes (on JSON) in the future versions of PostgreSQL?


Marco Colli
Pushpad

pgsql-performance by date:

Previous
From: Riswana Rahman
Date:
Subject: PostgeSQL JSONB Column with various type of data
Next
From: Michael Lewis
Date:
Subject: Re: PostgeSQL JSONB Column with various type of data