8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.223 2006/07/31 20:09:00 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.224 2006/08/15 22:36:17 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -590,6 +590,7 @@ boot_openrel(char *relname)
590
590
591
591
if (Typ == NULL )
592
592
{
593
+ /* We can now load the pg_type data */
593
594
rel = heap_open (TypeRelationId , NoLock );
594
595
scan = heap_beginscan (rel , SnapshotNow , 0 , NULL );
595
596
i = 0 ;
@@ -806,6 +807,10 @@ void
806
807
InsertOneValue (char * value , int i )
807
808
{
808
809
Oid typoid ;
810
+ int16 typlen ;
811
+ bool typbyval ;
812
+ char typalign ;
813
+ char typdelim ;
809
814
Oid typioparam ;
810
815
Oid typinput ;
811
816
Oid typoutput ;
@@ -817,52 +822,19 @@ InsertOneValue(char *value, int i)
817
822
818
823
if (Typ != NULL )
819
824
{
820
- struct typmap * * app ;
821
- struct typmap * ap ;
822
-
823
- elog (DEBUG5 , "Typ != NULL" );
824
825
typoid = boot_reldesc -> rd_att -> attrs [i ]-> atttypid ;
825
- app = Typ ;
826
- while (* app && (* app )-> am_oid != typoid )
827
- ++ app ;
828
- ap = * app ;
829
- if (ap == NULL )
830
- elog (ERROR , "could not find atttypid %u in Typ list" , typoid );
831
-
832
- /* XXX this logic should match getTypeIOParam() */
833
- if (OidIsValid (ap -> am_typ .typelem ))
834
- typioparam = ap -> am_typ .typelem ;
835
- else
836
- typioparam = typoid ;
837
-
838
- typinput = ap -> am_typ .typinput ;
839
- typoutput = ap -> am_typ .typoutput ;
840
826
}
841
827
else
842
828
{
843
- int typeindex ;
844
-
845
- /* XXX why is typoid determined differently in this path? */
829
+ /* XXX why is typoid determined differently in this case? */
846
830
typoid = attrtypes [i ]-> atttypid ;
847
- for (typeindex = 0 ; typeindex < n_types ; typeindex ++ )
848
- {
849
- if (TypInfo [typeindex ].oid == typoid )
850
- break ;
851
- }
852
- if (typeindex >= n_types )
853
- elog (ERROR , "type oid %u not found" , typoid );
854
- elog (DEBUG5 , "Typ == NULL, typeindex = %u" , typeindex );
855
-
856
- /* XXX this logic should match getTypeIOParam() */
857
- if (OidIsValid (TypInfo [typeindex ].elem ))
858
- typioparam = TypInfo [typeindex ].elem ;
859
- else
860
- typioparam = typoid ;
861
-
862
- typinput = TypInfo [typeindex ].inproc ;
863
- typoutput = TypInfo [typeindex ].outproc ;
864
831
}
865
832
833
+ boot_get_type_io_data (typoid ,
834
+ & typlen , & typbyval , & typalign ,
835
+ & typdelim , & typioparam ,
836
+ & typinput , & typoutput );
837
+
866
838
values [i ] = OidInputFunctionCall (typinput , value , typioparam , -1 );
867
839
prt = OidOutputFunctionCall (typoutput , values [i ]);
868
840
elog (DEBUG4 , "inserted -> %s" , prt );
@@ -972,6 +944,83 @@ gettype(char *type)
972
944
return 0 ;
973
945
}
974
946
947
+ /* ----------------
948
+ * boot_get_type_io_data
949
+ *
950
+ * Obtain type I/O information at bootstrap time. This intentionally has
951
+ * almost the same API as lsyscache.c's get_type_io_data, except that
952
+ * we only support obtaining the typinput and typoutput routines, not
953
+ * the binary I/O routines. It is exported so that array_in and array_out
954
+ * can be made to work during early bootstrap.
955
+ * ----------------
956
+ */
957
+ void
958
+ boot_get_type_io_data (Oid typid ,
959
+ int16 * typlen ,
960
+ bool * typbyval ,
961
+ char * typalign ,
962
+ char * typdelim ,
963
+ Oid * typioparam ,
964
+ Oid * typinput ,
965
+ Oid * typoutput )
966
+ {
967
+ if (Typ != NULL )
968
+ {
969
+ /* We have the boot-time contents of pg_type, so use it */
970
+ struct typmap * * app ;
971
+ struct typmap * ap ;
972
+
973
+ app = Typ ;
974
+ while (* app && (* app )-> am_oid != typid )
975
+ ++ app ;
976
+ ap = * app ;
977
+ if (ap == NULL )
978
+ elog (ERROR , "type OID %u not found in Typ list" , typid );
979
+
980
+ * typlen = ap -> am_typ .typlen ;
981
+ * typbyval = ap -> am_typ .typbyval ;
982
+ * typalign = ap -> am_typ .typalign ;
983
+ * typdelim = ap -> am_typ .typdelim ;
984
+
985
+ /* XXX this logic must match getTypeIOParam() */
986
+ if (OidIsValid (ap -> am_typ .typelem ))
987
+ * typioparam = ap -> am_typ .typelem ;
988
+ else
989
+ * typioparam = typid ;
990
+
991
+ * typinput = ap -> am_typ .typinput ;
992
+ * typoutput = ap -> am_typ .typoutput ;
993
+ }
994
+ else
995
+ {
996
+ /* We don't have pg_type yet, so use the hard-wired TypInfo array */
997
+ int typeindex ;
998
+
999
+ for (typeindex = 0 ; typeindex < n_types ; typeindex ++ )
1000
+ {
1001
+ if (TypInfo [typeindex ].oid == typid )
1002
+ break ;
1003
+ }
1004
+ if (typeindex >= n_types )
1005
+ elog (ERROR , "type OID %u not found in TypInfo" , typid );
1006
+
1007
+ * typlen = TypInfo [typeindex ].len ;
1008
+ * typbyval = TypInfo [typeindex ].byval ;
1009
+ * typalign = TypInfo [typeindex ].align ;
1010
+ /* We assume typdelim is ',' for all boot-time types */
1011
+ * typdelim = ',' ;
1012
+
1013
+ /* XXX this logic must match getTypeIOParam() */
1014
+ if (OidIsValid (TypInfo [typeindex ].elem ))
1015
+ * typioparam = TypInfo [typeindex ].elem ;
1016
+ else
1017
+ * typioparam = typid ;
1018
+
1019
+ * typinput = TypInfo [typeindex ].inproc ;
1020
+ * typoutput = TypInfo [typeindex ].outproc ;
1021
+ }
1022
+ }
1023
+
975
1024
/* ----------------
976
1025
* AllocateAttribute
977
1026
* ----------------
0 commit comments