pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15948: TRGM gin index is not be taken into account when using like all (array)
3+ messages / 3 participants
[nested] [flat]

* BUG #15948: TRGM gin index is not be taken into account when using like all (array)
@ 2019-08-11 23:35 PG Bug reporting form <noreply@postgresql.org>
  2019-08-11 23:41 ` Re: BUG #15948: TRGM gin index is not be taken into account when using like all (array) Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2019-08-11 23:35 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: james.inform@pharmapp.de

The following bug has been logged on the website:

Bug reference:      15948
Logged by:          James Inform
Email address:      james.inform@pharmapp.de
PostgreSQL version: 11.5
Operating system:   Mac OS X 10.13 / Ubuntu 18.04 LTS
Description:        

Use the following to reproduce the problem:

create extension pg_trgm;
create table mytable(myid int8 primary key, mytext text);
insert into mytable select g,md5(g::text) from generate_series(1,100000)
g;
create index gin1 on mytable using gin(mytext gin_trgm_ops);

-- Now there is the following record existing in the table
-- myid: 7 mytext: 8f14e45fceea167a5a36dedd4bea2543

-- Now try to query all record which contain "36dedd" AND "4e45f"
-- Using LIKE ALL, a seq scan is used which is very expensive
explain analyze
select * from mytable where mytext like all (array['%36dedd%','%4e45f%']);

-- Seq Scan on mytable  (cost=0.00..2185.00 rows=1 width=41) (actual
time=0.012..16.302 rows=1 loops=1)
--   Filter: (mytext ~~ ALL ('{%36dedd%,%4e45f%}'::text[]))
--  Rows Removed by Filter: 99999
-- Planning Time: 0.071 ms
-- Execution Time: 16.312 ms

-- Rewriting the same query with an where clause using the AND operator
works like one would expect from the LIKE ALL 
explain analyze
select * from mytable where mytext like '%36dedd%' and mytext like
'%4e45f%';

-- Bitmap Heap Scan on mytable  (cost=22.00..23.02 rows=1 width=41) (actual
time=0.136..0.136 rows=1 loops=1)
--   Recheck Cond: ((mytext ~~ '%36dedd%'::text) AND (mytext ~~
'%4e45f%'::text))
--   Heap Blocks: exact=1
--   ->  Bitmap Index Scan on gin1  (cost=0.00..22.00 rows=1 width=0)
(actual time=0.130..0.130 rows=1 loops=1)
--         Index Cond: ((mytext ~~ '%36dedd%'::text) AND (mytext ~~
'%4e45f%'::text))
-- Planning Time: 0.084 ms
-- Execution Time: 0.155 ms

So, is this a bug or a feature? ;)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15948: TRGM gin index is not be taken into account when using like all (array)
  2019-08-11 23:35 BUG #15948: TRGM gin index is not be taken into account when using like all (array) PG Bug reporting form <noreply@postgresql.org>
@ 2019-08-11 23:41 ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-08-12 09:57   ` Re: BUG #15948: TRGM gin index is not be taken into account when using like all (array) James Inform <james.inform@pharmapp.de>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2019-08-11 23:41 UTC (permalink / raw)
  To: james.inform@pharmapp.de; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> -- Now try to query all record which contain "36dedd" AND "4e45f"
> -- Using LIKE ALL, a seq scan is used which is very expensive
> explain analyze
> select * from mytable where mytext like all (array['%36dedd%','%4e45f%']);

This is not a bug.  At most it's an unimplemented feature ...
one I can't get very excited about, considering how little
use there is for such queries.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15948: TRGM gin index is not be taken into account when using like all (array)
  2019-08-11 23:35 BUG #15948: TRGM gin index is not be taken into account when using like all (array) PG Bug reporting form <noreply@postgresql.org>
  2019-08-11 23:41 ` Re: BUG #15948: TRGM gin index is not be taken into account when using like all (array) Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-08-12 09:57   ` James Inform <james.inform@pharmapp.de>
  0 siblings, 0 replies; 3+ messages in thread

From: James Inform @ 2019-08-12 09:57 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

<!DOCTYPE html>
<html><head>
    <meta charset="UTF-8">
</head><body><p><br></p><blockquote type="cite">On August 12, 2019 at 1:41 AM Tom Lane &#60;<a href="mailto:tgl@sss.pgh.pa.us">tgl@sss.pgh.pa.us</a>&#62; wrote:<br><br><br>PG Bug reporting form &#60;<a href="mailto:noreply@postgresql.org">noreply@postgresql.org</a>&#62; writes:<blockquote type="cite">-- Now try to query all record which contain &#34;36dedd&#34; AND &#34;4e45f&#34;<br>-- Using LIKE ALL, a seq scan is used which is very expensive<br>explain analyze<br>select * from mytable where mytext like all (array[&#39;%36dedd%&#39;,&#39;%4e45f%&#39;]);</blockquote><br>This is not a bug. At most it&#39;s an unimplemented feature ...<br>one I can&#39;t get very excited about, considering how little<br>use there is for such queries.<br><br> regards, tom lane</blockquote><p>Thanks for the clarification. I just stumbled about this because</p><p><code><strong>select * from mytable where mytext like any (array[&#39;%36dedd%&#39;,&#39;%4e45f%&#39;])</strong></code></p><p>uses the gin index the same way as</p><p><code><strong>select * from mytable where mytext like &#39;%36dedd%&#39; or mytext like &#39;%4e45f%&#39;</strong></code></p><p>does.</p><p><br></p><p>Its not a show stopper in any way, but for me a working</p><p><strong><code>select * from mytable where mytext like all (array[&#39;%36dedd%&#39;,&#39;%4e45f%&#39;])</code></strong></p><p>would be more elegant and more readable, because I am dealing with big amounts of free text columns.</p><p>Although I use full text search on those columns, I have a need to identify records where different search strings are contained (front and end masked, like &#39;%part%&#39;). This is because the free texts have many compound words, where I want to find words containing specific search strings.</p><p><br></p><p><em>Maybe this could be a good starting point for me for becoming involved. Could someone point me to the relevant source code area where this <strong>&#34;LIKE ALL&#34;</strong> handling should be implemented?!</em></p></body></html>
 





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2019-08-12 09:57 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-08-11 23:35 BUG #15948: TRGM gin index is not be taken into account when using like all (array) PG Bug reporting form <noreply@postgresql.org>
2019-08-11 23:41 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-12 09:57   ` James Inform <james.inform@pharmapp.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox