opr_sanity.out
来自「PostgreSQL7.4.6 for Linux」· OUT 代码 · 共 824 行 · 第 1/3 页
OUT
824 行
oid | oprname -----+---------(0 rows)-- Look for missing or unwanted operand typesSELECT p1.oid, p1.oprnameFROM pg_operator as p1WHERE (p1.oprleft = 0 and p1.oprkind != 'l') OR (p1.oprleft != 0 and p1.oprkind = 'l') OR (p1.oprright = 0 and p1.oprkind != 'r') OR (p1.oprright != 0 and p1.oprkind = 'r'); oid | oprname -----+---------(0 rows)-- Look for conflicting operator definitions (same names and input datatypes).SELECT p1.oid, p1.oprcode, p2.oid, p2.oprcodeFROM pg_operator AS p1, pg_operator AS p2WHERE p1.oid != p2.oid AND p1.oprname = p2.oprname AND p1.oprkind = p2.oprkind AND p1.oprleft = p2.oprleft AND p1.oprright = p2.oprright; oid | oprcode | oid | oprcode -----+---------+-----+---------(0 rows)-- Look for commutative operators that don't commute.-- DEFINITIONAL NOTE: If A.oprcom = B, then x A y has the same result as y B x.-- We expect that B will always say that B.oprcom = A as well; that's not-- inherently essential, but it would be inefficient not to mark it so.SELECT p1.oid, p1.oprcode, p2.oid, p2.oprcodeFROM pg_operator AS p1, pg_operator AS p2WHERE p1.oprcom = p2.oid AND (p1.oprkind != 'b' OR p1.oprleft != p2.oprright OR p1.oprright != p2.oprleft OR p1.oprresult != p2.oprresult OR p1.oid != p2.oprcom); oid | oprcode | oid | oprcode -----+---------+-----+---------(0 rows)-- Look for negatory operators that don't agree.-- DEFINITIONAL NOTE: If A.oprnegate = B, then both A and B must yield-- boolean results, and (x A y) == ! (x B y), or the equivalent for-- single-operand operators.-- We expect that B will always say that B.oprnegate = A as well; that's not-- inherently essential, but it would be inefficient not to mark it so.-- Also, A and B had better not be the same operator.SELECT p1.oid, p1.oprcode, p2.oid, p2.oprcodeFROM pg_operator AS p1, pg_operator AS p2WHERE p1.oprnegate = p2.oid AND (p1.oprkind != p2.oprkind OR p1.oprleft != p2.oprleft OR p1.oprright != p2.oprright OR p1.oprresult != 'bool'::regtype OR p2.oprresult != 'bool'::regtype OR p1.oid != p2.oprnegate OR p1.oid = p2.oid); oid | oprcode | oid | oprcode -----+---------+-----+---------(0 rows)-- Look for mergejoin operators that don't match their links.-- An lsortop/rsortop link leads from an '=' operator to the-- sort operator ('<' operator) that's appropriate for-- its left-side or right-side data type.-- An ltcmpop/gtcmpop link leads from an '=' operator to the-- '<' or '>' operator of the same input datatypes.-- (If the '=' operator has identical L and R input datatypes,-- then lsortop, rsortop, and ltcmpop are all the same operator.)SELECT p1.oid, p1.oprcode, p2.oid, p2.oprcodeFROM pg_operator AS p1, pg_operator AS p2WHERE p1.oprlsortop = p2.oid AND (p1.oprname NOT IN ('=', '~=~') OR p2.oprname NOT IN ('<', '~<~') OR p1.oprkind != 'b' OR p2.oprkind != 'b' OR p1.oprleft != p2.oprleft OR p1.oprleft != p2.oprright OR p1.oprresult != 'bool'::regtype OR p2.oprresult != 'bool'::regtype); oid | oprcode | oid | oprcode -----+---------+-----+---------(0 rows)SELECT p1.oid, p1.oprcode, p2.oid, p2.oprcodeFROM pg_operator AS p1, pg_operator AS p2WHERE p1.oprrsortop = p2.oid AND (p1.oprname NOT IN ('=', '~=~') OR p2.oprname NOT IN ('<', '~<~') OR p1.oprkind != 'b' OR p2.oprkind != 'b' OR p1.oprright != p2.oprleft OR p1.oprright != p2.oprright OR p1.oprresult != 'bool'::regtype OR p2.oprresult != 'bool'::regtype); oid | oprcode | oid | oprcode -----+---------+-----+---------(0 rows)SELECT p1.oid, p1.oprcode, p2.oid, p2.oprcodeFROM pg_operator AS p1, pg_operator AS p2WHERE p1.oprltcmpop = p2.oid AND (p1.oprname NOT IN ('=', '~=~') OR p2.oprname NOT IN ('<', '~<~') OR p1.oprkind != 'b' OR p2.oprkind != 'b' OR p1.oprleft != p2.oprleft OR p1.oprright != p2.oprright OR p1.oprresult != 'bool'::regtype OR p2.oprresult != 'bool'::regtype); oid | oprcode | oid | oprcode -----+---------+-----+---------(0 rows)SELECT p1.oid, p1.oprcode, p2.oid, p2.oprcodeFROM pg_operator AS p1, pg_operator AS p2WHERE p1.oprgtcmpop = p2.oid AND (p1.oprname NOT IN ('=', '~=~') OR p2.oprname NOT IN ('>', '~>~') OR p1.oprkind != 'b' OR p2.oprkind != 'b' OR p1.oprleft != p2.oprleft OR p1.oprright != p2.oprright OR p1.oprresult != 'bool'::regtype OR p2.oprresult != 'bool'::regtype); oid | oprcode | oid | oprcode -----+---------+-----+---------(0 rows)-- Make sure all four links are specified if any are.SELECT p1.oid, p1.oprcodeFROM pg_operator AS p1WHERE NOT ((oprlsortop = 0 AND oprrsortop = 0 AND oprltcmpop = 0 AND oprgtcmpop = 0) OR (oprlsortop != 0 AND oprrsortop != 0 AND oprltcmpop != 0 AND oprgtcmpop != 0)); oid | oprcode -----+---------(0 rows)-- A mergejoinable = operator must have a commutator (usually itself).SELECT p1.oid, p1.oprname FROM pg_operator AS p1WHERE p1.oprlsortop != 0 AND p1.oprcom = 0; oid | oprname -----+---------(0 rows)-- Mergejoinable operators across datatypes must come in closed sets, that-- is if you provide int2 = int4 and int4 = int8 then you must also provide-- int2 = int8 (and commutators of all these). This is necessary because-- the planner tries to deduce additional qual clauses from transitivity-- of mergejoinable operators. If there are clauses int2var = int4var and-- int4var = int8var, the planner will deduce int2var = int8var ... and it-- had better have a way to represent it.SELECT p1.oid, p2.oid FROM pg_operator AS p1, pg_operator AS p2WHERE p1.oprlsortop != p1.oprrsortop AND p1.oprrsortop = p2.oprlsortop AND p2.oprlsortop != p2.oprrsortop AND NOT EXISTS (SELECT 1 FROM pg_operator p3 WHERE p3.oprlsortop = p1.oprlsortop AND p3.oprrsortop = p2.oprrsortop); oid | oid -----+-----(0 rows)-- Hashing only works on simple equality operators "type = sametype",-- since the hash itself depends on the bitwise representation of the type.-- Check that allegedly hashable operators look like they might be "=".SELECT p1.oid, p1.oprnameFROM pg_operator AS p1WHERE p1.oprcanhash AND NOT (p1.oprkind = 'b' AND p1.oprresult = 'bool'::regtype AND p1.oprleft = p1.oprright AND p1.oprname IN ('=', '~=~') AND p1.oprcom = p1.oid); oid | oprname -----+---------(0 rows)-- In 6.5 we accepted hashable array equality operators when the array element-- type is hashable. However, what we actually need to make hashjoin work on-- an array is a hashable element type *and* no padding between elements in-- the array storage (or, perhaps, guaranteed-zero padding). Currently,-- since the padding code in arrayfuncs.c is pretty bogus, it seems safest-- to just forbid hashjoin on array equality ops.-- This should be reconsidered someday.-- -- Look for array equality operators that are hashable when the underlying-- -- type is not, or vice versa. This is presumably bogus.-- -- SELECT p1.oid, p1.oprcanhash, p2.oid, p2.oprcanhash, t1.typname, t2.typname-- FROM pg_operator AS p1, pg_operator AS p2, pg_type AS t1, pg_type AS t2-- WHERE p1.oprname = '=' AND p1.oprleft = p1.oprright AND -- p2.oprname = '=' AND p2.oprleft = p2.oprright AND-- p1.oprleft = t1.oid AND p2.oprleft = t2.oid AND t1.typelem = t2.oid AND-- p1.oprcanhash != p2.oprcanhash;-- Substitute check: forbid hashable array ops, period.SELECT p1.oid, p1.oprnameFROM pg_operator AS p1, pg_proc AS p2WHERE p1.oprcanhash AND p1.oprcode = p2.oid AND p2.proname = 'array_eq'; oid | oprname -----+---------(0 rows)-- Hashable operators should appear as members of hash index opclasses.SELECT p1.oid, p1.oprnameFROM pg_operator AS p1WHERE p1.oprcanhash AND NOT EXISTS (SELECT 1 FROM pg_opclass op JOIN pg_amop p ON op.oid = amopclaid WHERE opcamid = (SELECT oid FROM pg_am WHERE amname = 'hash') AND amopopr = p1.oid); oid | oprname -----+---------(0 rows)-- Check that each operator defined in pg_operator matches its oprcode entry-- in pg_proc. Easiest to do this separately for each oprkind.SELECT p1.oid, p1.oprname, p2.oid, p2.pronameFROM pg_operator AS p1, pg_proc AS p2WHERE p1.oprcode = p2.oid AND p1.oprkind = 'b' AND (p2.pronargs != 2 OR NOT binary_coercible(p2.prorettype, p1.oprresult) OR NOT binary_coercible(p1.oprleft, p2.proargtypes[0]) OR NOT binary_coercible(p1.oprright, p2.proargtypes[1])); oid | oprname | oid | proname -----+---------+-----+---------(0 rows)SELECT p1.oid, p1.oprname, p2.oid, p2.pronameFROM pg_operator AS p1, pg_proc AS p2WHERE p1.oprcode = p2.oid AND p1.oprkind = 'l' AND (p2.pronargs != 1 OR NOT binary_coercible(p2.prorettype, p1.oprresult) OR NOT binary_coercible(p1.oprright, p2.proargtypes[0]) OR p1.oprleft != 0); oid | oprname | oid | proname -----+---------+-----+---------(0 rows)SELECT p1.oid, p1.oprname, p2.oid, p2.pronameFROM pg_operator AS p1, pg_proc AS p2WHERE p1.oprcode = p2.oid AND p1.oprkind = 'r' AND (p2.pronargs != 1 OR NOT binary_coercible(p2.prorettype, p1.oprresult) OR NOT binary_coercible(p1.oprleft, p2.proargtypes[0]) OR p1.oprright != 0); oid | oprname | oid | proname -----+---------+-----+---------(0 rows)-- If the operator is mergejoinable or hashjoinable, its underlying function-- should not be volatile.SELECT p1.oid, p1.oprname, p2.oid, p2.pronameFROM pg_operator AS p1, pg_proc AS p2WHERE p1.oprcode = p2.oid AND (p1.oprlsortop != 0 OR p1.oprcanhash) AND p2.provolatile = 'v'; oid | oprname | oid | proname -----+---------+-----+---------(0 rows)-- If oprrest is set, the operator must return boolean,-- and it must link to a proc with the right signature-- to be a restriction selectivity estimator.-- The proc signature we want is: float8 proc(internal, oid, internal, int4)SELECT p1.oid, p1.oprname, p2.oid, p2.pronameFROM pg_operator AS p1, pg_proc AS p2WHERE p1.oprrest = p2.oid AND (p1.oprresult != 'bool'::regtype OR p2.prorettype != 'float8'::regtype OR p2.proretset OR p2.pronargs != 4 OR p2.proargtypes[0] != 'internal'::regtype OR p2.proargtypes[1] != 'oid'::regtype OR p2.proargtypes[2] != 'internal'::regtype OR p2.proargtypes[3] != 'int4'::regtype); oid | oprname | oid | proname -----+---------+-----+---------(0 rows)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?