Add unique index on pg_cast.oid, and document pg_cast table.
authorPeter Eisentraut
Mon, 22 Jul 2002 20:23:19 +0000 (20:23 +0000)
committerPeter Eisentraut
Mon, 22 Jul 2002 20:23:19 +0000 (20:23 +0000)
doc/src/sgml/catalogs.sgml
src/backend/catalog/indexing.c
src/backend/commands/functioncmds.c
src/include/catalog/indexing.h

index 602680aaacb2019d3346bf62d50a2ac43935d657..ccb316e3c4ebecc6ca5ad2813ab56f38844731f9 100644 (file)
@@ -1,6 +1,6 @@
 
 
 
       table columns (attributesfields)
      
 
+     
+      pg_cast
+      casts (data type conversions)
+     
+
      
       pg_class
       tables, indexes, sequences (relations)
  
 
 
+  pg_cast
+
+  
+   pg_cast stores data type conversion paths
+   defined with CREATE CAST plus the built-in
+   conversions.
+  
+
+  
+   pg_cast Columns
+
+   
+    
+     
+      Name
+      Type
+      References
+      Description
+     
+    
+
+    
+     
+      castsource
+      oid
+      pg_type.oid
+      OID of the source data type
+     
+
+     
+      casttarget
+      oid
+      pg_type.oid
+      OID of the target data type
+     
+
+     
+      castfunc
+      oid
+      pg_proc.oid
+      
+       The OID of the function to use to perform this cast.  A 0 is
+       stored if the data types are binary compatible (that is, no
+       function is needed to perform the cast).
+      
+     
+
+     
+      castimplicit
+      bool
+      
+      Indication whether this cast can be invoked implicitly
+     
+    
+   
+  
+
  
   pg_class
 
index 80e3a15cf57a75295f2ffabe4d41f232b98cd8d2..928949d4343a821e380003b859b8ecbfb831226e 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.98 2002/07/18 23:11:27 petere Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.99 2002/07/22 20:23:19 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -44,7 +44,7 @@ char     *Name_pg_attr_indices[Num_pg_attr_indices] =
 char      *Name_pg_attrdef_indices[Num_pg_attrdef_indices] =
 {AttrDefaultIndex, AttrDefaultOidIndex};
 char      *Name_pg_cast_indices[Num_pg_cast_indices] =
-{CastSourceTargetIndex};
+{CastOidIndex, CastSourceTargetIndex};
 char      *Name_pg_class_indices[Num_pg_class_indices] =
 {ClassNameNspIndex, ClassOidIndex};
 char      *Name_pg_constraint_indices[Num_pg_constraint_indices] =
index 8717749b563fad4611b654fea4a60de997e8b72a..a445b7d0e7b39717ad651d0167daf4fe51b9c4d4 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.11 2002/07/20 05:37:45 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.12 2002/07/22 20:23:19 petere Exp $
  *
  * DESCRIPTION
  *   These routines take the parse tree and pick out the
@@ -31,6 +31,7 @@
  */
 #include "postgres.h"
 
+#include "access/genam.h"
 #include "access/heapam.h"
 #include "catalog/catname.h"
 #include "catalog/dependency.h"
@@ -693,7 +694,7 @@ CreateCast(CreateCastStmt *stmt)
        if (procstruct->proisagg)
            elog(ERROR, "cast function must not be an aggregate function");
        if (procstruct->proretset)
-           elog(ERROR, "cast function must be not return a set");
+           elog(ERROR, "cast function must not return a set");
 
        ReleaseSysCache(tuple);
    }
@@ -727,7 +728,7 @@ CreateCast(CreateCastStmt *stmt)
        CatalogCloseIndices(Num_pg_cast_indices, idescs);
    }
 
-   myself.classId = get_system_catalog_relid(CastRelationName);
+   myself.classId = RelationGetRelid(relation);
    myself.objectId = HeapTupleGetOid(tuple);
    myself.objectSubId = 0;
 
@@ -819,21 +820,25 @@ DropCast(DropCastStmt *stmt)
 void
 DropCastById(Oid castOid)
 {
-   Relation    relation;
+   Relation    relation,
+               index;
    ScanKeyData scankey;
-   HeapScanDesc scan;
+   IndexScanDesc scan;
    HeapTuple   tuple;
 
    relation = heap_openr(CastRelationName, RowExclusiveLock);
+   index = index_openr(CastOidIndex);
+
    ScanKeyEntryInitialize(&scankey, 0x0,
-                          ObjectIdAttributeNumber, F_OIDEQ,
-                          ObjectIdGetDatum(castOid));
-   scan = heap_beginscan(relation, SnapshotNow, 1, &scankey);
-   tuple = heap_getnext(scan, ForwardScanDirection);
+                          1, F_OIDEQ, ObjectIdGetDatum(castOid));
+   scan = index_beginscan(relation, index, SnapshotNow, 1, &scankey);
+   tuple = index_getnext(scan, ForwardScanDirection);
    if (HeapTupleIsValid(tuple))
        simple_heap_delete(relation, &tuple->t_self);
    else
        elog(ERROR, "could not find tuple for cast %u", castOid);
-   heap_endscan(scan);
+   index_endscan(scan);
+
+   index_close(index);
    heap_close(relation, RowExclusiveLock);
 }
index 777a4031dd79b14f52682588642b1eb6684c379d..db14ae6bd6829ac7f2ac4945b73d48b5b8d2bcc4 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: indexing.h,v 1.71 2002/07/18 23:11:30 petere Exp $
+ * $Id: indexing.h,v 1.72 2002/07/22 20:23:19 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -26,7 +26,7 @@
 #define Num_pg_amproc_indices      1
 #define Num_pg_attr_indices            2
 #define Num_pg_attrdef_indices     2
-#define Num_pg_cast_indices            1
+#define Num_pg_cast_indices            2
 #define Num_pg_class_indices       2
 #define Num_pg_constraint_indices  3
 #define Num_pg_conversion_indices  3
@@ -61,6 +61,7 @@
 #define AttrDefaultOidIndex            "pg_attrdef_oid_index"
 #define AttributeRelidNameIndex        "pg_attribute_relid_attnam_index"
 #define AttributeRelidNumIndex     "pg_attribute_relid_attnum_index"
+#define CastOidIndex               "pg_cast_oid_index"
 #define CastSourceTargetIndex      "pg_cast_source_target_index"
 #define ClassNameNspIndex          "pg_class_relname_nsp_index"
 #define ClassOidIndex              "pg_class_oid_index"
@@ -169,6 +170,7 @@ DECLARE_UNIQUE_INDEX(pg_attrdef_adrelid_adnum_index on pg_attrdef using btree(ad
 DECLARE_UNIQUE_INDEX(pg_attrdef_oid_index on pg_attrdef using btree(oid oid_ops));
 DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnam_index on pg_attribute using btree(attrelid oid_ops, attname name_ops));
 DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnum_index on pg_attribute using btree(attrelid oid_ops, attnum int2_ops));
+DECLARE_UNIQUE_INDEX(pg_cast_oid_index on pg_cast using btree(oid oid_ops));
 DECLARE_UNIQUE_INDEX(pg_cast_source_target_index on pg_cast using btree(castsource oid_ops, casttarget oid_ops));
 DECLARE_UNIQUE_INDEX(pg_class_oid_index on pg_class using btree(oid oid_ops));
 DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index on pg_class using btree(relname name_ops, relnamespace oid_ops));