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

Commite9f42d5

Browse files
committed
Clean up/tighten up coercibility checks in opr_sanity regression test.
With the removal of the old abstime type, there are no longer any casesin this test where we need to use the weaker castcontext-ignoring formof binary coercibility check. (The other major source of such headaches,apparently-incompatible hash functions, is now hashvalidate()'s problemnot this test script's problem.) Hence, just use binary_coercible()everywhere, and remove the comments explaining why we don't do so ---which were broken anyway bycda6a8d.I left physically_coercible() in place but renamed it to bettermatch what it's actually testing, and added some comments.Also, in test queries that have an assumption about the maximum numberof function arguments they need to handle, add a clause to make them failif someday there's a relevant function with more arguments. Otherwisewe're likely not to notice that we need to extend the queries.Discussion:https://postgr.es/m/27637.1539388060@sss.pgh.pa.us
1 parent1df21dd commite9f42d5

File tree

2 files changed

+62
-48
lines changed

2 files changed

+62
-48
lines changed

‎src/test/regress/expected/opr_sanity.out

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
-- Helper functions to deal with cases where binary-coercible matches are
2020
-- allowed.
2121
-- This should match IsBinaryCoercible() in parse_coerce.c.
22+
-- It doesn't currently know about some cases, notably domains, anyelement,
23+
-- anynonarray, anyenum, or record, but it doesn't need to (yet).
2224
create function binary_coercible(oid, oid) returns bool as $$
2325
begin
2426
if $1 = $2 then return true; end if;
@@ -39,9 +41,11 @@ begin
3941
return false;
4042
end
4143
$$ language plpgsql strict stable;
42-
-- This one ignores castcontext, so it considers only physical equivalence
43-
-- and not whether the coercion can be invoked implicitly.
44-
create function physically_coercible(oid, oid) returns bool as $$
44+
-- This one ignores castcontext, so it will allow cases where an explicit
45+
-- (but still binary) cast would be required to convert the input type.
46+
-- We don't currently use this for any tests in this file, but it is a
47+
-- reasonable alternative definition for some scenarios.
48+
create function explicitly_binary_coercible(oid, oid) returns bool as $$
4549
begin
4650
if $1 = $2 then return true; end if;
4751
if EXISTS(select 1 from pg_catalog.pg_cast where
@@ -1221,7 +1225,7 @@ WHERE d.classoid IS NULL AND p1.oid <= 9999;
12211225

12221226
-- Check that operators' underlying functions have suitable comments,
12231227
-- namely 'implementation of XXX operator'. (Note: it's not necessary to
1224-
-- put such comments into pg_proc.h; initdb will generate them as needed.)
1228+
-- put such comments into pg_proc.dat; initdb will generate them as needed.)
12251229
-- In some cases involving legacy names for operators, there are multiple
12261230
-- operators referencing the same pg_proc entry, so ignore operators whose
12271231
-- comments say they are deprecated.
@@ -1323,7 +1327,6 @@ WHERE a.aggfnoid = p.oid AND
13231327
(0 rows)
13241328

