database - Indexing array of strings column type in PostgreSql -


is possible create index on column type array of strings. tried using gin indexes. queries not seem using indexes.

example  create table users (  name varchar(100),  groups text[], );  query: select name users any(groups) = 'engineering'. 

also best way perform group on 'groups' column efficiently can give 'groups' , count.

a gin index can used:

create table users (  name varchar(100),  groups text[] );  create index idx_users on users using gin(groups);  -- disable sequential scan in test: set enable_seqscan off;  explain analyze select name users  groups @> (array['engineering']); 

result:

"bitmap heap scan on users  (cost=4.26..8.27 rows=1 width=218) (actual time=0.021..0.021 rows=0 loops=1)" "  recheck cond: (groups @> '{engineering}'::text[])" "  ->  bitmap index scan on idx_users  (cost=0.00..4.26 rows=1 width=0) (actual time=0.016..0.016 rows=0 loops=1)" "        index cond: (groups @> '{engineering}'::text[])" "total runtime: 0.074 ms" 

using aggregate functions on array, problem. function unnest() might help.

why don't normalize data? fix problems, including many problems didn't encouter yet.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -