Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 28233ff

Browse files
committed
Add another regression test cross-checking operator and function comments.
Add a query that lists all the functions that are operator implementation functions and have a SQL comment that doesn't just say "implementation of XYZ operator". (Note that the preceding test checks that such functions' comments exactly match the corresponding operators' comments.) While it's not forbidden to add more functions to this list, that should only be done when we're encouraging users to use either the function or operator syntax for the functionality, which is a fairly rare situation.
1 parent 11829ff commit 28233ff

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

src/test/regress/expected/opr_sanity.out

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,11 @@ WHERE d.classoid IS NULL AND p1.oid <= 9999;
679679
(0 rows)
680680

681681
-- Check that operators' underlying functions have suitable comments,
682-
-- namely 'implementation of XXX operator'. In some cases involving legacy
683-
-- names for operators, there are multiple operators referencing the same
684-
-- pg_proc entry, so ignore operators whose comments say they are deprecated.
682+
-- namely 'implementation of XXX operator'. (Note: it's not necessary to
683+
-- put such comments into pg_proc.h; initdb will generate them as needed.)
684+
-- In some cases involving legacy names for operators, there are multiple
685+
-- operators referencing the same pg_proc entry, so ignore operators whose
686+
-- comments say they are deprecated.
685687
-- We also have a few functions that are both operator support and meant to
686688
-- be called directly; those should have comments matching their operator.
687689
WITH funcdescs AS (
@@ -700,6 +702,31 @@ SELECT * FROM funcdescs
700702
-------+---------+-------+---------+--------------+---------
701703
(0 rows)
702704

705+
-- Show all the operator-implementation functions that have their own
706+
-- comments. This should happen only in cases where the function and
707+
-- operator syntaxes are both documented at the user level.
708+
-- This should be a pretty short list; it's mostly legacy cases.
709+
WITH funcdescs AS (
710+
SELECT p.oid as p_oid, proname, o.oid as o_oid,
711+
obj_description(p.oid, 'pg_proc') as prodesc,
712+
'implementation of ' || oprname || ' operator' as expecteddesc,
713+
obj_description(o.oid, 'pg_operator') as oprdesc
714+
FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid
715+
WHERE o.oid <= 9999
716+
)
717+
SELECT p_oid, proname, prodesc FROM funcdescs
718+
WHERE prodesc IS DISTINCT FROM expecteddesc
719+
AND oprdesc NOT LIKE 'deprecated%'
720+
ORDER BY 1;
721+
p_oid | proname | prodesc
722+
-------+---------------+-------------------------------------
723+
378 | array_append | append element onto end of array
724+
379 | array_prepend | prepend element onto front of array
725+
1035 | aclinsert | add/update ACL item
726+
1036 | aclremove | remove ACL item
727+
1037 | aclcontains | contains
728+
(5 rows)
729+
703730
-- **************** pg_aggregate ****************
704731
-- Look for illegal values in pg_aggregate fields.
705732
SELECT ctid, aggfnoid::oid

src/test/regress/sql/opr_sanity.sql

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,11 @@ FROM pg_operator as p1 LEFT JOIN pg_description as d
544544
WHERE d.classoid IS NULL AND p1.oid <= 9999;
545545

546546
-- Check that operators' underlying functions have suitable comments,
547-
-- namely 'implementation of XXX operator'. In some cases involving legacy
548-
-- names for operators, there are multiple operators referencing the same
549-
-- pg_proc entry, so ignore operators whose comments say they are deprecated.
547+
-- namely 'implementation of XXX operator'. (Note: it's not necessary to
548+
-- put such comments into pg_proc.h; initdb will generate them as needed.)
549+
-- In some cases involving legacy names for operators, there are multiple
550+
-- operators referencing the same pg_proc entry, so ignore operators whose
551+
-- comments say they are deprecated.
550552
-- We also have a few functions that are both operator support and meant to
551553
-- be called directly; those should have comments matching their operator.
552554
WITH funcdescs AS (
@@ -562,6 +564,23 @@ SELECT * FROM funcdescs
562564
AND oprdesc NOT LIKE 'deprecated%'
563565
AND prodesc IS DISTINCT FROM oprdesc;
564566

567+
-- Show all the operator-implementation functions that have their own
568+
-- comments. This should happen only in cases where the function and
569+
-- operator syntaxes are both documented at the user level.
570+
-- This should be a pretty short list; it's mostly legacy cases.
571+
WITH funcdescs AS (
572+
SELECT p.oid as p_oid, proname, o.oid as o_oid,
573+
obj_description(p.oid, 'pg_proc') as prodesc,
574+
'implementation of ' || oprname || ' operator' as expecteddesc,
575+
obj_description(o.oid, 'pg_operator') as oprdesc
576+
FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid
577+
WHERE o.oid <= 9999
578+
)
579+
SELECT p_oid, proname, prodesc FROM funcdescs
580+
WHERE prodesc IS DISTINCT FROM expecteddesc
581+
AND oprdesc NOT LIKE 'deprecated%'
582+
ORDER BY 1;
583+
565584

566585
-- **************** pg_aggregate ****************
567586

0 commit comments

Comments
 (0)