Re: LIKE CLAUSE on VIEWS - Mailing list pgsql-performance

From Jeff Janes
Subject Re: LIKE CLAUSE on VIEWS
Date
Msg-id CAMkU=1waKK_oe1omYO9xHOed0M-B3oQMcG4n9znEp0HOxy8aqA@mail.gmail.com
Whole thread Raw
In response to LIKE CLAUSE on VIEWS  (aditya desai <admad123@gmail.com>)
List pgsql-performance
On Sun, Jan 22, 2023 at 6:34 AM aditya desai <admad123@gmail.com> wrote:
Hi,
Is there any way to improve performance of LIKE clause on VIEWS.

select * From request_vw where upper(status) like '%CAPTURED%' - 28 seconds.

You would need to have an expression index over upper(status) to support such a query, not an index on status itself.  It would probably be better to just use ILIKE rather than upper(), so `status ILIKE '%captured%'`, which can benefit from an index on "status" itself.

Also as this is VIEW TRIGRAM nor normal indexes don't get used.

There is no problem in general using trigram indexes (or any other index types) on views.  Maybe your view has particular features which inhibit the use of the index, but you haven't given any information which would be useful for assessing that.  Did you try an index, or just assume it wouldn't work without trying?
 
Cheers,

Jeff

pgsql-performance by date:

Previous
From: Rick Otten
Date:
Subject: Re: LIKE CLAUSE on VIEWS
Next
From: Mok
Date:
Subject: Database Stalls