Index not used when doing join on two text arrays using overlap operator with Postgresql 9.4 -
trying optimize join below, cost still seems high. there way how force postgres use index when doing join on 2 text array fields?
-> unique (cost=16508500.04..16510899.32 rows=319904 width=38) (actual time=580978.121..581078.948 rows=415229 loops=1) -> sort (cost=16508500.04..16509299.80 rows=319904 width=38) (actual time=580978.120..581013.446 rows=415229 loops=1) sort key: t992_1.name, t294_1.name sort method: quicksort memory: 51186kb -> nested loop (cost=0.00..16479249.17 rows=319904 width=38) (actual time=1.335..579142.184 rows=415229 loops=1) join filter: (array_lowercase((t294_1.name)::character varying[]) && array_lowercase((t992_1.name)::character varying[])) rows removed join filter: 31577903 -> seq scan on c04 t992_1 (cost=0.00..4106.69 rows=69848 width=195) (actual time=0.003..40.408 rows=69854 loops=1) filter: __name_flag rows removed filter: 15 -> materialize (cost=0.00..95.87 rows=458 width=83) (actual time=0.000..0.031 rows=458 loops=69854) -> seq scan on cat t294_1 (cost=0.00..93.58 rows=458 width=83) (actual time=0.003..0.381 rows=458 loops=1) the problematic part of query array_lowercase(t294_1.name) && array_lowercase(t992_1.name). have gin index on both columns (with array_lowercase).
in end i've solved using different function index. original function defined below won't used:
create or replace function array_lowercase(character varying[]) returns character varying[] $body$ select array_agg(q.tag) ( select btrim(lower(unnest($1)))::varchar tag ) q; $body$ language sql immutable cost 100;` but if array_lowercase function defined differently using text[] instead of character varying[] it's picked , used automatically:
create or replace function array_lowercase(text[]) returns text[] $body$ select array_agg(q.tag) ( select btrim(lower(unnest($1))) tag ) q; $body$ language sql immutable cost 100;
Comments
Post a Comment