为什么Netezza没有“强制执行”外键约束,尽管它具有外键的概念?不执行约束的优点是什么?
答案 0 :(得分:6)
Foreign Keys
来帮助构建最有效的查询计划,同时估算查询的成本。使用Foreign / Primary Keys
来利用包括Microsoft Visio在内的许多数据库可视化工具也很重要。不强制执行约束的优点是速度。 Netezza能够通过不维护此功能来挤出额外的性能。
答案 1 :(得分:0)
测试Netezza SQL:FOREIGN KEY子句
------------------------------------------------------------------
/*
NOTICE: foreign key constraints not enforced <-- Netezza SQL Parser complains here
*/
/* Start time 4/25/2013 6:21:32 PM, end time 4/25/2013 6:21:32 PM. */
/* Duration 0.078125 sec. */
CREATE TABLE table2ref
(
col1 smallint NOT NULL
,colref2 smallint
,col3 varchar(30 )
,CONSTRAINT fk_column_colref2 <-- THIS IS REF CONSTRAINT
FOREIGN KEY (colref2)
REFERENCES test2delete (col1) <-- the ref table must already be created
);
/* Start time 4/25/2013 6:21:32 PM, end time 4/25/2013 6:21:37 PM. */
/* Duration 4.53125 sec. */ <-- Observe how long the INSERT takes
/* Records Affected: 1. */
insert into table2ref values (3,12345,'reftabstring'); <-- THIS IS NON-EXISTING KEY "12345"
/* Start time 4/25/2013 6:21:37 PM, end time 4/25/2013 6:21:39 PM. */
/* Duration 2.65625 sec. */ <-- Observe how long the INSERT takes
/* Records Affected: 1. */
insert into table2ref values (3,12345,'reftabstring');