opr_sanity.out

来自「PostgreSQL7.4.6 for Linux」· OUT 代码 · 共 824 行 · 第 1/3 页

OUT
824
字号
---- OPR_SANITY-- Sanity checks for common errors in making operator/procedure system tables:-- pg_operator, pg_proc, pg_cast, pg_aggregate, pg_am, pg_amop, pg_amproc, pg_opclass.---- None of the SELECTs here should ever find any matching entries,-- so the expected output is easy to maintain ;-).-- A test failure indicates someone messed up an entry in the system tables.---- NB: we assume the oidjoins test will have caught any dangling links,-- that is OID or REGPROC fields that are not zero and do not match some-- row in the linked-to table.  However, if we want to enforce that a link-- field can't be 0, we have to check it here.---- NB: run this test earlier than the create_operator test, because-- that test creates some bogus operators...-- Helper functions to deal with cases where binary-coercible matches are-- allowed.-- This should match IsBinaryCoercible() in parse_coerce.c.create function binary_coercible(oid, oid) returns bool as'SELECT ($1 = $2) OR EXISTS(select 1 from pg_cast where        castsource = $1 and casttarget = $2 and        castfunc = 0 and castcontext = ''i'')'language sql;-- This one ignores castcontext, so it considers only physical equivalence-- and not whether the coercion can be invoked implicitly.create function physically_coercible(oid, oid) returns bool as'SELECT ($1 = $2) OR EXISTS(select 1 from pg_cast where        castsource = $1 and casttarget = $2 and        castfunc = 0)'language sql;-- **************** pg_proc ****************-- Look for illegal values in pg_proc fields.-- NOTE: in reality pronargs could be more than 10, but I'm too lazy to put-- a larger number of proargtypes check clauses in here.  If we ever have-- more-than-10-arg functions in the standard catalogs, extend this query.SELECT p1.oid, p1.pronameFROM pg_proc as p1WHERE p1.prolang = 0 OR p1.prorettype = 0 OR       p1.pronargs < 0 OR p1.pronargs > 10 OR       (p1.proargtypes[0] = 0 AND p1.pronargs > 0) OR       (p1.proargtypes[1] = 0 AND p1.pronargs > 1) OR       (p1.proargtypes[2] = 0 AND p1.pronargs > 2) OR       (p1.proargtypes[3] = 0 AND p1.pronargs > 3) OR       (p1.proargtypes[4] = 0 AND p1.pronargs > 4) OR       (p1.proargtypes[5] = 0 AND p1.pronargs > 5) OR       (p1.proargtypes[6] = 0 AND p1.pronargs > 6) OR       (p1.proargtypes[7] = 0 AND p1.pronargs > 7) OR       (p1.proargtypes[8] = 0 AND p1.pronargs > 8) OR       (p1.proargtypes[9] = 0 AND p1.pronargs > 9); oid | proname -----+---------(0 rows)-- Look for conflicting proc definitions (same names and input datatypes).-- (This test should be dead code now that we have the unique index-- pg_proc_proname_narg_type_index, but I'll leave it in anyway.)SELECT p1.oid, p1.proname, p2.oid, p2.pronameFROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.proname = p2.proname AND    p1.pronargs = p2.pronargs AND    p1.proargtypes = p2.proargtypes; oid | proname | oid | proname -----+---------+-----+---------(0 rows)-- Considering only built-in procs (prolang = 12), look for multiple uses-- of the same internal function (ie, matching prosrc fields).  It's OK to-- have several entries with different pronames for the same internal function,-- but conflicts in the number of arguments and other critical items should-- be complained of.SELECT p1.oid, p1.proname, p2.oid, p2.pronameFROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    (p1.prolang != p2.prolang OR     p1.proisagg != p2.proisagg OR     p1.prosecdef != p2.prosecdef OR     p1.proisstrict != p2.proisstrict OR     p1.proretset != p2.proretset OR     p1.provolatile != p2.provolatile OR     p1.pronargs != p2.pronargs); oid | proname | oid | proname -----+---------+-----+---------(0 rows)-- Look for uses of different type OIDs in the argument/result type fields-- for different aliases of the same built-in function.-- This indicates that the types are being presumed to be binary-equivalent,-- or that the built-in function is prepared to deal with different types.-- That's not wrong, necessarily, but we make lists of all the types being-- so treated.  Note that the expected output of this part of the test will-- need to be modified whenever new pairs of types are made binary-equivalent,-- or when new polymorphic built-in functions are added!-- Note: ignore aggregate functions here, since they all point to the same-- dummy built-in function.SELECT DISTINCT p1.prorettype, p2.prorettypeFROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    NOT p1.proisagg AND NOT p2.proisagg AND    (p1.prorettype < p2.prorettype); prorettype | prorettype ------------+------------         25 |       1043       1114 |       1184(2 rows)SELECT DISTINCT p1.proargtypes[0], p2.proargtypes[0]FROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    NOT p1.proisagg AND NOT p2.proisagg AND    (p1.proargtypes[0] < p2.proargtypes[0]); proargtypes | proargtypes -------------+-------------          25 |        1042          25 |        1043        1114 |        1184        1560 |        1562        2277 |        2283(5 rows)SELECT DISTINCT p1.proargtypes[1], p2.proargtypes[1]FROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    NOT p1.proisagg AND NOT p2.proisagg AND    (p1.proargtypes[1] < p2.proargtypes[1]); proargtypes | proargtypes -------------+-------------          23 |          28          25 |        1042        1114 |        1184        1560 |        1562        2277 |        2283(5 rows)SELECT DISTINCT p1.proargtypes[2], p2.proargtypes[2]FROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    NOT p1.proisagg AND NOT p2.proisagg AND    (p1.proargtypes[2] < p2.proargtypes[2]); proargtypes | proargtypes -------------+-------------        1114 |        1184(1 row)SELECT DISTINCT p1.proargtypes[3], p2.proargtypes[3]FROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    NOT p1.proisagg AND NOT p2.proisagg AND    (p1.proargtypes[3] < p2.proargtypes[3]); proargtypes | proargtypes -------------+-------------        1114 |        1184(1 row)SELECT DISTINCT p1.proargtypes[4], p2.proargtypes[4]FROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    NOT p1.proisagg AND NOT p2.proisagg AND    (p1.proargtypes[4] < p2.proargtypes[4]); proargtypes | proargtypes -------------+-------------(0 rows)SELECT DISTINCT p1.proargtypes[5], p2.proargtypes[5]FROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    NOT p1.proisagg AND NOT p2.proisagg AND    (p1.proargtypes[5] < p2.proargtypes[5]); proargtypes | proargtypes -------------+-------------(0 rows)SELECT DISTINCT p1.proargtypes[6], p2.proargtypes[6]FROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    NOT p1.proisagg AND NOT p2.proisagg AND    (p1.proargtypes[6] < p2.proargtypes[6]); proargtypes | proargtypes -------------+-------------(0 rows)SELECT DISTINCT p1.proargtypes[7], p2.proargtypes[7]FROM pg_proc AS p1, pg_proc AS p2WHERE p1.oid != p2.oid AND    p1.prosrc = p2.prosrc AND    p1.prolang = 12 AND p2.prolang = 12 AND    NOT p1.proisagg AND NOT p2.proisagg AND    (p1.proargtypes[7] < p2.proargtypes[7]); proargtypes | proargtypes -------------+-------------(0 rows)-- Look for functions that return type "internal" and do not have any-- "internal" argument.  Such a function would be a security hole since-- it might be used to call an internal function from an SQL command.-- As of 7.3 this query should find only internal_in.SELECT p1.oid, p1.pronameFROM pg_proc as p1WHERE p1.prorettype = 'internal'::regtype AND NOT    ('(' || oidvectortypes(p1.proargtypes) || ')') ~ '[^a-z0-9_]internal[^a-z0-9_]'; oid  |   proname   ------+------------- 2304 | internal_in(1 row)-- **************** pg_cast ****************-- Look for casts from and to the same type.  This is not harmful, but-- useless.  Also catch bogus values in pg_cast columns (other than-- cases detected by oidjoins test).SELECT *FROM pg_cast cWHERE castsource = casttarget OR castsource = 0 OR casttarget = 0    OR castcontext NOT IN ('e', 'a', 'i'); castsource | casttarget | castfunc | castcontext ------------+------------+----------+-------------(0 rows)-- Look for cast functions that don't have the right signature.  The-- argument and result types in pg_proc must be the same as, or binary-- compatible with, what it says in pg_cast.SELECT c.*FROM pg_cast c, pg_proc pWHERE c.castfunc = p.oid AND    (p.pronargs <> 1     OR NOT binary_coercible(c.castsource, p.proargtypes[0])     OR NOT binary_coercible(p.prorettype, c.casttarget)); castsource | casttarget | castfunc | castcontext ------------+------------+----------+-------------(0 rows)-- Look for binary compatible casts that do not have the reverse-- direction registered as well, or where the reverse direction is not-- also binary compatible.  This is legal, but usually not intended.-- As of 7.4, this finds the casts from text and varchar to bpchar, because-- those are binary-compatible while the reverse way goes through rtrim().SELECT *FROM pg_cast cWHERE c.castfunc = 0 AND    NOT EXISTS (SELECT 1 FROM pg_cast k                WHERE k.castfunc = 0 AND                    k.castsource = c.casttarget AND                    k.casttarget = c.castsource); castsource | casttarget | castfunc | castcontext ------------+------------+----------+-------------         25 |       1042 |        0 | i       1043 |       1042 |        0 | i(2 rows)-- **************** pg_operator ****************-- Look for illegal values in pg_operator fields.SELECT p1.oid, p1.oprnameFROM pg_operator as p1WHERE (p1.oprkind != 'b' AND p1.oprkind != 'l' AND p1.oprkind != 'r') OR    p1.oprresult = 0 OR p1.oprcode = 0;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?