@@ -27,18 +27,15 @@ ____________________________________________________________________________-->
27
27
<para>
28
28
The structures of the catalogs are declared in specially formatted C
29
29
header files in the <filename>src/include/catalog/</filename> directory of
30
- the source tree. In particular, for each catalog there is a header file
30
+ the source tree. For each catalog there is a header file
31
31
named after the catalog (e.g., <filename>pg_class.h</filename>
32
32
for <structname>pg_class</structname>), which defines the set of columns
33
33
the catalog has, as well as some other basic properties such as its OID.
34
- Other critical files defining the catalog structure
35
- include <filename>indexing.h</filename>, which defines the indexes present
36
- on all the system catalogs, and <filename>toasting.h</filename>, which
37
- defines TOAST tables for catalogs that need one.
38
34
</para>
39
35
____________________________________________________________________________-->
40
36
<para>
41
- 目录的结构声明在特殊格式的C头文件中,它们位于源码树的<filename>src/include/catalog/</filename>目录中。特别地,对每一个目录都有一个以其名称命名的头文件(例如,<structname>pg_class</structname>的头文件是<filename>pg_class.h</filename>),头文件定义了目录具有的列集合,以及一些其他的基本属性(例如OID)。其他定义目录结构的重要文件包括<filename>indexing.h</filename>和<filename>toasting.h</filename>,前者定义所有系统目录上的索引,而后者为需要TOAST表的目录定义TOAST表。
37
+ 目录的结构声明在特殊格式的C头文件中,它们位于源码树的<filename>src/include/catalog/</filename>目录中。
38
+ 对每一个目录都有一个以其名称命名的头文件(例如,<structname>pg_class</structname>的头文件是<filename>pg_class.h</filename>),头文件定义了目录具有的列集合,以及一些其他的基本属性(例如OID)。
42
39
</para>
43
40
44
41
<!--==========================orignal english content==========================
@@ -166,7 +163,8 @@ ____________________________________________________________________________-->
166
163
require all columns that should be non-nullable to be marked so
167
164
in <structname>pg_attribute</structname>. The bootstrap code will
168
165
automatically mark catalog columns as <literal>NOT NULL</literal>
169
- if they are fixed-width and are not preceded by any nullable column.
166
+ if they are fixed-width and are not preceded by any nullable or
167
+ variable-width column.
170
168
Where this rule is inadequate, you can force correct marking by using
171
169
<literal>BKI_FORCE_NOT_NULL</literal>
172
170
and <literal>BKI_FORCE_NULL</literal> annotations as needed.
@@ -177,7 +175,7 @@ ____________________________________________________________________________-->
177
175
通过将它们包裹在<literal>#ifdef CATALOG_VARLEN</literal> ... <literal>#endif</literal>(其中<literal>CATALOG_VARLEN</literal>是一个永不被定义的符号)中可以实现这一点。
178
176
这能防止C代码不小心尝试访问可能不在那里或者可能在其他某个偏移位置的域。
179
177
作为一种防止创建不正确行的措施,我们要求所有应该为非空的列在<structname>pg_attribute</structname>中也被标记为非空。
180
- 如果目录列是定长的并且前面没有任何可以为空的列 ,bootstrap代码将自动把它标记为<literal>NOT NULL</literal>。
178
+ 如果目录列是定长的并且前面没有任何可以为空或可变宽度的列 ,bootstrap代码将自动把它标记为<literal>NOT NULL</literal>。
181
179
在这一规则不适用的地方,可以根据需要使用<literal>BKI_FORCE_NOT_NULL</literal>和<literal>BKI_FORCE_NULL</literal>标注强制正确的标记。
182
180
</para>
183
181
@@ -714,15 +712,22 @@ ____________________________________________________________________________-->
714
712
<listitem>
715
713
<!--==========================orignal english content==========================
716
714
<para>
717
- In such a column, all entries must use the symbolic format except
718
- when writing <literal>0</literal> for InvalidOid. (If the column is
715
+ In some catalog columns, it's allowed for entries to be zero instead
716
+ of a valid reference. If this is allowed, write
717
+ <literal>BKI_LOOKUP_OPT</literal> instead
718
+ of <literal>BKI_LOOKUP</literal>. Then you can
719
+ write <literal>0</literal> for an entry. (If the column is
719
720
declared <type>regproc</type>, you can optionally
720
721
write <literal>-</literal> instead of <literal>0</literal>.)
722
+ Except for this special case, all entries in
723
+ a <literal>BKI_LOOKUP</literal> column must be symbolic references.
721
724
<filename>genbki.pl</filename> will warn about unrecognized names.
722
725
</para>
723
726
____________________________________________________________________________-->
724
727
<para>
725
- 在这样的一个列中,所有的项必须使用符号化格式,不过写成<literal>0</literal>(表示InvalidOid)除外(如果列被声明为<type>regproc</type>,可以选择用<literal>-</literal>代替<literal>0</literal>)。对于无法识别的名称,<filename>genbki.pl</filename>将会告警。
728
+ 在一些目录列,允许条目为零而不是有效的引用。如果这是允许的,写<literal>BKI_LOOKUP_OPT</literal>而不是<literal>BKI_LOOKUP</literal>。
729
+ 然后你能对一个条目写<literal>0</literal> 。(如果列为<type>regproc</type>声明,你可以有选择的写<literal>-</literal>而不是<literal>0</literal>。)
730
+ 除了这种特殊情况外,<literal>BKI_LOOKUP</literal>列中的所有条目都必须是符号引用。<filename>genbki.pl</filename>将会警告无法识别的名称。
726
731
</para>
727
732
</listitem>
728
733
@@ -805,22 +810,6 @@ ____________________________________________________________________________-->
805
810
</para>
806
811
</listitem>
807
812
808
- <listitem>
809
- <!--==========================orignal english content==========================
810
- <para>
811
- In addition to the generic lookup mechanisms, there is a special
812
- convention that <literal>PGNSP</literal> is replaced by the OID of
813
- the <literal>pg_catalog</literal> schema,
814
- and <literal>PGUID</literal> is replaced by the OID of the bootstrap
815
- superuser role. These usages are somewhat historical but so far
816
- there hasn't been a need to generalize them.
817
- </para>
818
- ____________________________________________________________________________-->
819
- <para>
820
- 除了通用的查找机制外,还有一个特殊约定,即<literal>PGNSP</literal>用<literal>pg_catalog</literal>模式的OID代替,而<literal>PGUID</literal>用自举超级用户角色的OID取代。这些用法有历史性,但到目前为止没有必要普及他们。
821
- </para>
822
- </listitem>
823
-
824
813
</itemizedlist>
825
814
826
815
<!--==========================orignal english content==========================
@@ -834,6 +823,30 @@ ____________________________________________________________________________-->
834
823
<para>
835
824
<filename>genbki.pl</filename>在运行时会解决所有符号化引用并且把简单的数字OID放到输出的BKI文件中。因此不需要bootstrap后端处理符号化引用。
836
825
</para>
826
+
827
+ <!--==========================orignal english content==========================
828
+ <para>
829
+ It's desirable to mark OID reference columns
830
+ with <literal>BKI_LOOKUP</literal> or <literal>BKI_LOOKUP_OPT</literal>
831
+ even if the catalog has no initial data that requires lookup. This
832
+ allows <filename>genbki.pl</filename> to record the foreign key
833
+ relationships that exist in the system catalogs. That information is
834
+ used in the regression tests to check for incorrect entries. See also
835
+ the macros <literal>DECLARE_FOREIGN_KEY</literal>,
836
+ <literal>DECLARE_FOREIGN_KEY_OPT</literal>,
837
+ <literal>DECLARE_ARRAY_FOREIGN_KEY</literal>,
838
+ and <literal>DECLARE_ARRAY_FOREIGN_KEY_OPT</literal>, which are
839
+ used to declare foreign key relationships that are too complex
840
+ for <literal>BKI_LOOKUP</literal> (typically, multi-column foreign
841
+ keys).
842
+ </para>
843
+ ____________________________________________________________________________-->
844
+ <para>
845
+ 将OID引用列标记为<literal>BKI_LOOKUP</literal>或<literal>BKI_LOOKUP_OPT</literal>是较为可取的,即使目录没有需要查找的初始数据。
846
+ 这允许<filename>genbki.pl</filename>记录已经存在系统目录中的外键的关系。这些信息在回归测试中用于检查不正确的条目。
847
+ 也可参见宏 <literal>DECLARE_FOREIGN_KEY</literal>,<literal>DECLARE_FOREIGN_KEY_OPT</literal>,<literal>DECLARE_ARRAY_FOREIGN_KEY</literal>,
848
+ 和 <literal>DECLARE_ARRAY_FOREIGN_KEY_OPT</literal>,用于声明<literal>BKI_LOOKUP</literal>过于复杂的外键关系(通常是,多列外键)。
849
+ </para>
837
850
</sect2>
838
851
839
852
<sect2 id="system-catalog-auto-array-types">
@@ -988,7 +1001,7 @@ ____________________________________________________________________________-->
988
1001
<filename>reformat_dat_file.pl</filename> can be adapted to perform
989
1002
many kinds of bulk changes. Look for its block comments showing where
990
1003
one-off code can be inserted. In the following example, we are going
991
- to consolidate two boolean fields in <structname>pg_proc</structname>
1004
+ to consolidate two Boolean fields in <structname>pg_proc</structname>
992
1005
into a char field:
993
1006
994
1007
<orderedlist>
@@ -1071,7 +1084,7 @@ $ perl rewrite_dat_with_prokind.pl pg_proc.dat
1071
1084
</para>
1072
1085
____________________________________________________________________________-->
1073
1086
<para>
1074
- 可以修改<filename>reformat_dat_file.pl</filename>执行很多种批量更改。寻找其中展示可以插入一次性代码的注释块。在下面的例子中,我们将把<structname>pg_proc</structname>中的两个boolean域联合成一个char域 :
1087
+ 可以修改<filename>reformat_dat_file.pl</filename>执行很多种批量更改。寻找其中展示可以插入一次性代码的注释块。在下面的例子中,我们将把<structname>pg_proc</structname>中的两个Boolean域联合成一个char域 :
1075
1088
1076
1089
<orderedlist>
1077
1090
<listitem>
@@ -1171,12 +1184,14 @@ ____________________________________________________________________________-->
1171
1184
next token that syntactically cannot belong to the preceding
1172
1185
command starts a new one. (Usually you would put a new command on
1173
1186
a new line, for clarity.) Tokens can be certain key words, special
1174
- characters (parentheses, commas, etc.), numbers, or double-quoted
1175
- strings. Everything is case sensitive.
1187
+ characters (parentheses, commas, etc.), identifiers, numbers, or
1188
+ single-quoted strings. Everything is case sensitive.
1176
1189
</para>
1177
1190
____________________________________________________________________________-->
1178
1191
<para>
1179
- <acronym>BKI</acronym>输入由一个命令序列组成。根据命令的语法,命令由一系列记号构成。记号之间通常由空白分隔,但是在没有歧义时也可不用。没有什么特殊的命令分隔符;语法上无法属于前一命令的记号将开始新的一条命令(通常你会把一个新命令放在一个新行上以保持清晰)。 记号可以是某些关键字、特殊字符(圆括弧,逗号等)、数字或者双引号字串。 所有东西都是大小写敏感的。
1192
+ <acronym>BKI</acronym>输入由一个命令序列组成。根据命令的语法,命令由一系列记号构成。记号之间通常由空白分隔,但是在没有歧义时也可不用。
1193
+ 没有什么特殊的命令分隔符;语法上无法属于前一命令的记号将开始新的一条命令(通常你会把一个新命令放在一个新行上以保持清晰)。
1194
+ 记号可以是某些关键字、特殊字符(圆括弧,逗号等)、标识符、数字或者单引号字串。 所有东西都是大小写敏感的。
1180
1195
</para>
1181
1196
1182
1197
<!--==========================orignal english content==========================
@@ -1375,11 +1390,14 @@ ____________________________________________________________________________-->
1375
1390
<para>
1376
1391
NULL values can be specified using the special key word
1377
1392
<literal>_null_</literal>. Values that do not look like
1378
- identifiers or digit strings must be double quoted.
1393
+ identifiers or digit strings must be single-quoted.
1394
+ (To include a single quote in a value, write it twice.
1395
+ Escape-string-style backslash escapes are allowed in the string, too.)
1379
1396
</para>
1380
1397
____________________________________________________________________________-->
1381
1398
<para>
1382
- NULL 可以用特殊的关键字<literal>_null_</literal>指定。看起来不像标识符或者数字字符串的值必须被加上双引号。
1399
+ NULL 可以用特殊的关键字<literal>_null_</literal>指定。看起来不像标识符或者数字字符串的值必须被加上单引号。
1400
+ (要在一个值中包含单引号,将其写两次。转义字符串风格的反斜杠转义在字符串中也是允许的。)
1383
1401
</para>
1384
1402
</listitem>
1385
1403
</varlistentry>
@@ -1671,7 +1689,7 @@ ____________________________________________________________________________-->
1671
1689
<programlisting>
1672
1690
create test_table 420 (oid = oid, cola = int4, colb = text)
1673
1691
open test_table
1674
- insert ( 421 1 "value1" )
1692
+ insert ( 421 1 'value 1' )
1675
1693
insert ( 422 2 _null_ )
1676
1694
close test_table
1677
1695
</programlisting>
@@ -1682,7 +1700,7 @@ ____________________________________________________________________________-->
1682
1700
<programlisting>
1683
1701
create test_table 420 (oid = oid, cola = int4, colb = text)
1684
1702
open test_table
1685
- insert ( 421 1 "value1" )
1703
+ insert ( 421 1 'value 1' )
1686
1704
insert ( 422 2 _null_ )
1687
1705
close test_table
1688
1706
</programlisting>
0 commit comments