📄 opr_sanity.out
字号:
SELECT a.aggfnoid::oid, o.oidFROM pg_operator AS o, pg_aggregate AS a, pg_proc AS pWHERE a.aggfnoid = p.oid AND a.aggsortop = o.oid AND (oprkind != 'b' OR oprresult != 'boolean'::regtype OR oprleft != p.proargtypes[0] OR oprright != p.proargtypes[0]); aggfnoid | oid ----------+-----(0 rows)-- Check operator is a suitable btree opclass memberSELECT a.aggfnoid::oid, o.oidFROM pg_operator AS o, pg_aggregate AS a, pg_proc AS pWHERE a.aggfnoid = p.oid AND a.aggsortop = o.oid AND NOT EXISTS(SELECT 1 FROM pg_amop ao, pg_opclass oc WHERE amopclaid = oc.oid AND amopsubtype = 0 AND amopopr = o.oid AND opcamid = 403 AND opcintype = o.oprleft AND opcdefault); aggfnoid | oid ----------+-----(0 rows)-- Check correspondence of btree strategies and namesSELECT DISTINCT proname, oprname, amopstrategyFROM pg_operator AS o, pg_aggregate AS a, pg_proc AS p, pg_amop as ao, pg_opclass ocWHERE a.aggfnoid = p.oid AND a.aggsortop = o.oid AND amopclaid = oc.oid AND amopopr = o.oid AND opcamid = 403ORDER BY 1; proname | oprname | amopstrategy ---------+---------+-------------- max | > | 5 min | < | 1(2 rows)-- **************** pg_opclass ****************-- Look for illegal values in pg_opclass fieldsSELECT p1.oidFROM pg_opclass as p1WHERE p1.opcamid = 0 OR p1.opcintype = 0; oid -----(0 rows)-- There should not be multiple entries in pg_opclass with opcdefault true-- and the same opcamid/opcintype combination.SELECT p1.oid, p2.oidFROM pg_opclass AS p1, pg_opclass AS p2WHERE p1.oid != p2.oid AND p1.opcamid = p2.opcamid AND p1.opcintype = p2.opcintype AND p1.opcdefault AND p2.opcdefault; oid | oid -----+-----(0 rows)-- **************** pg_amop ****************-- Look for illegal values in pg_amop fieldsSELECT p1.amopclaid, p1.amopstrategyFROM pg_amop as p1WHERE p1.amopclaid = 0 OR p1.amopstrategy <= 0 OR p1.amopopr = 0; amopclaid | amopstrategy -----------+--------------(0 rows)-- Cross-check amopstrategy index against parent AMSELECT p1.amopclaid, p1.amopopr, p2.oid, p2.amnameFROM pg_amop AS p1, pg_am AS p2, pg_opclass AS p3WHERE p1.amopclaid = p3.oid AND p3.opcamid = p2.oid AND p1.amopstrategy > p2.amstrategies; amopclaid | amopopr | oid | amname -----------+---------+-----+--------(0 rows)-- Detect missing pg_amop entries: should have as many strategy operators-- as AM expects for each opclass for the AM. When nondefault subtypes are-- present, enforce condition separately for each subtype.-- We have to exclude GiST, unfortunately, since it hasn't got any fixed-- requirements about strategy operators.SELECT p1.oid, p1.amname, p2.oid, p2.opcname, p3.amopsubtypeFROM pg_am AS p1, pg_opclass AS p2, pg_amop AS p3WHERE p2.opcamid = p1.oid AND p3.amopclaid = p2.oid AND p1.amname != 'gist' AND p1.amstrategies != (SELECT count(*) FROM pg_amop AS p4 WHERE p4.amopclaid = p2.oid AND p4.amopsubtype = p3.amopsubtype); oid | amname | oid | opcname | amopsubtype -----+--------+-----+---------+-------------(0 rows)-- Check that amopopr points at a reasonable-looking operator, ie a binary-- operator yielding boolean.SELECT p1.amopclaid, p1.amopopr, p2.oid, p2.oprnameFROM pg_amop AS p1, pg_operator AS p2WHERE p1.amopopr = p2.oid AND (p2.oprkind != 'b' OR p2.oprresult != 'bool'::regtype); amopclaid | amopopr | oid | oprname -----------+---------+-----+---------(0 rows)-- Make a list of all the distinct operator names being used in particular-- strategy slots. This is a bit hokey, since the list might need to change-- in future releases, but it's an effective way of spotting mistakes such as-- swapping two operators within a class.SELECT DISTINCT opcamid, amopstrategy, oprnameFROM pg_amop p1 LEFT JOIN pg_opclass p2 ON amopclaid = p2.oid LEFT JOIN pg_operator p3 ON amopopr = p3.oidORDER BY 1, 2, 3; opcamid | amopstrategy | oprname ---------+--------------+--------- 402 | 1 | << 402 | 2 | &< 402 | 3 | && 402 | 4 | &> 402 | 5 | >> 402 | 6 | ~= 402 | 7 | ~ 402 | 8 | @ 402 | 9 | &<| 402 | 10 | <<| 402 | 11 | |>> 402 | 12 | |&> 403 | 1 | < 403 | 1 | ~<~ 403 | 2 | <= 403 | 2 | ~<=~ 403 | 3 | = 403 | 3 | ~=~ 403 | 4 | >= 403 | 4 | ~>=~ 403 | 5 | > 403 | 5 | ~>~ 405 | 1 | = 405 | 1 | ~=~ 783 | 1 | << 783 | 2 | &< 783 | 3 | && 783 | 4 | &> 783 | 5 | >> 783 | 6 | ~= 783 | 7 | ~ 783 | 8 | @ 783 | 9 | &<| 783 | 10 | <<| 783 | 11 | |>> 783 | 12 | |&>(36 rows)-- Check that all operators linked to by opclass entries have selectivity-- estimators. This is not absolutely required, but it seems a reasonable-- thing to insist on for all standard datatypes.SELECT p1.amopclaid, p1.amopopr, p2.oid, p2.oprnameFROM pg_amop AS p1, pg_operator AS p2WHERE p1.amopopr = p2.oid AND (p2.oprrest = 0 OR p2.oprjoin = 0); amopclaid | amopopr | oid | oprname -----------+---------+-----+---------(0 rows)-- Check that operator input types match the opclass-- For 8.0, we require that oprleft match opcintype (possibly by coercion).-- When amopsubtype is zero (default), oprright must equal oprleft;-- when amopsubtype is not zero, oprright must equal amopsubtype.SELECT p1.amopclaid, p1.amopopr, p2.oid, p2.oprname, p3.opcnameFROM pg_amop AS p1, pg_operator AS p2, pg_opclass AS p3WHERE p1.amopopr = p2.oid AND p1.amopclaid = p3.oid AND NOT binary_coercible(p3.opcintype, p2.oprleft); amopclaid | amopopr | oid | oprname | opcname -----------+---------+-----+---------+---------(0 rows)SELECT p1.amopclaid, p1.amopopr, p2.oid, p2.oprname, p3.opcnameFROM pg_amop AS p1, pg_operator AS p2, pg_opclass AS p3WHERE p1.amopopr = p2.oid AND p1.amopclaid = p3.oid AND p1.amopsubtype = 0 AND p2.oprleft != p2.oprright; amopclaid | amopopr | oid | oprname | opcname -----------+---------+-----+---------+---------(0 rows)SELECT p1.amopclaid, p1.amopopr, p2.oid, p2.oprname, p3.opcnameFROM pg_amop AS p1, pg_operator AS p2, pg_opclass AS p3WHERE p1.amopopr = p2.oid AND p1.amopclaid = p3.oid AND p1.amopsubtype != 0 AND p1.amopsubtype != p2.oprright; amopclaid | amopopr | oid | oprname | opcname -----------+---------+-----+---------+---------(0 rows)-- Operators that are primary members of opclasses must be immutable (else-- it suggests that the index ordering isn't fixed). Operators that are-- cross-type members need only be stable, since they are just shorthands-- for index probe queries.SELECT p1.amopclaid, p1.amopopr, p2.oprname, p3.prosrcFROM pg_amop AS p1, pg_operator AS p2, pg_proc AS p3WHERE p1.amopopr = p2.oid AND p2.oprcode = p3.oid AND p1.amopsubtype = 0 AND p3.provolatile != 'i'; amopclaid | amopopr | oprname | prosrc -----------+---------+---------+--------(0 rows)SELECT p1.amopclaid, p1.amopopr, p2.oprname, p3.prosrcFROM pg_amop AS p1, pg_operator AS p2, pg_proc AS p3WHERE p1.amopopr = p2.oid AND p2.oprcode = p3.oid AND p1.amopsubtype != 0 AND p3.provolatile = 'v'; amopclaid | amopopr | oprname | prosrc -----------+---------+---------+--------(0 rows)-- **************** pg_amproc ****************-- Look for illegal values in pg_amproc fieldsSELECT p1.amopclaid, p1.amprocnumFROM pg_amproc as p1WHERE p1.amopclaid = 0 OR p1.amprocnum <= 0 OR p1.amproc = 0; amopclaid | amprocnum -----------+-----------(0 rows)-- Cross-check amprocnum index against parent AMSELECT p1.amopclaid, p1.amprocnum, p2.oid, p2.amnameFROM pg_amproc AS p1, pg_am AS p2, pg_opclass AS p3WHERE p1.amopclaid = p3.oid AND p3.opcamid = p2.oid AND p1.amprocnum > p2.amsupport; amopclaid | amprocnum | oid | amname -----------+-----------+-----+--------(0 rows)-- Detect missing pg_amproc entries: should have as many support functions-- as AM expects for each opclass for the AM. When nondefault subtypes are-- present, enforce condition separately for each subtype.SELECT p1.oid, p1.amname, p2.oid, p2.opcname, p3.amprocsubtypeFROM pg_am AS p1, pg_opclass AS p2, pg_amproc AS p3WHERE p2.opcamid = p1.oid AND p3.amopclaid = p2.oid AND p1.amsupport != (SELECT count(*) FROM pg_amproc AS p4 WHERE p4.amopclaid = p2.oid AND p4.amprocsubtype = p3.amprocsubtype); oid | amname | oid | opcname | amprocsubtype -----+--------+-----+---------+---------------(0 rows)-- Unfortunately, we can't check the amproc link very well because the-- signature of the function may be different for different support routines-- or different base data types.-- We can check that all the referenced instances of the same support-- routine number take the same number of parameters, but that's about it-- for a general check...SELECT p1.amopclaid, p1.amprocnum, p2.oid, p2.proname, p3.opcname, p4.amopclaid, p4.amprocnum, p5.oid, p5.proname, p6.opcnameFROM pg_amproc AS p1, pg_proc AS p2, pg_opclass AS p3, pg_amproc AS p4, pg_proc AS p5, pg_opclass AS p6WHERE p1.amopclaid = p3.oid AND p4.amopclaid = p6.oid AND p3.opcamid = p6.opcamid AND p1.amprocnum = p4.amprocnum AND p1.amproc = p2.oid AND p4.amproc = p5.oid AND (p2.proretset OR p5.proretset OR p2.pronargs != p5.pronargs); amopclaid | amprocnum | oid | proname | opcname | amopclaid | amprocnum | oid | proname | opcname -----------+-----------+-----+---------+---------+-----------+-----------+-----+---------+---------(0 rows)-- For btree, though, we can do better since we know the support routines-- must be of the form cmp(input, input) returns int4 in the default case-- (subtype = 0), and cmp(input, subtype) returns int4 when subtype != 0.SELECT p1.amopclaid, p1.amprocnum, p2.oid, p2.proname, p3.opcnameFROM pg_amproc AS p1, pg_proc AS p2, pg_opclass AS p3WHERE p3.opcamid = (SELECT oid FROM pg_am WHERE amname = 'btree') AND p1.amopclaid = p3.oid AND p1.amproc = p2.oid AND amprocsubtype = 0 AND (opckeytype != 0 OR amprocnum != 1 OR proretset OR prorettype != 23 OR pronargs != 2 OR NOT binary_coercible(opcintype, proargtypes[0]) OR proargtypes[0] != proargtypes[1]); amopclaid | amprocnum | oid | proname | opcname -----------+-----------+-----+---------+---------(0 rows)SELECT p1.amopclaid, p1.amprocnum, p2.oid, p2.proname, p3.opcnameFROM pg_amproc AS p1, pg_proc AS p2, pg_opclass AS p3WHERE p3.opcamid = (SELECT oid FROM pg_am WHERE amname = 'btree') AND p1.amopclaid = p3.oid AND p1.amproc = p2.oid AND amprocsubtype != 0 AND (opckeytype != 0 OR amprocnum != 1 OR proretset OR prorettype != 23 OR pronargs != 2 OR NOT binary_coercible(opcintype, proargtypes[0]) OR proargtypes[1] != amprocsubtype); amopclaid | amprocnum | oid | proname | opcname -----------+-----------+-----+---------+---------(0 rows)-- For hash we can also do a little better: the support routines must be-- of the form hash(something) returns int4. Ideally we'd check that the-- opcintype is binary-coercible to the function's input, but there are-- enough cases where that fails that I'll just leave out the check for now.SELECT p1.amopclaid, p1.amprocnum, p2.oid, p2.proname, p3.opcnameFROM pg_amproc AS p1, pg_proc AS p2, pg_opclass AS p3WHERE p3.opcamid = (SELECT oid FROM pg_am WHERE amname = 'hash') AND p1.amopclaid = p3.oid AND p1.amproc = p2.oid AND (opckeytype != 0 OR amprocnum != 1 OR proretset OR prorettype != 23 OR pronargs != 1-- OR NOT physically_coercible(opcintype, proargtypes[0])); amopclaid | amprocnum | oid | proname | opcname -----------+-----------+-----+---------+---------(0 rows)-- Support routines that are primary members of opclasses must be immutable-- (else it suggests that the index ordering isn't fixed). But cross-type-- members need only be stable, since they are just shorthands-- for index probe queries.SELECT p1.amopclaid, p1.amproc, p2.prosrcFROM pg_amproc AS p1, pg_proc AS p2WHERE p1.amproc = p2.oid AND p1.amprocsubtype = 0 AND p2.provolatile != 'i'; amopclaid | amproc | prosrc -----------+--------+--------(0 rows)SELECT p1.amopclaid, p1.amproc, p2.prosrcFROM pg_amproc AS p1, pg_proc AS p2WHERE p1.amproc = p2.oid AND p1.amprocsubtype != 0 AND p2.provolatile = 'v'; amopclaid | amproc | prosrc -----------+--------+--------(0 rows)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -