5.9.1. Caveats

5.9.1. Caveats
5.9.1.注意事项
Note that not all SQL commands are able to work on inheritance hierarchies. Commands that are used  for data querying, data modification, or schema modification (e.g., SELECT , UPDATE , DELETE , most  variants of ALTER TABLE , but not INSERT or ALTER TABLE ... RENAME ) typically default  to including child tables and support the ONLY notation to exclude them. Commands that do database  maintenance and tuning (e.g., REINDEX , VACUUM ) typically only work on individual, physical tables  and do not support recursing over inheritance hierarchies. The respective behavior of each individual  command is documented in its reference page (SQL Commands).
注意,并不是所有的SQL命令都可以用在继承层次上。一般用于数据查询、数据更改或者模式修改的命令(例如SELECT,UPDATE,DELETE,ALTER TABLE的大多数语法,但不包含INSERT或者ALTER TABLE ... RENAME)在执行时默认包含子表,且支持ONLY语法。用于数据库维护和调优的命令(例如REINDEX,VACUUM)通常仅对单独的物理表有效,且不支持继承层次的递归。各自命令的用法在引用页上进行了介绍( SQL命令)。
 
A serious limitation of the inheritance feature is that indexes (including unique constraints) and foreign  key constraints only apply to single tables, not to their inheritance children. This is true on both the  referencing and referenced sides of a foreign key constraint. Thus, in the terms of the above example:
• If we declared cities . name to be UNIQUE or a PRIMARY KEY , this would not stop the capitals  table from having rows with names duplicating rows in cities . And those duplicate rows  would by default show up in queries from cities . In fact, by default capitals would have no  unique constraint at all, and so could contain multiple rows with the same name. You could add a  unique constraint to capitals , but this would not prevent duplication compared to cities .
• Similarly, if we were to specify that cities . name REFERENCES some other table, this constraint  would not automatically propagate to capitals . In this case you could work around it by manually  adding the same REFERENCES constraint to capitals .
• Specifying that another table's column REFERENCES cities(name) would allow the other  table to contain city names, but not capital names. There is no good workaround for this case.
继承特性的一个限制是,索引(包含唯一约束)及外键约束仅适用于单一表,而不适用于它们的继承子表。这对于外键约束中的引用及被引用表均是如此。因此,就以上示例而言:
  • 如果在cities.name列上定义了唯一或主键,这并不能限制capitals表中出现于cities表中重复的行。而默认情况下,当查询时,重复行会返回cities表中所在行。实际上,默认capitals不会有唯一约束,那么也就会包含相同的重复行。也可以在capitals表上创建唯一约束,但这并不能防止出现与cities表中相同的行。
  • 同样,如果指定cities.name列引用其他表,但此约束对capitals表却是无效的。在此情形下,折中办法是,也为表capitals指定相同的引用约束。
  • 如果其他表的列引用了cities表的name列,那么引用表仅能包含城市表,却无法包含首府名称。此情形暂无比较好的解决办法。
 
These deficiencies will probably be fixed in some future release, but in the meantime considerable  care is needed in deciding whether inheritance is useful for your application.
以上限制可能会在新的版本中解决,但在此之前,继承对你的应用程序是否有用,还需慎重的考虑。

你可能感兴趣的:(PostgreSQL,11.2用户手册学习)