pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jagmohan Kaintura <jagmohan@tecorelabs.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used
Date: Fri, 26 Mar 2021 01:08:13 -0400
Message-ID: <1556144.1616735293@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+cYFtt5bBOGJVhYbZ0zLLwc=jVUVi_v+aUw0GTqVAceD1MawA@mail.gmail.com>
References: <CA+cYFtt5bBOGJVhYbZ0zLLwc=jVUVi_v+aUw0GTqVAceD1MawA@mail.gmail.com>

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





view thread (5+ messages)  latest in thread

Message-ID: <1556144.1616735293@sss.pgh.pa.us>
Permalink:  ../1556144.1616735293@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1556144.1616735293@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jagmohan@tecorelabs.com
  Subject: Re: PostgreSQL Views Where Clause Character Columns getting Typecasted to Text and Indexes not getting Used
  In-Reply-To: <1556144.1616735293@sss.pgh.pa.us>
  References: <CA+cYFtt5bBOGJVhYbZ0zLLwc=jVUVi_v+aUw0GTqVAceD1MawA@mail.gmail.com> <1556144.1616735293@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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