Skip to content

Commit e9c013f

Browse files
committed
Add unique index on pg_cast.oid, and document pg_cast table.
1 parent a7ffd69 commit e9c013f

File tree

4 files changed

+86
-15
lines changed

4 files changed

+86
-15
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.45 2002/07/12 18:43:12 tgl Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.46 2002/07/22 20:23:19 petere Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -66,6 +66,11 @@
6666
<entry>table columns (<quote>attributes</quote>, <quote>fields</quote>)</entry>
6767
</row>
6868

69+
<row>
70+
<entry>pg_cast</entry>
71+
<entry>casts (data type conversions)</entry>
72+
</row>
73+
6974
<row>
7075
<entry>pg_class</entry>
7176
<entry>tables, indexes, sequences (<quote>relations</quote>)</entry>
@@ -519,6 +524,65 @@
519524
</sect1>
520525

521526

527+
<sect1 id="catalog-pg-cast">
528+
<title>pg_cast</title>
529+
530+
<para>
531+
<structname>pg_cast</structname> stores data type conversion paths
532+
defined with <command>CREATE CAST</command> plus the built-in
533+
conversions.
534+
</para>
535+
536+
<table>
537+
<title>pg_cast Columns</title>
538+
539+
<tgroup cols=4>
540+
<thead>
541+
<row>
542+
<entry>Name</entry>
543+
<entry>Type</entry>
544+
<entry>References</entry>
545+
<entry>Description</entry>
546+
</row>
547+
</thead>
548+
549+
<tbody>
550+
<row>
551+
<entry>castsource</entry>
552+
<entry><type>oid</type></entry>
553+
<entry>pg_type.oid</entry>
554+
<entry>OID of the source data type</entry>
555+
</row>
556+
557+
<row>
558+
<entry>casttarget</entry>
559+
<entry><type>oid</type></entry>
560+
<entry>pg_type.oid</entry>
561+
<entry>OID of the target data type</entry>
562+
</row>
563+
564+
<row>
565+
<entry>castfunc</entry>
566+
<entry><type>oid</type></entry>
567+
<entry>pg_proc.oid</entry>
568+
<entry>
569+
The OID of the function to use to perform this cast. A 0 is
570+
stored if the data types are binary compatible (that is, no
571+
function is needed to perform the cast).
572+
</entry>
573+
</row>
574+
575+
<row>
576+
<entry>castimplicit</entry>
577+
<entry><type>bool</type></entry>
578+
<entry></entry>
579+
<entry>Indication whether this cast can be invoked implicitly</entry>
580+
</row>
581+
</tbody>
582+
</tgroup>
583+
</table>
584+
</sect1>
585+
522586
<sect1 id="catalog-pg-class">
523587
<title>pg_class</title>
524588

src/backend/catalog/indexing.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.98 2002/07/18 23:11:27 petere Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.99 2002/07/22 20:23:19 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -44,7 +44,7 @@ char *Name_pg_attr_indices[Num_pg_attr_indices] =
4444
char *Name_pg_attrdef_indices[Num_pg_attrdef_indices] =
4545
{AttrDefaultIndex, AttrDefaultOidIndex};
4646
char *Name_pg_cast_indices[Num_pg_cast_indices] =
47-
{CastSourceTargetIndex};
47+
{CastOidIndex, CastSourceTargetIndex};
4848
char *Name_pg_class_indices[Num_pg_class_indices] =
4949
{ClassNameNspIndex, ClassOidIndex};
5050
char *Name_pg_constraint_indices[Num_pg_constraint_indices] =

src/backend/commands/functioncmds.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.11 2002/07/20 05:37:45 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.12 2002/07/22 20:23:19 petere Exp $
1313
*
1414
* DESCRIPTION
1515
* These routines take the parse tree and pick out the
@@ -31,6 +31,7 @@
3131
*/
3232
#include "postgres.h"
3333

34+
#include "access/genam.h"
3435
#include "access/heapam.h"
3536
#include "catalog/catname.h"
3637
#include "catalog/dependency.h"
@@ -693,7 +694,7 @@ CreateCast(CreateCastStmt *stmt)
693694
if (procstruct->proisagg)
694695
elog(ERROR, "cast function must not be an aggregate function");
695696
if (procstruct->proretset)
696-
elog(ERROR, "cast function must be not return a set");
697+
elog(ERROR, "cast function must not return a set");
697698

