Re: View performance with implicit cast

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tomasz Szypowski <tomasz(dot)szypowski(at)asseco(dot)pl>
Cc: "Zornoza Sanchez, Jose Blas" <jbzornoza(at)sia(dot)es>, "pgsql-sql(at)lists(dot)postgresql(dot)org" <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: View performance with implicit cast
Date: 2025-01-07 20:34:40
Message-ID: 1508460.1736282080@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tomasz Szypowski <tomasz(dot)szypowski(at)asseco(dot)pl> writes:
> Thanks for the explanation, but what about the reported problem.
> How can I force the view to use both indexes?

You can't, because the indexes are not on the same expressions
appearing in the view. Your outer WHERE clause constrains those
expressions, not the underlying table columns.

If it's impractical to make the underlying tables share the same
column type, you would need to do something like

create view v_test as
select date_1 from test1
union all
select date_2::timestamp from test2;

create index on test2 ((date_2::timestamp));

Consider the extra index as your penance for not having thought
harder about data type choices to begin with.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tchouante, Merlin 2025-02-12 21:05:51 Database Query to find content location
Previous Message Tomasz Szypowski 2025-01-07 20:07:16 RE: View performance with implicit cast