Skip to content

Commit 5f27b5f

Browse files
committed
Dissociate btequalimage() from interval_ops, ending its deduplication.
Under interval_ops, some equal values are distinguishable. One such pair is '24:00:00' and '1 day'. With that being so, btequalimage() breaches the documented contract for the "equalimage" btree support function. This can cause incorrect results from index-only scans. Users should REINDEX any btree indexes having interval-type columns. After updating, pg_amcheck will report an error for almost all such indexes. This fix makes interval_ops simply omit the support function, like numeric_ops does. Back-pack to v13, where btequalimage() first appeared. In back branches, for the benefit of old catalog content, btequalimage() code will return false for type "interval". Going forward, back-branch initdb will include the catalog change. Reviewed by Peter Geoghegan. Discussion: https://postgr.es/m/20231011013317.22.nmisch@google.com
1 parent 90ebcc3 commit 5f27b5f

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

contrib/amcheck/verify_nbtree.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "access/xact.h"
3232
#include "catalog/index.h"
3333
#include "catalog/pg_am.h"
34+
#include "catalog/pg_opfamily_d.h"
3435
#include "commands/tablecmds.h"
3536
#include "common/pg_prng.h"
3637
#include "lib/bloomfilter.h"
@@ -338,10 +339,20 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed,
338339
errmsg("index \"%s\" metapage has equalimage field set on unsupported nbtree version",
339340
RelationGetRelationName(indrel))));
340341
if (allequalimage && !_bt_allequalimage(indrel, false))
342+
{
343+
bool has_interval_ops = false;
344+
345+
for (int i = 0; i < IndexRelationGetNumberOfKeyAttributes(indrel); i++)
346+
if (indrel->rd_opfamily[i] == INTERVAL_BTREE_FAM_OID)
347+
has_interval_ops = true;
341348
ereport(ERROR,
342349
(errcode(ERRCODE_INDEX_CORRUPTED),
343350
errmsg("index \"%s\" metapage incorrectly indicates that deduplication is safe",
344-
RelationGetRelationName(indrel))));
351+
RelationGetRelationName(indrel)),
352+
has_interval_ops
353+
? errhint("This is known of \"interval\" indexes last built on a version predating 2023-11.")
354+
: 0));
355+
}
345356

346357
/* Check index, possibly against table it is an index on */
347358
bt_check_every_level(indrel, heaprel, heapkeyspace, parentcheck,

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202310131
60+
#define CATALOG_VERSION_NO 202310141
6161

6262
#endif

src/include/catalog/pg_amproc.dat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@
172172
{ amprocfamily => 'btree/interval_ops', amproclefttype => 'interval',
173173
amprocrighttype => 'interval', amprocnum => '3',
174174
amproc => 'in_range(interval,interval,interval,bool,bool)' },
175-
{ amprocfamily => 'btree/interval_ops', amproclefttype => 'interval',
176-
amprocrighttype => 'interval', amprocnum => '4', amproc => 'btequalimage' },
177175
{ amprocfamily => 'btree/macaddr_ops', amproclefttype => 'macaddr',
178176
amprocrighttype => 'macaddr', amprocnum => '1', amproc => 'macaddr_cmp' },
179177
{ amprocfamily => 'btree/macaddr_ops', amproclefttype => 'macaddr',

src/include/catalog/pg_opfamily.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
opfmethod => 'btree', opfname => 'integer_ops' },
5151
{ oid => '1977',
5252
opfmethod => 'hash', opfname => 'integer_ops' },
53-
{ oid => '1982',
53+
{ oid => '1982', oid_symbol => 'INTERVAL_BTREE_FAM_OID',
5454
opfmethod => 'btree', opfname => 'interval_ops' },
5555
{ oid => '1983',
5656
opfmethod => 'hash', opfname => 'interval_ops' },

src/test/regress/expected/opr_sanity.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,7 @@ ORDER BY 1, 2, 3;
22082208
| array_ops | array_ops | anyarray
22092209
| float_ops | float4_ops | real
22102210
| float_ops | float8_ops | double precision
2211+
| interval_ops | interval_ops | interval
22112212
| jsonb_ops | jsonb_ops | jsonb
22122213
| multirange_ops | multirange_ops | anymultirange
22132214
| numeric_ops | numeric_ops | numeric
@@ -2216,7 +2217,7 @@ ORDER BY 1, 2, 3;
22162217
| record_ops | record_ops | record
22172218
| tsquery_ops | tsquery_ops | tsquery
22182219
| tsvector_ops | tsvector_ops | tsvector
2219-
(15 rows)
2220+
(16 rows)
22202221

22212222
-- **************** pg_index ****************
22222223
-- Look for illegal values in pg_index fields.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy