Re: index not used for bigint without explicit cast

From: Noah Misch <noah(at)leadboat(dot)com>
To: "Sam(dot)Mesh" <Sam(dot)Mesh(at)gmail(dot)com>
Cc: Peter Geoghegan <pg(at)bowt(dot)ie>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: index not used for bigint without explicit cast
Date: 2023-01-19 05:30:47
Message-ID: 20230119053047.GA1295127@rfd.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Jan 18, 2023 at 01:43:43PM -0800, Sam.Mesh wrote:
> Peter, thank you for clarification.
> Could you please double check the following reasoning based on
> https://www.postgresql.org/docs/current/btree-behavior.html?
> - Index search by bigint column requires conversion of limiting
> expressions to bigint type.
> - Conversion from number(19,0) to bigint may cause overflow.
> - So, index search is not possible.

Essentially, yes. This is a query planner limitation, not a fundamental
property of the search problem. "bigintcol = '5.1'::numeric" is equivalent to
"bigintcol <> bigintcol" or "CASE WHEN bigintcol IS NULL THEN NULL ELSE false
END". In contexts that don't distinguish "false" from NULL, it's equivalent
to constant "false". Those observations apply to any search value such that
'search_value'::numeric::bigint::numeric <> 'search_value'::numeric does not
return true, including overflow-error cases. Like many datatype-specific
tricks, the planner isn't aware at this time.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2023-01-19 05:51:48 Re: index not used for bigint without explicit cast
Previous Message PG Bug reporting form 2023-01-18 22:33:15 BUG #17753: pg_dump --if-exists bug