13251329
-- Cross-check transfn against its entry in pg_proc.
1326-
-- NOTE: use physically_coercible here, not binary_coercible, because
13271330
SELECT a.aggfnoid::oid, p.proname, ptr.oid, ptr.proname
13281331
FROM pg_aggregate AS a, pg_proc AS p, pg_proc AS ptr
13291332
WHERE a.aggfnoid = p.oid AND
@@ -1332,15 +1335,16 @@ WHERE a.aggfnoid = p.oid AND
13321335
OR NOT (ptr.pronargs =
13331336
CASE WHEN a.aggkind = 'n' THEN p.pronargs + 1
13341337
ELSE greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 END)
1335-
OR NOTphysically_coercible(ptr.prorettype, a.aggtranstype)
1336-
OR NOTphysically_coercible(a.aggtranstype, ptr.proargtypes[0])
1338+
OR NOTbinary_coercible(ptr.prorettype, a.aggtranstype)
1339+
OR NOTbinary_coercible(a.aggtranstype, ptr.proargtypes[0])
13371340
OR (p.pronargs > 0 AND
1338-
NOTphysically_coercible(p.proargtypes[0], ptr.proargtypes[1]))
1341+
NOTbinary_coercible(p.proargtypes[0], ptr.proargtypes[1]))
13391342
OR (p.pronargs > 1 AND
1340-
NOTphysically_coercible(p.proargtypes[1], ptr.proargtypes[2]))
1343+
NOTbinary_coercible(p.proargtypes[1], ptr.proargtypes[2]))
13411344
OR (p.pronargs > 2 AND
1342-
NOTphysically_coercible(p.proargtypes[2], ptr.proargtypes[3]))
1345+
NOTbinary_coercible(p.proargtypes[2], ptr.proargtypes[3]))
13431346
-- we could carry the check further, but 3 args is enough for now
1347+
OR (p.pronargs > 3)
13441348
);
13451349
aggfnoid | proname | oid | proname
13461350
----------+---------+-----+---------
@@ -1362,7 +1366,8 @@ WHERE a.aggfnoid = p.oid AND
13621366
NOT binary_coercible(p.proargtypes[1], pfn.proargtypes[2]))
13631367
OR (pfn.pronargs > 3 AND
13641368
NOT binary_coercible(p.proargtypes[2], pfn.proargtypes[3]))
1365-
-- we could carry the check further, but 3 args is enough for now
1369+
-- we could carry the check further, but 4 args is enough for now
1370+
OR (pfn.pronargs > 4)
13661371
);
13671372
aggfnoid | proname | oid | proname
13681373
----------+---------+-----+---------
@@ -1418,15 +1423,16 @@ WHERE a.aggfnoid = p.oid AND
14181423
OR NOT (ptr.pronargs =
14191424
CASE WHEN a.aggkind = 'n' THEN p.pronargs + 1
14201425
ELSE greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 END)
1421-
OR NOTphysically_coercible(ptr.prorettype, a.aggmtranstype)
1422-
OR NOTphysically_coercible(a.aggmtranstype, ptr.proargtypes[0])
1426+
OR NOTbinary_coercible(ptr.prorettype, a.aggmtranstype)
1427+
OR NOTbinary_coercible(a.aggmtranstype, ptr.proargtypes[0])
14231428
OR (p.pronargs > 0 AND
1424-
NOTphysically_coercible(p.proargtypes[0], ptr.proargtypes[1]))
1429+
NOTbinary_coercible(p.proargtypes[0], ptr.proargtypes[1]))
14251430
OR (p.pronargs > 1 AND
1426-
NOTphysically_coercible(p.proargtypes[1], ptr.proargtypes[2]))
1431+
NOTbinary_coercible(p.proargtypes[1], ptr.proargtypes[2]))
14271432
OR (p.pronargs > 2 AND
1428-
NOTphysically_coercible(p.proargtypes[2], ptr.proargtypes[3]))
1433+
NOTbinary_coercible(p.proargtypes[2], ptr.proargtypes[3]))
14291434
-- we could carry the check further, but 3 args is enough for now
1435+
OR (p.pronargs > 3)
14301436
);
14311437
aggfnoid | proname | oid | proname
14321438
----------+---------+-----+---------
@@ -1441,15 +1447,16 @@ WHERE a.aggfnoid = p.oid AND
14411447
OR NOT (ptr.pronargs =
14421448
CASE WHEN a.aggkind = 'n' THEN p.pronargs + 1
14431449
ELSE greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 END)
1444-
OR NOTphysically_coercible(ptr.prorettype, a.aggmtranstype)
1445-
OR NOTphysically_coercible(a.aggmtranstype, ptr.proargtypes[0])
1450+
OR NOTbinary_coercible(ptr.prorettype, a.aggmtranstype)
1451+
OR NOTbinary_coercible(a.aggmtranstype, ptr.proargtypes[0])
14461452
OR (p.pronargs > 0 AND
1447-
NOTphysically_coercible(p.proargtypes[0], ptr.proargtypes[1]))
1453+
NOTbinary_coercible(p.proargtypes[0], ptr.proargtypes[1]))
14481454
OR (p.pronargs > 1 AND
1449-
NOTphysically_coercible(p.proargtypes[1], ptr.proargtypes[2]))
1455+
NOTbinary_coercible(p.proargtypes[1], ptr.proargtypes[2]))
14501456
OR (p.pronargs > 2 AND
1451-
NOTphysically_coercible(p.proargtypes[2], ptr.proargtypes[3]))
1457+
NOTbinary_coercible(p.proargtypes[2], ptr.proargtypes[3]))
14521458
-- we could carry the check further, but 3 args is enough for now
1459+
OR (p.pronargs > 3)
14531460
);
14541461
aggfnoid | proname | oid | proname
14551462
----------+---------+-----+---------
@@ -1471,7 +1478,8 @@ WHERE a.aggfnoid = p.oid AND
14711478
NOT binary_coercible(p.proargtypes[1], pfn.proargtypes[2]))
14721479
OR (pfn.pronargs > 3 AND
14731480
NOT binary_coercible(p.proargtypes[2], pfn.proargtypes[3]))
1474-
-- we could carry the check further, but 3 args is enough for now
1481+
-- we could carry the check further, but 4 args is enough for now
1482+
OR (pfn.pronargs > 4)
14751483
);
14761484
aggfnoid | proname | oid | proname
14771485
----------+---------+-----+---------
@@ -1503,14 +1511,13 @@ WHERE a.aggfnoid = p.oid AND
15031511

