Re: Anyway to index array with other columns

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Chris Hoover <chrish(at)aweber(dot)com>, pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: Anyway to index array with other columns
Date: 2023-08-03 06:30:44
Message-ID: c33f14e7990deba1020eaf568cf6c1182d3e63b3.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Wed, 2023-08-02 at 16:17 -0400, Chris Hoover wrote:
> Given table below, is there any way to index  field_a, field_b, array_a?
>
> Create table table1 (
> field_a integer not null primary key,
> field_b integer not null,
> ...
> array_a text[]
> )
>
> My app is running queries similar to this:
> Select * from table1 where field_a = 123 and field_b = 456 and array_a @> ARRAY[’tag_xyz’];
>
> The array_a can have unto 1000 elements.  Currently these queries get very expensive if the array has any length to it.

That seems unlikely, since you have the primary key in the WHERE condition.

Can you provide the output of EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
for the query?

Yours,
Laurenz Albe

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Laurenz Albe 2023-08-03 12:37:11 Re: analyze foreign tables
Previous Message David G. Johnston 2023-08-02 20:24:24 Re: Anyway to index array with other columns