テーブルとジンインデックスがあり、 100万個の乱数を挿入。0 < 数値 < 100,000。
2 つの同等のクエリをテストする
create table Test
(
id serial primary key,
code varchar(255) not null
);
create index Test_code_gin on Test using gin (code gin_trgm_ops);
-- Test1
explain analyse
select * from Test where code like '1234';
-- Test2
explain analyse
select * from Test where code = '1234';
テスト 1 は gin_trgm_ops インデックスを使用、実行時間: 1.640 ミリ秒。
Test2 はインデックスを使用しません。実行時間: 24.531 ms;
PostgreSQL でインデックスを使用するにはどうすればよいですか? または、ORM 戦略と SQL ステートメントを変更しますか? または単に BTree インデックスを追加しますか?