You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- gin cannot use sort index, just btrees (or using btree_gin since pg12). the only alternative would be RUM
235
+
but its not guaranteed to be always faster. also doesnt support like op unless changing code:
236
+
see https://github.com/postgrespro/rum/issues/34 for supporting LIKE.
237
+
- gin is apparently not too helpful for very short string searches.
238
+
- btree not usable for text except for equals and startsWith.
239
+
240
+
create index on cache__demo_work_items using gin (
241
+
description gin_trgm_ops
242
+
, last_message_at
243
+
, reopened);
229
244
245
+
set enable_seqscan = "off";
246
+
explain analyze select * from cache__demo_work_items where description ilike '%54%' order by last_message_at desc;
247
+
248
+
1000 rows dataset: (to properly test index, rows returned must be >0)
249
+
Index Scan Backward using cache__demo_work_items_last_message_at_idx on cache__demo_work_items (cost=0.28..58.22 rows=20 width=145) (actual time=0.059..0.725 rows=20 loops=1)
250
+
Filter: (description ~~* '%54%'::text)
251
+
Rows Removed by Filter: 980
252
+
*/
230
253
case project_name
231
254
when 'demo_work_items' then
232
255
idx_def :='using gin (
233
-
title extensions.gin_trgm_ops
234
-
, line extensions.gin_trgm_ops
235
-
, ref extensions.gin_trgm_ops
256
+
title gin_trgm_ops
257
+
, line gin_trgm_ops
258
+
, description gin_trgm_ops
259
+
, ref gin_trgm_ops
260
+
, last_message_at
236
261
, reopened)';
237
262
when 'demo_two_work_items' then
238
263
idx_def :='using gin (
239
-
title extensions.gin_trgm_ops
264
+
title gin_trgm_ops
265
+
, description gin_trgm_ops
240
266
)';
241
267
else
242
268
idx_def :=''; raise exception 'No index definition found for cache__%' , project_name;
243
269
end case;
244
270
245
271
if idx_def <>''and not same_index_definition (idx_name , idx_def) then
246
-
execute FORMAT('create index newidx on cache__%I %s;' , project_name , idx_def);
247
-
--
248
-
execute FORMAT('drop index if exists %s;' , idx_name);
249
-
--
250
-
execute FORMAT('alter index newidx rename to %s;' , idx_name);
251
-
else
252
-
raise notice 'skipping identical create index statement: %' , idx_name;
0 commit comments