2014-02-11 198 views
1

爲什麼Netezza雖然具有外鍵的概念,但並不「強制」外鍵約束?不執行限制有什麼好處?Netezza外鍵約束

回答

4

Foreign Keys仍然被查詢優化器用來幫助構建最有效的查詢計劃,同時估計查詢的成本。使用Foreign/Primary Keys來利用許多數據庫可視化工具(包括Microsoft Visio)也很重要。不強制約束的優點是速度。 Netezza能夠通過不保留此功能來擠壓額外的性能。

Netezza Manual

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');