public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Tomasz Szypowski <[email protected]>
Cc: Zornoza Sanchez, Jose Blas <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: View performance with implicit cast
Date: Tue, 07 Jan 2025 15:34:40 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <DU0PR04MB941950CC9F69A0F3B0FE877B99112@DU0PR04MB9419.eurprd04.prod.outlook.com>
References: <DU0PR04MB94192D3922E05C8E0A18F5F399142@DU0PR04MB9419.eurprd04.prod.outlook.com>
	<[email protected]>
	<DU0PR04MB941961BC101B5B4AFB0C1C1699172@DU0PR04MB9419.eurprd04.prod.outlook.com>
	<PR3P193MB073140BB6374E47E7E6EB87CCC112@PR3P193MB0731.EURP193.PROD.OUTLOOK.COM>
	<[email protected]>
	<DU0PR04MB941950CC9F69A0F3B0FE877B99112@DU0PR04MB9419.eurprd04.prod.outlook.com>

Tomasz Szypowski <[email protected]> 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






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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: View performance with implicit cast
  In-Reply-To: <[email protected]>

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

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox