Как вы видели, это не будет хорошо работать с триграммами. Триграммы не совпадают по границе пространства, поэтому, если все ваши данные содержат одинаковые слова, индекс будет соответствовать каждой строке.
Это может прояснить ситуацию:
with data as (select * from (values ('^ first 1 | second 3'),
('^ first 1 | second 2 ^ first 2 | second 3'),
('^ first 1 | second 2 | second 3'),
('^ first 2 | second 3 ^ first 1 | second 2 | second 2'),
('^ first 2 | second 3 ^ first 1 | second 3')
) v(keyvalues)
)
select keyvalues, show_trgm(keyvalues) from data;
keyvalues | show_trgm
------------------------------------------------------+-------------------------------------------------------------------------------------------------------
^ first 1 | second 3 | {" 1"," 3"," f"," s"," 1 "," 3 "," fi"," se",con,eco,fir,irs,"nd ",ond,rst,sec,"st "}
^ first 1 | second 2 ^ first 2 | second 3 | {" 1"," 2"," 3"," f"," s"," 1 "," 2 "," 3 "," fi"," se",con,eco,fir,irs,"nd ",ond,rst,sec,"st "}
^ first 1 | second 2 | second 3 | {" 1"," 2"," 3"," f"," s"," 1 "," 2 "," 3 "," fi"," se",con,eco,fir,irs,"nd ",ond,rst,sec,"st "}
^ first 2 | second 3 ^ first 1 | second 2 | second 2 | {" 1"," 2"," 3"," f"," s"," 1 "," 2 "," 3 "," fi"," se",con,eco,fir,irs,"nd ",ond,rst,sec,"st "}
^ first 2 | second 3 ^ first 1 | second 3 | {" 1"," 2"," 3"," f"," s"," 1 "," 2 "," 3 "," fi"," se",con,eco,fir,irs,"nd ",ond,rst,sec,"st "}
Не могли бы вы использовать частичный индекс для исключения строк с ^ в середине?