Optimization of count query for PostgreSQL

前端 未结 3 789
南笙
南笙 2021-01-05 08:44

I have a table in postgresql that contains an array which is updated constantly.

In my application i need to get the number of rows for which a specific parameter is

3条回答
  •  臣服心动
    2021-01-05 09:46

    I think with Your current data model You are out of luck. Try to think of an algorithm that the database has to execute for Your query. There is no way it could work without sequential scanning of data.

    Can You arrange the column so that it stores the inverse of data (so that the the query would be select count(id) from table where ARRAY[‘parameter value’] <@ table.array_column) ? This query would use a gin/gist index.

提交回复
热议问题