Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit782be0f

Browse files
committed
Dissociate btequalimage() from interval_ops, ending its deduplication.
Under interval_ops, some equal values are distinguishable. One suchpair is '24:00:00' and '1 day'. With that being so, btequalimage()breaches the documented contract for the "equalimage" btree supportfunction. 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 suchindexes. This fix makes interval_ops simply omit the support function,like numeric_ops does. Back-pack to v13, where btequalimage() firstappeared. In back branches, for the benefit of old catalog content,btequalimage() code will return false for type "interval". Goingforward, back-branch initdb will include the catalog change.Reviewed by Peter Geoghegan.Discussion:https://postgr.es/m/20231011013317.22.nmisch@google.com
1 parent1102f4e commit782be0f

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
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"
@@ -337,10 +338,20 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed,
337338
errmsg("index \"%s\" metapage has equalimage field set on unsupported nbtree version",
338339
RelationGetRelationName(indrel))));
339340
if (allequalimage&& !_bt_allequalimage(indrel, false))
341+
{
342+
boolhas_interval_ops= false;
343+
344+
for (inti=0;i<IndexRelationGetNumberOfKeyAttributes(indrel);i++)
345+
if (indrel->rd_opfamily[i]==INTERVAL_BTREE_FAM_OID)
346+
has_interval_ops= true;
340347
ereport(ERROR,
341348
(errcode(ERRCODE_INDEX_CORRUPTED),
342349
errmsg("index \"%s\" metapage incorrectly indicates that deduplication is safe",
343-
RelationGetRelationName(indrel))));
350+
RelationGetRelationName(indrel)),
351+
has_interval_ops
352+
?errhint("This is known of \"interval\" indexes last built on a version predating 2023-11.")
353+
:0));
354+
}
344355

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

‎src/backend/utils/adt/datum.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include"postgres.h"
4444

4545
#include"access/detoast.h"
46+
#include"catalog/pg_type_d.h"
4647
#include"common/hashfn.h"
4748
#include"fmgr.h"
4849
#include"utils/builtins.h"
@@ -385,20 +386,17 @@ datum_image_hash(Datum value, bool typByVal, int typLen)
385386
* datum_image_eq() in all cases can use this as their "equalimage" support
386387
* function.
387388
*
388-
* Currently, we unconditionally assume that any B-Tree operator class that
389-
* registers btequalimage as its support function 4 must be able to safely use
390-
* optimizations like deduplication (i.e. we return true unconditionally). If
391-
* it ever proved necessary to rescind support for an operator class, we could
392-
* do that in a targeted fashion by doing something with the opcintype
393-
* argument.
389+
* Earlier minor releases erroneously associated this function with
390+
* interval_ops. Detect that case to rescind deduplication support, without
391+
* requiring initdb.
394392
*-------------------------------------------------------------------------
395393
*/
396394
Datum
397395
btequalimage(PG_FUNCTION_ARGS)
398396
{
399-
/*Oidopcintype = PG_GETARG_OID(0); */
397+
Oidopcintype=PG_GETARG_OID(0);
400398

401-
PG_RETURN_BOOL(true);
399+
PG_RETURN_BOOL(opcintype!=INTERVALOID);
402400
}
403401

404402
/*-------------------------------------------------------------------------

‎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
@@ -2175,6 +2175,7 @@ ORDER BY 1, 2, 3;
21752175
| array_ops | array_ops | anyarray
21762176
| float_ops | float4_ops | real
21772177
| float_ops | float8_ops | double precision
2178+
| interval_ops | interval_ops | interval
21782179
| jsonb_ops | jsonb_ops | jsonb
21792180
| multirange_ops | multirange_ops | anymultirange
21802181
| numeric_ops | numeric_ops | numeric
@@ -2183,7 +2184,7 @@ ORDER BY 1, 2, 3;
21832184
| record_ops | record_ops | record
21842185
| tsquery_ops | tsquery_ops | tsquery
21852186
| tsvector_ops | tsvector_ops | tsvector
2186-
(15 rows)
2187+
(16 rows)
21872188

21882189
-- **************** pg_index ****************
21892190
-- Look for illegal values in pg_index fields.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp