diff --git a/pkg/workload/tpcc/tpcc.go b/pkg/workload/tpcc/tpcc.go index 0c7d944022d4..6c8ac5e92a43 100644 --- a/pkg/workload/tpcc/tpcc.go +++ b/pkg/workload/tpcc/tpcc.go @@ -230,17 +230,24 @@ func (w *tpcc) Hooks() workload.Hooks { }, PostLoad: func(db *gosql.DB) error { if w.fks { + // We avoid validating foreign keys because we just generated + // the data set and don't want to scan over the entire thing + // again. Unfortunately, this means that we leave the foreign + // keys unvalidated for the duration of the test, so the SQL + // optimizer can't use them. + // TODO(lucy-zhang): expose an internal knob to validate fk + // relations without performing full validation. See #38833. fkStmts := []string{ - `alter table district add foreign key (d_w_id) references warehouse (w_id)`, - `alter table customer add foreign key (c_w_id, c_d_id) references district (d_w_id, d_id)`, - `alter table history add foreign key (h_c_w_id, h_c_d_id, h_c_id) references customer (c_w_id, c_d_id, c_id)`, - `alter table history add foreign key (h_w_id, h_d_id) references district (d_w_id, d_id)`, - `alter table "order" add foreign key (o_w_id, o_d_id, o_c_id) references customer (c_w_id, c_d_id, c_id)`, - `alter table new_order add foreign key (no_w_id, no_d_id, no_o_id) references "order" (o_w_id, o_d_id, o_id)`, - `alter table stock add foreign key (s_w_id) references warehouse (w_id)`, - `alter table stock add foreign key (s_i_id) references item (i_id)`, - `alter table order_line add foreign key (ol_w_id, ol_d_id, ol_o_id) references "order" (o_w_id, o_d_id, o_id)`, - `alter table order_line add foreign key (ol_supply_w_id, ol_i_id) references stock (s_w_id, s_i_id)`, + `alter table district add foreign key (d_w_id) references warehouse (w_id) not valid`, + `alter table customer add foreign key (c_w_id, c_d_id) references district (d_w_id, d_id) not valid`, + `alter table history add foreign key (h_c_w_id, h_c_d_id, h_c_id) references customer (c_w_id, c_d_id, c_id) not valid`, + `alter table history add foreign key (h_w_id, h_d_id) references district (d_w_id, d_id) not valid`, + `alter table "order" add foreign key (o_w_id, o_d_id, o_c_id) references customer (c_w_id, c_d_id, c_id) not valid`, + `alter table new_order add foreign key (no_w_id, no_d_id, no_o_id) references "order" (o_w_id, o_d_id, o_id) not valid`, + `alter table stock add foreign key (s_w_id) references warehouse (w_id) not valid`, + `alter table stock add foreign key (s_i_id) references item (i_id) not valid`, + `alter table order_line add foreign key (ol_w_id, ol_d_id, ol_o_id) references "order" (o_w_id, o_d_id, o_id) not valid`, + `alter table order_line add foreign key (ol_supply_w_id, ol_i_id) references stock (s_w_id, s_i_id) not valid`, } for _, fkStmt := range fkStmts {