Re: View performance with implicit cast
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tomasz Szypowski <tomasz.szypowski@asseco.pl>
Cc: "Zornoza Sanchez, Jose Blas" <jbzornoza@sia.es>,
"pgsql-sql@lists.postgresql.org" <pgsql-sql@lists.postgresql.org>
Date: 2025-01-07T20:34:40Z
Lists: 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