15041512
-- Check that all combine functions have signature
15051513
-- combine(transtype, transtype) returns transtype
1506-
-- NOTE: use physically_coercible here, not binary_coercible, because
15071514
SELECT a.aggfnoid, p.proname
15081515
FROM pg_aggregate as a, pg_proc as p
15091516
WHERE a.aggcombinefn = p.oid AND
15101517
(p.pronargs != 2 OR
15111518
p.prorettype != p.proargtypes[0] OR
15121519
p.prorettype != p.proargtypes[1] OR
1513-
NOTphysically_coercible(a.aggtranstype, p.proargtypes[0]));
1520+
NOTbinary_coercible(a.aggtranstype, p.proargtypes[0]));
15141521
aggfnoid | proname
15151522
----------+---------
15161523
(0 rows)

‎src/test/regress/sql/opr_sanity.sql

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
-- allowed.
2323

2424
-- This should match IsBinaryCoercible() in parse_coerce.c.
25+
-- It doesn't currently know about some cases, notably domains, anyelement,
26+
-- anynonarray, anyenum, or record, but it doesn't need to (yet).
2527
createfunctionbinary_coercible(oid,oid) returns boolas $$
2628
begin
2729
if $1= $2 then return true; end if;
@@ -43,9 +45,11 @@ begin
4345
end
4446
$$ language plpgsql strict stable;
4547

46-
-- This one ignores castcontext, so it considers only physical equivalence
47-
-- and not whether the coercion can be invoked implicitly.
48-
createfunctionphysically_coercible(oid,oid) returns boolas $$
48+
-- This one ignores castcontext, so it will allow cases where an explicit
49+
-- (but still binary) cast would be required to convert the input type.
50+
-- We don't currently use this for any tests in this file, but it is a
51+
-- reasonable alternative definition for some scenarios.
52+
createfunctionexplicitly_binary_coercible(oid,oid) returns boolas $$
4953
begin
5054
if $1= $2 then return true; end if;
5155
if EXISTS(select1frompg_catalog.pg_castwhere
@@ -741,7 +745,7 @@ WHERE d.classoid IS NULL AND p1.oid <= 9999;
741745

742746
-- Check that operators' underlying functions have suitable comments,
743747
-- namely 'implementation of XXX operator'. (Note: it's not necessary to
744-
-- put such comments into pg_proc.h; initdb will generate them as needed.)
748+
-- put such comments into pg_proc.dat; initdb will generate them as needed.)
745749
-- In some cases involving legacy names for operators, there are multiple
746750
-- operators referencing the same pg_proc entry, so ignore operators whose
747751
-- comments say they are deprecated.
@@ -822,7 +826,6 @@ WHERE a.aggfnoid = p.oid AND
822826
a.aggfinalfn=0ANDp.prorettype!=a.aggtranstype;
823827

