Skip to content

Commit 3b2af2e

Browse files
committed
Update bki.sgml
1 parent c789c00 commit 3b2af2e

File tree

1 file changed

+54
-36
lines changed

1 file changed

+54
-36
lines changed

postgresql/doc/src/sgml/bki.sgml

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@ ____________________________________________________________________________-->
2727
<para>
2828
The structures of the catalogs are declared in specially formatted C
2929
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
3131
named after the catalog (e.g., <filename>pg_class.h</filename>
3232
for <structname>pg_class</structname>), which defines the set of columns
3333
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.
3834
</para>
3935
____________________________________________________________________________-->
4036
<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)。
4239
</para>
4340

4441
<!--==========================orignal english content==========================
@@ -166,7 +163,8 @@ ____________________________________________________________________________-->
166163
require all columns that should be non-nullable to be marked so
167164
in <structname>pg_attribute</structname>. The bootstrap code will
168165
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.
170168
Where this rule is inadequate, you can force correct marking by using
171169
<literal>BKI_FORCE_NOT_NULL</literal>
172170
and <literal>BKI_FORCE_NULL</literal> annotations as needed.
@@ -177,7 +175,7 @@ ____________________________________________________________________________-->
177175
通过将它们包裹在<literal>#ifdef CATALOG_VARLEN</literal> ... <literal>#endif</literal>(其中<literal>CATALOG_VARLEN</literal>是一个永不被定义的符号)中可以实现这一点。
178176
这能防止C代码不小心尝试访问可能不在那里或者可能在其他某个偏移位置的域。
179177
作为一种防止创建不正确行的措施,我们要求所有应该为非空的列在<structname>pg_attribute</structname>中也被标记为非空。
180-
如果目录列是定长的并且前面没有任何可以为空的列,bootstrap代码将自动把它标记为<literal>NOT NULL</literal>。
178+
如果目录列是定长的并且前面没有任何可以为空或可变宽度的列,bootstrap代码将自动把它标记为<literal>NOT NULL</literal>。
181179
在这一规则不适用的地方,可以根据需要使用<literal>BKI_FORCE_NOT_NULL</literal>和<literal>BKI_FORCE_NULL</literal>标注强制正确的标记。
182180
</para>
183181

@@ -714,15 +712,22 @@ ____________________________________________________________________________-->
714712
<listitem>
715713
<!--==========================orignal english content==========================
716714
<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
719720
declared <type>regproc</type>, you can optionally
720721
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.
721724
<filename>genbki.pl</filename> will warn about unrecognized names.
722725
</para>
723726
____________________________________________________________________________-->
724727
<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>将会警告无法识别的名称。
726731
</para>
727732
</listitem>
728733

@@ -805,22 +810,6 @@ ____________________________________________________________________________-->
805810
</para>
806811
</listitem>
807812

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-
824813
</itemizedlist>
825814

826815
<!--==========================orignal english content==========================
@@ -834,6 +823,30 @@ ____________________________________________________________________________-->
834823
<para>
835824
<filename>genbki.pl</filename>在运行时会解决所有符号化引用并且把简单的数字OID放到输出的BKI文件中。因此不需要bootstrap后端处理符号化引用。
836825
</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>
837850
</sect2>
838851

839852
<sect2 id="system-catalog-auto-array-types">
@@ -988,7 +1001,7 @@ ____________________________________________________________________________-->
9881001
<filename>reformat_dat_file.pl</filename> can be adapted to perform
9891002
many kinds of bulk changes. Look for its block comments showing where
9901003
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>
9921005
into a char field:
9931006

9941007
<orderedlist>
@@ -1071,7 +1084,7 @@ $ perl rewrite_dat_with_prokind.pl pg_proc.dat
10711084
</para>
10721085
____________________________________________________________________________-->
10731086
<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域
10751088

10761089
<orderedlist>
10771090
<listitem>
@@ -1171,12 +1184,14 @@ ____________________________________________________________________________-->
11711184
next token that syntactically cannot belong to the preceding
11721185
command starts a new one. (Usually you would put a new command on
11731186
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.
11761189
</para>
11771190
____________________________________________________________________________-->
11781191
<para>
1179-
<acronym>BKI</acronym>输入由一个命令序列组成。根据命令的语法,命令由一系列记号构成。记号之间通常由空白分隔,但是在没有歧义时也可不用。没有什么特殊的命令分隔符;语法上无法属于前一命令的记号将开始新的一条命令(通常你会把一个新命令放在一个新行上以保持清晰)。 记号可以是某些关键字、特殊字符(圆括弧,逗号等)、数字或者双引号字串。 所有东西都是大小写敏感的。
1192+
<acronym>BKI</acronym>输入由一个命令序列组成。根据命令的语法,命令由一系列记号构成。记号之间通常由空白分隔,但是在没有歧义时也可不用。
1193+
没有什么特殊的命令分隔符;语法上无法属于前一命令的记号将开始新的一条命令(通常你会把一个新命令放在一个新行上以保持清晰)。
1194+
记号可以是某些关键字、特殊字符(圆括弧,逗号等)、标识符、数字或者单引号字串。 所有东西都是大小写敏感的。
11801195
</para>
11811196

11821197
<!--==========================orignal english content==========================
@@ -1375,11 +1390,14 @@ ____________________________________________________________________________-->
13751390
<para>
13761391
NULL values can be specified using the special key word
13771392
<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.)
13791396
</para>
13801397
____________________________________________________________________________-->
13811398
<para>
1382-
NULL 可以用特殊的关键字<literal>_null_</literal>指定。看起来不像标识符或者数字字符串的值必须被加上双引号。
1399+
NULL 可以用特殊的关键字<literal>_null_</literal>指定。看起来不像标识符或者数字字符串的值必须被加上单引号。
1400+
(要在一个值中包含单引号,将其写两次。转义字符串风格的反斜杠转义在字符串中也是允许的。)
13831401
</para>
13841402
</listitem>
13851403
</varlistentry>
@@ -1671,7 +1689,7 @@ ____________________________________________________________________________-->
16711689
<programlisting>
16721690
create test_table 420 (oid = oid, cola = int4, colb = text)
16731691
open test_table
1674-
insert ( 421 1 "value1" )
1692+
insert ( 421 1 'value 1' )
16751693
insert ( 422 2 _null_ )
16761694
close test_table
16771695
</programlisting>
@@ -1682,7 +1700,7 @@ ____________________________________________________________________________-->
16821700
<programlisting>
16831701
create test_table 420 (oid = oid, cola = int4, colb = text)
16841702
open test_table
1685-
insert ( 421 1 "value1" )
1703+
insert ( 421 1 'value 1' )
16861704
insert ( 422 2 _null_ )
16871705
close test_table
16881706
</programlisting>

0 commit comments

Comments
 (0)