title: Postgres is using UNIQUE index instead of FTS index
body: <p>I have a table with &gt; 10.000.000 rows. The table has a column <code>OfficialEnterprise_vatNumber</code> that should be unique and can be part of a full text search.</p>
  <p>Here are the indexes:</p>
  <pre><code>&quot;uq_officialenterprise_vatnumber&quot;   &quot;CREATE UNIQUE INDEX uq_officialenterprise_vatnumber ON commonservices.&quot;&quot;OfficialEnterprise&quot;&quot; USING btree (&quot;&quot;OfficialEnterprise_vatNumber&quot;&quot;)&quot;
  &quot;ix_officialenterprise_vatnumber&quot;   &quot;CREATE INDEX ix_officialenterprise_vatnumber ON commonservices.&quot;&quot;OfficialEnterprise&quot;&quot; USING gin (to_tsvector('commonservices.unaccent_dictionary'::regconfig, (&quot;&quot;OfficialEnterprise_vatNumber&quot;&quot;)::text))&quot;
  </code></pre>
  <p>But if I <code>EXPLAIN</code> a query that should be using the <code>FTS</code> index like this</p>
  <pre><code>SELECT * FROM commonservices.&quot;OfficialEnterprise&quot; 
  WHERE 
    to_tsvector('commonservices.unaccent_dictionary', &quot;OfficialEnterprise_vatNumber&quot;) @@ to_tsquery('FR:* | IE:*')
  ORDER BY &quot;OfficialEnterprise_vatNumber&quot; ASC 
  LIMIT 100
  </code></pre>
  <p>It shows that the used index is <code>uq_officialenterprise_vatnumber</code> and not <code>ix_officialenterprise_vatnumber</code>.</p>
  <p>Is their something I'm missing ?</p>
  <p><strong>EDIT</strong>:</p>
  <p>Here is the <code>EXPLAIN ANALYZE</code> statement of the original query.</p>
  <pre><code>&quot;Limit  (cost=0.43..1460.27 rows=100 width=238) (actual time=6996.976..6997.057 rows=15 loops=1)&quot;
  &quot;  -&gt;  Index Scan using uq_officialenterprise_vatnumber on &quot;&quot;OfficialEnterprise&quot;&quot;  (cost=0.43..1067861.32 rows=73149 width=238) (actual time=6996.975..6997.054 rows=15 loops=1)&quot;
  &quot;        Filter: (to_tsvector('commonservices.unaccent_dictionary'::regconfig, (&quot;&quot;OfficialEnterprise_vatNumber&quot;&quot;)::text) @@ to_tsquery('FR:* | IE:*'::text))&quot;
  &quot;        Rows Removed by Filter: 1847197&quot;
  &quot;Planning Time: 0.185 ms&quot;
  &quot;Execution Time: 6997.081 ms&quot;
  </code></pre>
  <p>Here is the <code>EXPLAIN ANALYZE</code> of the query if I add <code>|| '0'</code> to the order by.</p>
  <pre><code>&quot;Limit  (cost=55558.82..55570.49 rows=100 width=270) (actual time=7.069..9.827 rows=15 loops=1)&quot;
  &quot;  -&gt;  Gather Merge  (cost=55558.82..62671.09 rows=60958 width=270) (actual time=7.068..9.823 rows=15 loops=1)&quot;
  &quot;        Workers Planned: 2&quot;
  &quot;        Workers Launched: 2&quot;
  &quot;        -&gt;  Sort  (cost=54558.80..54635.00 rows=30479 width=270) (actual time=0.235..0.238 rows=5 loops=3)&quot;
  &quot;              Sort Key: (((&quot;&quot;OfficialEnterprise_vatNumber&quot;&quot;)::text || '0'::text))&quot;
  &quot;              Sort Method: quicksort  Memory: 28kB&quot;
  &quot;              Worker 0:  Sort Method: quicksort  Memory: 25kB&quot;
  &quot;              Worker 1:  Sort Method: quicksort  Memory: 25kB&quot;
  &quot;              -&gt;  Parallel Bitmap Heap Scan on &quot;&quot;OfficialEnterprise&quot;&quot;  (cost=719.16..53393.91 rows=30479 width=270) (actual time=0.157..0.166 rows=5 loops=3)&quot;
  &quot;                    Recheck Cond: (to_tsvector('commonservices.unaccent_dictionary'::regconfig, (&quot;&quot;OfficialEnterprise_vatNumber&quot;&quot;)::text) @@ to_tsquery('FR:* | IE:*'::text))&quot;
  &quot;                    Heap Blocks: exact=6&quot;
  &quot;                    -&gt;  Bitmap Index Scan on ix_officialenterprise_vatnumber  (cost=0.00..700.87 rows=73149 width=0) (actual time=0.356..0.358 rows=15 loops=1)&quot;
  &quot;                          Index Cond: (to_tsvector('commonservices.unaccent_dictionary'::regconfig, (&quot;&quot;OfficialEnterprise_vatNumber&quot;&quot;)::text) @@ to_tsquery('FR:* | IE:*'::text))&quot;
  &quot;Planning Time: 0.108 ms&quot;
  &quot;Execution Time: 9.886 ms&quot;
  </code></pre>