postgresql/src/include/catalog/pg_attribute.h

232 lines
7.4 KiB
C
Raw Normal View History

/*-------------------------------------------------------------------------
*
* pg_attribute.h
* definition of the system "attribute" relation (pg_attribute)
* along with the relation's initial contents.
*
*
2017-01-03 19:48:53 +01:00
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
2010-09-20 22:08:53 +02:00
* src/include/catalog/pg_attribute.h
*
* NOTES
* the genbki.pl script reads this file and generates .bki
* information from the DATA() statements.
*
*-------------------------------------------------------------------------
*/
#ifndef PG_ATTRIBUTE_H
#define PG_ATTRIBUTE_H
#include "catalog/genbki.h"
/* ----------------
* pg_attribute definition. cpp turns this into
* typedef struct FormData_pg_attribute
*
* If you change the following, make sure you change the structs for
* system attributes in catalog/heap.c also.
* You may need to change catalog/genbki.pl as well.
* ----------------
*/
#define AttributeRelationId 1249
#define AttributeRelation_Rowtype_Id 75
CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BKI_SCHEMA_MACRO
{
2005-10-15 04:49:52 +02:00
Oid attrelid; /* OID of relation containing this attribute */
NameData attname; /* name of attribute */
/*
* atttypid is the OID of the instance in Catalog Class pg_type that
2005-10-15 04:49:52 +02:00
* defines the data type of this attribute (e.g. int4). Information in
* that instance is redundant with the attlen, attbyval, and attalign
* attributes of this instance, so they had better match or Postgres will
* fail.
*/
Oid atttypid;
/*
2005-10-15 04:49:52 +02:00
* attstattarget is the target number of statistics datapoints to collect
* during VACUUM ANALYZE of this column. A zero here indicates that we do
* not wish to collect any stats about this column. A "-1" here indicates
* that no value has been explicitly set for this column, so ANALYZE
* should use the default setting.
*/
int32 attstattarget;
/*
2005-10-15 04:49:52 +02:00
* attlen is a copy of the typlen field from pg_type for this attribute.
* See atttypid comments above.
*/
int16 attlen;
/*
* attnum is the "attribute number" for the attribute: A value that
* uniquely identifies this attribute within its class. For user
2005-10-15 04:49:52 +02:00
* attributes, Attribute numbers are greater than 0 and not greater than
* the number of attributes in the class. I.e. if the Class pg_class says
* that Class XYZ has 10 attributes, then the user attribute numbers in
* Class pg_attribute must be 1-10.
*
* System attributes have attribute numbers less than 0 that are unique
* within the class, but not constrained to any particular range.
*
* Note that (attnum - 1) is often used as the index to an array.
*/
int16 attnum;
/*
* attndims is the declared number of dimensions, if an array type,
* otherwise zero.
*/
int32 attndims;
/*
2005-10-15 04:49:52 +02:00
* fastgetattr() uses attcacheoff to cache byte offsets of attributes in
* heap tuples. The value actually stored in pg_attribute (-1) indicates
* no cached value. But when we copy these tuples into a tuple
* descriptor, we may then update attcacheoff in the copies. This speeds
* up the attribute walking process.
*/
int32 attcacheoff;
/*
2005-10-15 04:49:52 +02:00
* atttypmod records type-specific data supplied at table creation time
* (for example, the max length of a varchar field). It is passed to
* type-specific input and output functions as the third argument. The
* value will generally be -1 for types that do not need typmod.
*/
int32 atttypmod;
/*
* attbyval is a copy of the typbyval field from pg_type for this
* attribute. See atttypid comments above.
*/
bool attbyval;
/*----------
* attstorage tells for VARLENA attributes, what the heap access
* methods can do to it if a given tuple doesn't fit into a page.
* Possible values are
* 'p': Value must be stored plain always
* 'e': Value can be stored in "secondary" relation (if relation
* has one, see pg_class.reltoastrelid)
* 'm': Value can be stored compressed inline
* 'x': Value can be stored compressed inline or in "secondary"
* Note that 'm' fields can also be moved out to secondary storage,
* but only as a last resort ('e' and 'x' fields are moved first).
*----------
*/
char attstorage;
/*
* attalign is a copy of the typalign field from pg_type for this
* attribute. See atttypid comments above.
*/
char attalign;
/* This flag represents the "NOT NULL" constraint */
bool attnotnull;
/* Has DEFAULT value or not */
bool atthasdef;
/* One of the ATTRIBUTE_IDENTITY_* constants below, or '\0' */
char attidentity;
/* Is dropped (ie, logically invisible) or not */
bool attisdropped;
/*
* This flag specifies whether this column has ever had a local
2015-05-24 03:35:49 +02:00
* definition. It is set for normal non-inherited columns, but also for
* columns that are inherited from parents if also explicitly listed in
* CREATE TABLE INHERITS. It is also set when inheritance is removed from
* a table with ALTER TABLE NO INHERIT. If the flag is set, the column is
* not dropped by a parent's DROP COLUMN even if this causes the column's
* attinhcount to become zero.
*/
bool attislocal;
/* Number of times inherited from direct parent relation(s) */
int32 attinhcount;
/* attribute's collation */
Oid attcollation;
#ifdef CATALOG_VARLEN /* variable-length fields start here */
/* NOTE: The following fields are not present in tuple descriptors. */
/* Column-level access permissions */
aclitem attacl[1];
/* Column-level options */
text attoptions[1];
/* Column-level FDW options */
text attfdwoptions[1];
#endif
} FormData_pg_attribute;
/*
* ATTRIBUTE_FIXED_PART_SIZE is the size of the fixed-layout,
* guaranteed-not-null part of a pg_attribute row. This is in fact as much
* of the row as gets copied into tuple descriptors, so don't expect you
* can access fields beyond attcollation except in a real tuple!
*/
#define ATTRIBUTE_FIXED_PART_SIZE \
(offsetof(FormData_pg_attribute,attcollation) + sizeof(Oid))
/* ----------------
* Form_pg_attribute corresponds to a pointer to a tuple with
* the format of pg_attribute relation.
* ----------------
*/
1998-09-01 05:29:17 +02:00
typedef FormData_pg_attribute *Form_pg_attribute;
/* ----------------
* compiler constants for pg_attribute
* ----------------
*/
#define Natts_pg_attribute 22
#define Anum_pg_attribute_attrelid 1
#define Anum_pg_attribute_attname 2
#define Anum_pg_attribute_atttypid 3
#define Anum_pg_attribute_attstattarget 4
#define Anum_pg_attribute_attlen 5
#define Anum_pg_attribute_attnum 6
#define Anum_pg_attribute_attndims 7
#define Anum_pg_attribute_attcacheoff 8
#define Anum_pg_attribute_atttypmod 9
#define Anum_pg_attribute_attbyval 10
#define Anum_pg_attribute_attstorage 11
#define Anum_pg_attribute_attalign 12
#define Anum_pg_attribute_attnotnull 13
#define Anum_pg_attribute_atthasdef 14
#define Anum_pg_attribute_attidentity 15
#define Anum_pg_attribute_attisdropped 16
#define Anum_pg_attribute_attislocal 17
#define Anum_pg_attribute_attinhcount 18
#define Anum_pg_attribute_attcollation 19
#define Anum_pg_attribute_attacl 20
#define Anum_pg_attribute_attoptions 21
#define Anum_pg_attribute_attfdwoptions 22
/* ----------------
* initial contents of pg_attribute
Clean up various to-do items associated with system indexes: pg_database now has unique indexes on oid and on datname. pg_shadow now has unique indexes on usename and on usesysid. pg_am now has unique index on oid. pg_opclass now has unique index on oid. pg_amproc now has unique index on amid+amopclaid+amprocnum. Remove pg_rewrite's unnecessary index on oid, delete unused RULEOID syscache. Remove index on pg_listener and associated syscache for performance reasons (caching rows that are certain to change before you need 'em again is rather pointless). Change pg_attrdef's nonunique index on adrelid into a unique index on adrelid+adnum. Fix various incorrect settings of pg_class.relisshared, make that the primary reference point for whether a relation is shared or not. IsSharedSystemRelationName() is now only consulted to initialize relisshared during initial creation of tables and indexes. In theory we might now support shared user relations, though it's not clear how one would get entries for them into pg_class &etc of multiple databases. Fix recently reported bug that pg_attribute rows created for an index all have the same OID. (Proof that non-unique OID doesn't matter unless it's actually used to do lookups ;-)) There's no need to treat pg_trigger, pg_attrdef, pg_relcheck as bootstrap relations. Convert them into plain system catalogs without hardwired entries in pg_class and friends. Unify global.bki and template1.bki into a single init script postgres.bki, since the alleged distinction between them was misleading and pointless. Not to mention that it didn't work for setting up indexes on shared system relations. Rationalize locking of pg_shadow, pg_group, pg_attrdef (no need to use AccessExclusiveLock where ExclusiveLock or even RowExclusiveLock will do). Also, hold locks until transaction commit where necessary.
2001-06-12 07:55:50 +02:00
*
* The initial contents of pg_attribute are generated at compile time by
* genbki.pl. Only "bootstrapped" relations need be included.
* ----------------
*/
#define ATTRIBUTE_IDENTITY_ALWAYS 'a'
#define ATTRIBUTE_IDENTITY_BY_DEFAULT 'd'
Phase 2 of pgindent updates. Change pg_bsd_indent to follow upstream rules for placement of comments to the right of code, and remove pgindent hack that caused comments following #endif to not obey the general rule. Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using the published version of pg_bsd_indent, but a hacked-up version that tried to minimize the amount of movement of comments to the right of code. The situation of interest is where such a comment has to be moved to the right of its default placement at column 33 because there's code there. BSD indent has always moved right in units of tab stops in such cases --- but in the previous incarnation, indent was working in 8-space tab stops, while now it knows we use 4-space tabs. So the net result is that in about half the cases, such comments are placed one tab stop left of before. This is better all around: it leaves more room on the line for comment text, and it means that in such cases the comment uniformly starts at the next 4-space tab stop after the code, rather than sometimes one and sometimes two tabs after. Also, ensure that comments following #endif are indented the same as comments following other preprocessor commands such as #else. That inconsistency turns out to have been self-inflicted damage from a poorly-thought-through post-indent "fixup" in pgindent. This patch is much less interesting than the first round of indent changes, but also bulkier, so I thought it best to separate the effects. Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
#endif /* PG_ATTRIBUTE_H */