Re: PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jagmohan Kaintura <jagmohan(at)tecorelabs(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used
Date: 2021-03-26 05:08:13
Message-ID: 1556144.1616735293@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jagmohan Kaintura <jagmohan(at)tecorelabs(dot)com> writes:
> When we are compiling View definition into database , the where clause on
> the Character Columns is getting internally typecasted to text.

That's normal. In Postgres, varchar has no operators of its own;
everything you might do with it involves a (no-cost) cast to text.
You might think of varchar as being a domain over text, though for
historical reasons it's not implemented exactly that way.

> These Columns are Primary Key columns and because of this Type Casting on
> those columns Index scan is not happening and we are always getting
> Sequential Scan.

This, on the other hand, is just nonsense. You haven't presented
any examples in which an indexscan looks likely to be a win.
Postgres generally won't bother with an index when scanning a tiny
table. Nor is an index necessarily helpful when doing a join,
unless the join is designed to access just a small part of the table.

> Please help us in identifying the solution.

Please read
https://wiki.postgresql.org/wiki/Slow_Query_Questions

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tim Cross 2021-03-26 06:41:32 Re: About CVE-2018-1058
Previous Message Rob Sargent 2021-03-26 04:55:21 Re: PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used