Re: LIKE CLAUSE on VIEWS

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: aditya desai <admad123(at)gmail(dot)com>
Cc: Pgsql Performance <pgsql-performance(at)lists(dot)postgresql(dot)org>
Subject: Re: LIKE CLAUSE on VIEWS
Date: 2023-01-22 17:49:51
Message-ID: CAMkU=1waKK_oe1omYO9xHOed0M-B3oQMcG4n9znEp0HOxy8aqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Sun, Jan 22, 2023 at 6:34 AM aditya desai <admad123(at)gmail(dot)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

>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Mok 2023-01-30 17:47:49 Database Stalls
Previous Message Rick Otten 2023-01-22 15:55:13 Re: LIKE CLAUSE on VIEWS