From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tim Slechta <trslechta@gmail.com>
Cc: pgsql-performance@lists.postgresql.org
Subject: Re: Views don't seem to use indexes?
Date: Thu, 28 Oct 2021 02:15:52 -0400
Message-ID: <309712.1635401752@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJVU3y0uF-U8rZR=X1s=Sp5jYa5vKx0sWaALTwcWpPiE4Y1xpg@mail.gmail.com>
References: <CAJVU3y0uF-U8rZR=X1s=Sp5jYa5vKx0sWaALTwcWpPiE4Y1xpg@mail.gmail.com>
Tim Slechta <trslechta@gmail.com> writes:
> Why does the planner not use an index when a view is involved?
It's not about a "view" ... you'd get the same results if you wrote
out the UNION ALL construct in-line as a sub-select.
I think you may be shooting yourself in the foot by not making sure that
the UNION ALL arms match in data type. You did not show us the definition
of pworkspaceobject, but if pworkspaceobject.pobject_name isn't of type
text (maybe it's varchar?) then the type mismatch would prevent pushing
down a condition on that column. The source code says:
* For subqueries using UNION/UNION ALL/INTERSECT/INTERSECT ALL, we can
* push quals into each component query, but the quals can only reference
* subquery columns that suffer no type coercions in the set operation.
* Otherwise there are possible semantic gotchas.
I'm too tired to reconstruct an example of the semantic issues...
regards, tom lane
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, trslechta@gmail.com, pgsql-performance@lists.postgresql.org
Subject: Re: Views don't seem to use indexes?
In-Reply-To: <309712.1635401752@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