824828
-- Cross-check transfn against its entry in pg_proc.
825-
-- NOTE: use physically_coercible here, not binary_coercible, because
826829
SELECTa.aggfnoid::oid,p.proname,ptr.oid,ptr.proname
827830
FROM pg_aggregateAS a, pg_procAS p, pg_procAS ptr
828831
WHEREa.aggfnoid=p.oidAND
@@ -831,15 +834,16 @@ WHERE a.aggfnoid = p.oid AND
831834
OR NOT (ptr.pronargs=
832835
CASE WHENa.aggkind='n' THENp.pronargs+1
833836
ELSE greatest(p.pronargs-a.aggnumdirectargs,1)+1 END)
834-
OR NOTphysically_coercible(ptr.prorettype,a.aggtranstype)
835-
OR NOTphysically_coercible(a.aggtranstype,ptr.proargtypes[0])
837+
OR NOTbinary_coercible(ptr.prorettype,a.aggtranstype)
838+
OR NOTbinary_coercible(a.aggtranstype,ptr.proargtypes[0])
836839
OR (p.pronargs>0AND
837-
NOTphysically_coercible(p.proargtypes[0],ptr.proargtypes[1]))
840+
NOTbinary_coercible(p.proargtypes[0],ptr.proargtypes[1]))
838841
OR (p.pronargs>1AND
839-
NOTphysically_coercible(p.proargtypes[1],ptr.proargtypes[2]))
842+
NOTbinary_coercible(p.proargtypes[1],ptr.proargtypes[2]))
840843
OR (p.pronargs>2AND
841-
NOTphysically_coercible(p.proargtypes[2],ptr.proargtypes[3]))
844+
NOTbinary_coercible(p.proargtypes[2],ptr.proargtypes[3]))
842845
-- we could carry the check further, but 3 args is enough for now
846+
OR (p.pronargs>3)
843847
);
844848

845849
-- Cross-check finalfn (if present) against its entry in pg_proc.
@@ -859,7 +863,8 @@ WHERE a.aggfnoid = p.oid AND
859863
NOT binary_coercible(p.proargtypes[1],pfn.proargtypes[2]))
860864
OR (pfn.pronargs>3AND
861865
NOT binary_coercible(p.proargtypes[2],pfn.proargtypes[3]))
862-
-- we could carry the check further, but 3 args is enough for now
866+
-- we could carry the check further, but 4 args is enough for now
867+
OR (pfn.pronargs>4)
863868
);
864869

