pg_trgm index not used with commutator PostgreSQL 9.6, on a table with ~100000 rows of text up to 3200 characters long.

I have the trigram indexes:

CREATE INDEX trgm_idx_gin ON test_trgm USING gin (t gin_trgm_ops);
CREATE INDEX trgm_idx_gist ON test_trgm USING gist (t gist_trgm_ops);


SELECT t, 'word' &lt;&lt;-&gt; t AS dist
  FROM test_trgm
  ORDER BY dist LIMIT 10;


Index is used as predicted by the documentation, execution: 331 ms.

Limit  (cost=0.41..23.91 rows=10 width=886)
  -&gt;  Index Scan using trgm_idx_gist on test_trgm  (cost=0.41..421142.11 rows=179185 width=886)
        Order By: (t &lt;-&gt;&gt; 'word'::text)


But the commutator &lt;-&gt;&gt; of the &lt;&lt;-&gt; operator for word_similarity() does not use the index:

SELECT t, 'word' &lt;-&gt;&gt; t AS dist
  FROM test_trgm
  ORDER BY dist LIMIT 10;


Execution: 38 s, more than 100x more.

Limit  (cost=70833.94..70833.96 rows=10 width=886)
  -&gt;  Sort  (cost=70833.94..71281.90 rows=179185 width=886)
        Sort Key: (('word'::text &lt;-&gt;&gt; t))
        -&gt;  Seq Scan on test_trgm  (cost=0.00..66961.81 rows=179185 width=886)


How could I speed up the commutator?
You cannot.  These are different operations, and only one of them is supported by the index.  If you were to swap the order of the arguments as well as the operator itself, then it would be the same operation and the index would still support it.

Although it might be possible that you could modify the source code of pg_trgm to support this other operation.  I doubt it would be very efficient, though.