698699
ReleaseSysCache(tuple);
699700
}
@@ -727,7 +728,7 @@ CreateCast(CreateCastStmt *stmt)
727728
CatalogCloseIndices(Num_pg_cast_indices, idescs);
728729
}
729730

730-
myself.classId = get_system_catalog_relid(CastRelationName);
731+
myself.classId = RelationGetRelid(relation);
731732
myself.objectId = HeapTupleGetOid(tuple);
732733
myself.objectSubId = 0;
733734

@@ -819,21 +820,25 @@ DropCast(DropCastStmt *stmt)
819820
void
820821
DropCastById(Oid castOid)
821822
{
822-
Relation relation;
823+
Relation relation,
824+
index;
823825
ScanKeyData scankey;
824-
HeapScanDesc scan;
826+
IndexScanDesc scan;
825827
HeapTuple tuple;
826828

827829
relation = heap_openr(CastRelationName, RowExclusiveLock);
830+
index = index_openr(CastOidIndex);
831+
828832
ScanKeyEntryInitialize(&scankey, 0x0,
829-
ObjectIdAttributeNumber, F_OIDEQ,
830-
ObjectIdGetDatum(castOid));
831-
scan = heap_beginscan(relation, SnapshotNow, 1, &scankey);
832-
tuple = heap_getnext(scan, ForwardScanDirection);
833+
1, F_OIDEQ, ObjectIdGetDatum(castOid));
834+
scan = index_beginscan(relation, index, SnapshotNow, 1, &scankey);
835+
tuple = index_getnext(scan, ForwardScanDirection);
833836
if (HeapTupleIsValid(tuple))
834837
simple_heap_delete(relation, &tuple->t_self);
835838
else
836839
elog(ERROR, "could not find tuple for cast %u", castOid);
837-
heap_endscan(scan);
840+
index_endscan(scan);
841+
842+
index_close(index);
838843
heap_close(relation, RowExclusiveLock);
839844
}

src/include/catalog/indexing.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: indexing.h,v 1.71 2002/07/18 23:11:30 petere Exp $
11+
* $Id: indexing.h,v 1.72 2002/07/22 20:23:19 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -26,7 +26,7 @@
2626
#define Num_pg_amproc_indices 1
2727
#define Num_pg_attr_indices 2
2828
#define Num_pg_attrdef_indices 2
29-
#define Num_pg_cast_indices 1
29+
#define Num_pg_cast_indices 2
3030
#define Num_pg_class_indices 2
3131
#define Num_pg_constraint_indices 3
3232
#define Num_pg_conversion_indices 3
@@ -61,6 +61,7 @@
6161
#define AttrDefaultOidIndex "pg_attrdef_oid_index"
6262
#define AttributeRelidNameIndex "pg_attribute_relid_attnam_index"
6363
#define AttributeRelidNumIndex "pg_attribute_relid_attnum_index"
64+
#define CastOidIndex "pg_cast_oid_index"
6465
#define CastSourceTargetIndex "pg_cast_source_target_index"
6566
#define ClassNameNspIndex "pg_class_relname_nsp_index"
6667
#define ClassOidIndex "pg_class_oid_index"
@@ -169,6 +170,7 @@ DECLARE_UNIQUE_INDEX(pg_attrdef_adrelid_adnum_index on pg_attrdef using btree(ad
169170
DECLARE_UNIQUE_INDEX(pg_attrdef_oid_index on pg_attrdef using btree(oid oid_ops));
170171
DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnam_index on pg_attribute using btree(attrelid oid_ops, attname name_ops));
171172
DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnum_index on pg_attribute using btree(attrelid oid_ops, attnum int2_ops));
173+
DECLARE_UNIQUE_INDEX(pg_cast_oid_index on pg_cast using btree(oid oid_ops));
172174
DECLARE_UNIQUE_INDEX(pg_cast_source_target_index on pg_cast using btree(castsource oid_ops, casttarget oid_ops));
173175
DECLARE_UNIQUE_INDEX(pg_class_oid_index on pg_class using btree(oid oid_ops));
174176
DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index on pg_class using btree(relname name_ops, relnamespace oid_ops));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy