title: Multi-column index with ts_vector and int types
body: <p>I would like to make this query :</p>
  <pre><code>SELECT
      *
  FROM
      &quot;public&quot;.&quot;items&quot;
  WHERE
      &quot;created_at_ts&quot; &gt; '2022-04-16 09:50'
      AND catalog_id = ANY (ARRAY [
         1237,
         1238,
         1239,
         1241,
         1242
       ])
      AND brand_id = ANY (ARRAY [53])
      AND size_id = ANY (ARRAY [780,782,784])
      AND 0 &lt;= price_numeric AND 100 &gt;= price_numeric
      AND color1_id = ANY (ARRAY [1,12])
      AND status_id = ANY (ARRAY [1,2,3,4,6])
      AND(fr_ts @@ to_tsquery('french', replace(TRIM(BOTH FROM 'nike'), ' ', ' &amp; ')))
  ORDER BY
      created_at_ts
  </code></pre>
  <p>I have currently those indexes</p>
  <pre><code>idx_items_id_key, BTREE, id
  idx_items_created_at_ts, BTREE, created_at_ts
  fr_ts_idx, GIN, fr_ts
  </code></pre>
  <p>The query plan looks like this</p>
  <pre><code>Sort  (cost=87579.91..87579.91 rows=1 width=682) (actual time=53.855..53.894 rows=318 loops=1)
    Sort Key: created_at_ts
    Sort Method: quicksort  Memory: 316kB
    Buffers: shared hit=29957
    -&gt;  Bitmap Heap Scan on items  (cost=796.77..87579.90 rows=1 width=682) (actual time=12.434..53.379 rows=318 loops=1)
  &quot;        Recheck Cond: (fr_ts @@ '''nik'''::tsquery)&quot;
  &quot;        Filter: ((brand_id = ANY ('{53}'::integer[])) AND (created_at_ts &gt; '2022-04-16 09:50:00'::timestamp without time zone) AND ('0'::numeric &lt;= price_numeric) AND ('100'::numeric &gt;= price_numeric) AND (color1_id = ANY ('{1,12}'::integer[])) AND (size_id = ANY ('{780,782,784}'::integer[])) AND (catalog_id = ANY ('{1237,1238,1239,1241,1242}'::integer[])) AND (status_id = ANY ('{1,2,3,4,6}'::integer[])))&quot;
          Rows Removed by Filter: 33604
          Heap Blocks: exact=29810
          Buffers: shared hit=29957
          -&gt;  Bitmap Index Scan on fr_ts_idx  (cost=0.00..796.77 rows=32103 width=0) (actual time=8.223..8.223 rows=33922 loops=1)
  &quot;              Index Cond: (fr_ts @@ '''nik'''::tsquery)&quot;
                Buffers: shared hit=147
  Planning:
    Buffers: shared hit=24
  Planning Time: 0.357 ms
  Execution Time: 54.302 ms
  </code></pre>
  <p>Which indexes should I build to make it faster ?<br />
  Should I create one index per column or a multi-column index that combines the ts_vector and int4 columns and then how should it be built ?</p>
  <p>Thanks</p>