Re: PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used - Mailing list pgsql-general

From Tom Lane
Subject Re: PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used
Date
Msg-id 1556144.1616735293@sss.pgh.pa.us
Whole thread Raw
In response to PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used  (Jagmohan Kaintura <jagmohan@tecorelabs.com>)
Responses Re: PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used
List pgsql-general
Jagmohan Kaintura <jagmohan@tecorelabs.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



pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used
Next
From: Tim Cross
Date:
Subject: Re: About CVE-2018-1058