mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
pgsql-hackers. pg_opclass now has a row for each opclass supported by each index AM, not a row for each opclass name. This allows pg_opclass to show directly whether an AM supports an opclass, and furthermore makes it possible to store additional information about an opclass that might be AM-dependent. pg_opclass and pg_amop now store "lossy" and "haskeytype" information that we previously expected the user to remember to provide in CREATE INDEX commands. Lossiness is no longer an index-level property, but is associated with the use of a particular operator in a particular index opclass. Along the way, IndexSupportInitialize now uses the syscaches to retrieve pg_amop and pg_amproc entries. I find this reduces backend launch time by about ten percent, at the cost of a couple more special cases in catcache.c's IndexScanOK. Initial work by Oleg Bartunov and Teodor Sigaev, further hacking by Tom Lane. initdb forced.
149 lines
4.0 KiB
Plaintext
149 lines
4.0 KiB
Plaintext
---------------------------------------------------------------------------
|
|
--
|
|
-- syscat.sql-
|
|
-- sample queries to the system catalogs
|
|
--
|
|
--
|
|
-- Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
|
-- Portions Copyright (c) 1994, Regents of the University of California
|
|
--
|
|
-- $Id: syscat.source,v 1.5 2001/08/21 16:36:06 tgl Exp $
|
|
--
|
|
---------------------------------------------------------------------------
|
|
|
|
--
|
|
-- lists the name of all database adminstrators and the name of their
|
|
-- database(s)
|
|
--
|
|
SELECT usename, datname
|
|
FROM pg_user, pg_database
|
|
WHERE usesysid = datdba
|
|
ORDER BY usename, datname;
|
|
|
|
--
|
|
-- lists all user-defined classes
|
|
--
|
|
SELECT relname
|
|
FROM pg_class
|
|
WHERE relkind = 'r' -- not indices, views, etc
|
|
and relname !~ '^pg_' -- not catalogs
|
|
ORDER BY relname;
|
|
|
|
|
|
--
|
|
-- lists all simple indices (ie. those that are not defined over a function
|
|
-- of several attributes)
|
|
--
|
|
SELECT bc.relname AS class_name,
|
|
ic.relname AS index_name,
|
|
a.attname
|
|
FROM pg_class bc, -- base class
|
|
pg_class ic, -- index class
|
|
pg_index i,
|
|
pg_attribute a -- att in base
|
|
WHERE i.indrelid = bc.oid
|
|
and i.indexrelid = ic.oid
|
|
and i.indkey[0] = a.attnum
|
|
and a.attrelid = bc.oid
|
|
and i.indproc = '0'::oid -- no functional indices
|
|
ORDER BY class_name, index_name, attname;
|
|
|
|
|
|
--
|
|
-- lists the user-defined attributes and their types for all user-defined
|
|
-- classes
|
|
--
|
|
SELECT c.relname, a.attname, t.typname
|
|
FROM pg_class c, pg_attribute a, pg_type t
|
|
WHERE c.relkind = 'r' -- no indices
|
|
and c.relname !~ '^pg_' -- no catalogs
|
|
and a.attnum > 0 -- no system att's
|
|
and a.attrelid = c.oid
|
|
and a.atttypid = t.oid
|
|
ORDER BY relname, attname;
|
|
|
|
|
|
--
|
|
-- lists all user-defined base types (not including array types)
|
|
--
|
|
SELECT u.usename, t.typname
|
|
FROM pg_type t, pg_user u
|
|
WHERE u.usesysid = t.typowner
|
|
and t.typrelid = '0'::oid -- no complex types
|
|
and t.typelem = '0'::oid -- no arrays
|
|
and u.usename <> 'postgres'
|
|
ORDER BY usename, typname;
|
|
|
|
|
|
--
|
|
-- lists all left unary operators
|
|
--
|
|
SELECT o.oprname AS left_unary,
|
|
right_type.typname AS operand,
|
|
result.typname AS return_type
|
|
FROM pg_operator o, pg_type right_type, pg_type result
|
|
WHERE o.oprkind = 'l' -- left unary
|
|
and o.oprright = right_type.oid
|
|
and o.oprresult = result.oid
|
|
ORDER BY operand;
|
|
|
|
|
|
--
|
|
-- lists all right unary operators
|
|
--
|
|
SELECT o.oprname AS right_unary,
|
|
left_type.typname AS operand,
|
|
result.typname AS return_type
|
|
FROM pg_operator o, pg_type left_type, pg_type result
|
|
WHERE o.oprkind = 'r' -- right unary
|
|
and o.oprleft = left_type.oid
|
|
and o.oprresult = result.oid
|
|
ORDER BY operand;
|
|
|
|
--
|
|
-- lists all binary operators
|
|
--
|
|
SELECT o.oprname AS binary_op,
|
|
left_type.typname AS left_opr,
|
|
right_type.typname AS right_opr,
|
|
result.typname AS return_type
|
|
FROM pg_operator o, pg_type left_type, pg_type right_type, pg_type result
|
|
WHERE o.oprkind = 'b' -- binary
|
|
and o.oprleft = left_type.oid
|
|
and o.oprright = right_type.oid
|
|
and o.oprresult = result.oid
|
|
ORDER BY left_opr, right_opr;
|
|
|
|
|
|
--
|
|
-- lists the name, number of arguments and the return type of all user-defined
|
|
-- C functions
|
|
--
|
|
SELECT p.proname, p.pronargs, t.typname
|
|
FROM pg_proc p, pg_language l, pg_type t
|
|
WHERE p.prolang = l.oid
|
|
and p.prorettype = t.oid
|
|
and l.lanname = 'c'
|
|
ORDER BY proname;
|
|
|
|
--
|
|
-- lists all aggregate functions and the types to which they can be applied
|
|
--
|
|
SELECT a.aggname, t.typname
|
|
FROM pg_aggregate a, pg_type t
|
|
WHERE a.aggbasetype = t.oid
|
|
ORDER BY aggname, typname;
|
|
|
|
|
|
--
|
|
-- lists all the operator classes that can be used with each access method
|
|
-- as well as the operators that cn be used with the respective operator
|
|
-- classes
|
|
--
|
|
SELECT am.amname, opc.opcname, opr.oprname
|
|
FROM pg_am am, pg_opclass opc, pg_amop amop, pg_operator opr
|
|
WHERE opc.opcamid = am.oid
|
|
and amop.amopclaid = opc.oid
|
|
and amop.amopopr = opr.oid
|
|
ORDER BY amname, opcname, oprname;
|