865870
-- If transfn is strict then either initval should be non-NULL, or
@@ -903,15 +908,16 @@ WHERE a.aggfnoid = p.oid AND
903908
OR NOT (ptr.pronargs=
904909
CASE WHENa.aggkind='n' THENp.pronargs+1
905910
ELSE greatest(p.pronargs-a.aggnumdirectargs,1)+1 END)
906-
OR NOTphysically_coercible(ptr.prorettype,a.aggmtranstype)
907-
OR NOTphysically_coercible(a.aggmtranstype,ptr.proargtypes[0])
911+
OR NOTbinary_coercible(ptr.prorettype,a.aggmtranstype)
912+
OR NOTbinary_coercible(a.aggmtranstype,ptr.proargtypes[0])
908913
OR (p.pronargs>0AND
909-
NOTphysically_coercible(p.proargtypes[0],ptr.proargtypes[1]))
914+
NOTbinary_coercible(p.proargtypes[0],ptr.proargtypes[1]))
910915
OR (p.pronargs>1AND
911-
NOTphysically_coercible(p.proargtypes[1],ptr.proargtypes[2]))
916+
NOTbinary_coercible(p.proargtypes[1],ptr.proargtypes[2]))
912917
OR (p.pronargs>2AND
913-
NOTphysically_coercible(p.proargtypes[2],ptr.proargtypes[3]))
918+
NOTbinary_coercible(p.proargtypes[2],ptr.proargtypes[3]))
914919
-- we could carry the check further, but 3 args is enough for now
920+
OR (p.pronargs>3)
915921
);
916922

917923
-- Cross-check minvtransfn (if present) against its entry in pg_proc.
@@ -923,15 +929,16 @@ WHERE a.aggfnoid = p.oid AND
923929
OR NOT (ptr.pronargs=
924930
CASE WHENa.aggkind='n' THENp.pronargs+1
925931
ELSE greatest(p.pronargs-a.aggnumdirectargs,1)+1 END)
926-
OR NOTphysically_coercible(ptr.prorettype,a.aggmtranstype)
927-
OR NOTphysically_coercible(a.aggmtranstype,ptr.proargtypes[0])
932+
OR NOTbinary_coercible(ptr.prorettype,a.aggmtranstype)
933+
OR NOTbinary_coercible(a.aggmtranstype,ptr.proargtypes[0])
928934
OR (p.pronargs>0AND
929-
NOTphysically_coercible(p.proargtypes[0],ptr.proargtypes[1]))
935+
NOTbinary_coercible(p.proargtypes[0],ptr.proargtypes[1]))
930936
OR (p.pronargs>1AND
931-
NOTphysically_coercible(p.proargtypes[1],ptr.proargtypes[2]))
937+
NOTbinary_coercible(p.proargtypes[1],ptr.proargtypes[2]))
932938
OR (p.pronargs>2AND
933-
NOTphysically_coercible(p.proargtypes[2],ptr.proargtypes[3]))
939+
NOTbinary_coercible(p.proargtypes[2],ptr.proargtypes[3]))
934940
-- we could carry the check further, but 3 args is enough for now
941+
OR (p.pronargs>3)
935942
);
936943

937944
-- Cross-check mfinalfn (if present) against its entry in pg_proc.
@@ -951,7 +958,8 @@ WHERE a.aggfnoid = p.oid AND
951958
NOT binary_coercible(p.proargtypes[1],pfn.proargtypes[2]))
952959
OR (pfn.pronargs>3AND
953960
NOT binary_coercible(p.proargtypes[2],pfn.proargtypes[3]))
954-
-- we could carry the check further, but 3 args is enough for now
961+
-- we could carry the check further, but 4 args is enough for now
962+
OR (pfn.pronargs>4)
955963
);
956964

957965
-- If mtransfn is strict then either minitval should be non-NULL, or
@@ -976,15 +984,14 @@ WHERE a.aggfnoid = p.oid AND
976984

977985
-- Check that all combine functions have signature
978986
-- combine(transtype, transtype) returns transtype
979-
-- NOTE: use physically_coercible here, not binary_coercible, because
980987

981988
SELECTa.aggfnoid,p.proname
982989
FROM pg_aggregateas a, pg_procas p
983990
WHEREa.aggcombinefn=p.oidAND
984991
(p.pronargs!=2OR
985992
p.prorettype!=p.proargtypes[0]OR
986993
p.prorettype!=p.proargtypes[1]OR
987-
NOTphysically_coercible(a.aggtranstype,p.proargtypes[0]));
994+
NOTbinary_coercible(a.aggtranstype,p.proargtypes[0]));
988995

989996
-- Check that no combine function for an INTERNAL transtype is strict.
990997

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp