Re: View performance with implicit cast - Mailing list pgsql-sql

From Tom Lane
Subject Re: View performance with implicit cast
Date
Msg-id 1508460.1736282080@sss.pgh.pa.us
Whole thread Raw
In response to View performance with implicit cast  (Tomasz Szypowski <tomasz.szypowski@asseco.pl>)
List pgsql-sql
Tomasz Szypowski <tomasz.szypowski@asseco.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



pgsql-sql by date:

Previous
From: Tomasz Szypowski
Date:
Subject: RE: View performance with implicit cast