Re: Index not used without explicit typecast
От | Tom Lane |
---|---|
Тема | Re: Index not used without explicit typecast |
Дата | |
Msg-id | 2512257.1596637942@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Index not used without explicit typecast (Jan Kort <jan.kort@genetics.nl>) |
Ответы |
Re: Index not used without explicit typecast
|
Список | pgsql-bugs |
Jan Kort <jan.kort@genetics.nl> writes: > UPDATE TABLE1 SET date1 = current_timestamp WHERE ID = 1000000; > [ uses index on integer column ID ] > UPDATE TABLE1 SET date1 = current_timestamp WHERE ID = 1000000::numeric; > [ doesn't use index ] Yeah. This is the price we pay for extensibility. The only available "=" operator that can match the second query is "numeric = numeric", so the parser effectively converts it to "ID::numeric = 1000000::numeric", and then "ID::numeric" does not match the index, any more than say "abs(ID)" would. In principle one could invent an "integer = numeric" operator and then make it a member of the appropriate btree operator class, but there are assorted pitfalls and gotchas in that. The biggest risk is that the extra operator would result in "ambiguous operator" failures for queries that work fine today. If you're desperate for a workaround that doesn't involve fixing the query, you could build an additional index on "ID::numeric". This'd be kind of expensive from an index-maintenance standpoint, of course. regards, tom lane
В списке pgsql-bugs по дате отправления: