From ebdc735d57418e7c8a42bf61773e406a40e1bbae Mon Sep 17 00:00:00 2001 From: "Josh Innis (Warner Marketing Incorporated)" Date: Fri, 6 Oct 2023 16:21:26 -0700 Subject: [PATCH] Remove Unneeded Indices From TPCH MSSQL When Colstore is enabled, the non unique indices on the columns are not required. Removing them will imporve the load time of the TPCH load. --- src/mssqlserver/mssqlsolap.tcl | 102 +++++++++++++++------------------ 1 file changed, 45 insertions(+), 57 deletions(-) diff --git a/src/mssqlserver/mssqlsolap.tcl b/src/mssqlserver/mssqlsolap.tcl index 1c50dd89..71b2c879 100755 --- a/src/mssqlserver/mssqlsolap.tcl +++ b/src/mssqlserver/mssqlsolap.tcl @@ -119,33 +119,27 @@ proc CreateIndexes { odbc maxdop colstore bcp } { set sql(6) "create unique index supplier_pk on dbo.supplier(s_suppkey) with (maxdop=$maxdop)" set sql(7) "create index o_orderdate_ind on orders(o_orderdate) with (fillfactor=95, sort_in_tempdb=on, maxdop=$maxdop)" set sql(8) "create unique index orders_pk on dbo.orders(o_orderkey) with (fillfactor = 95, maxdop=$maxdop)" - set sql(9) "create index n_regionkey_ind on dbo.nation(n_regionkey) with (fillfactor=100, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(10) "create index ps_suppkey_ind on dbo.partsupp(ps_suppkey) with(fillfactor=100, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(11) "create index s_nationkey_ind on dbo.supplier(s_nationkey) with (fillfactor=100, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(12) "create index l_shipdate_ind on dbo.lineitem(l_shipdate) with (fillfactor=95, sort_in_tempdb=off, maxdop=$maxdop)" - set sql(13) "create index l_orderkey_ind on dbo.lineitem(l_orderkey) with ( fillfactor=95, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(14) "create index l_partkey_ind on dbo.lineitem(l_partkey) with (fillfactor=95, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(15) "alter table dbo.customer with nocheck add constraint customer_nation_fk foreign key(c_nationkey) references dbo.nation (n_nationkey)" - set sql(16) "alter table dbo.lineitem with nocheck add constraint lineitem_order_fk foreign key(l_orderkey) references dbo.orders (o_orderkey)" - set sql(17) "alter table dbo.lineitem with nocheck add constraint lineitem_partkey_fk foreign key (l_partkey) references dbo.part(p_partkey)" - set sql(18) "alter table dbo.lineitem with nocheck add constraint lineitem_suppkey_fk foreign key (l_suppkey) references dbo.supplier(s_suppkey)" - set sql(19) "alter table dbo.lineitem with nocheck add constraint lineitem_partsupp_fk foreign key(l_partkey,l_suppkey) references partsupp(ps_partkey, ps_suppkey)" - set sql(20) "alter table dbo.nation with nocheck add constraint nation_region_fk foreign key(n_regionkey) references dbo.region (r_regionkey)" - set sql(21) "alter table dbo.partsupp with nocheck add constraint partsupp_part_fk foreign key(ps_partkey) references dbo.part (p_partkey)" - set sql(22) "alter table dbo.partsupp with nocheck add constraint partsupp_supplier_fk foreign key(ps_suppkey) references dbo.supplier (s_suppkey)" - set sql(23) "alter table dbo.supplier with nocheck add constraint supplier_nation_fk foreign key(s_nationkey) references dbo.nation (n_nationkey)" - set sql(24) "alter table dbo.orders with nocheck add constraint order_customer_fk foreign key(o_custkey) references dbo.customer (c_custkey)" - set sql(25) "alter table dbo.customer check constraint customer_nation_fk" - set sql(26) "alter table dbo.lineitem check constraint lineitem_order_fk" - set sql(27) "alter table dbo.lineitem check constraint lineitem_partkey_fk" - set sql(28) "alter table dbo.lineitem check constraint lineitem_suppkey_fk" - set sql(29) "alter table dbo.lineitem check constraint lineitem_partsupp_fk" - set sql(30) "alter table dbo.nation check constraint nation_region_fk" - set sql(31) "alter table dbo.partsupp check constraint partsupp_part_fk" - set sql(32) "alter table dbo.partsupp check constraint partsupp_part_fk" - set sql(33) "alter table dbo.supplier check constraint supplier_nation_fk" - set sql(34) "alter table dbo.orders check constraint order_customer_fk" - for { set i 1 } { $i <= 34 } { incr i } { + set sql(9) "alter table dbo.customer with nocheck add constraint customer_nation_fk foreign key(c_nationkey) references dbo.nation (n_nationkey)" + set sql(10) "alter table dbo.lineitem with nocheck add constraint lineitem_order_fk foreign key(l_orderkey) references dbo.orders (o_orderkey)" + set sql(12) "alter table dbo.lineitem with nocheck add constraint lineitem_partkey_fk foreign key (l_partkey) references dbo.part(p_partkey)" + set sql(13) "alter table dbo.lineitem with nocheck add constraint lineitem_suppkey_fk foreign key (l_suppkey) references dbo.supplier(s_suppkey)" + set sql(14) "alter table dbo.lineitem with nocheck add constraint lineitem_partsupp_fk foreign key(l_partkey,l_suppkey) references partsupp(ps_partkey, ps_suppkey)" + set sql(15) "alter table dbo.nation with nocheck add constraint nation_region_fk foreign key(n_regionkey) references dbo.region (r_regionkey)" + set sql(16) "alter table dbo.partsupp with nocheck add constraint partsupp_part_fk foreign key(ps_partkey) references dbo.part (p_partkey)" + set sql(17) "alter table dbo.partsupp with nocheck add constraint partsupp_supplier_fk foreign key(ps_suppkey) references dbo.supplier (s_suppkey)" + set sql(18) "alter table dbo.supplier with nocheck add constraint supplier_nation_fk foreign key(s_nationkey) references dbo.nation (n_nationkey)" + set sql(19) "alter table dbo.orders with nocheck add constraint order_customer_fk foreign key(o_custkey) references dbo.customer (c_custkey)" + set sql(20) "alter table dbo.customer check constraint customer_nation_fk" + set sql(21) "alter table dbo.lineitem check constraint lineitem_order_fk" + set sql(22) "alter table dbo.lineitem check constraint lineitem_partkey_fk" + set sql(23) "alter table dbo.lineitem check constraint lineitem_suppkey_fk" + set sql(24) "alter table dbo.lineitem check constraint lineitem_partsupp_fk" + set sql(25) "alter table dbo.nation check constraint nation_region_fk" + set sql(26) "alter table dbo.partsupp check constraint partsupp_part_fk" + set sql(27) "alter table dbo.partsupp check constraint partsupp_part_fk" + set sql(28) "alter table dbo.supplier check constraint supplier_nation_fk" + set sql(29) "alter table dbo.orders check constraint order_customer_fk" + for { set i 1 } { $i <= 29 } { incr i } { $odbc evaldirect $sql($i) } } elseif { $colstore } { @@ -162,36 +156,30 @@ proc CreateIndexes { odbc maxdop colstore bcp } { set sql(11) "create unique index part_pk on dbo.part(p_partkey) with (maxdop=$maxdop)" set sql(12) "create unique index region_pk on dbo.region(r_regionkey)" set sql(13) "create unique index supplier_pk on dbo.supplier(s_suppkey) with (maxdop=$maxdop)" - set sql(14) "create index l_shipdate_ind on dbo.lineitem(l_shipdate) with (fillfactor=95, sort_in_tempdb=off, maxdop=$maxdop)" - set sql(15) "create index o_orderdate_ind on orders(o_orderdate) with (fillfactor=95, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(16) "create index l_partkey_ind on dbo.lineitem(l_partkey) with (fillfactor=95, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(17) "create unique index partsupp_pk on dbo.partsupp(ps_partkey, ps_suppkey) with (maxdop=$maxdop)" - set sql(18) "create unique index orders_pk on dbo.orders(o_orderkey) with (fillfactor = 95, maxdop=$maxdop)" - set sql(19) "create index n_regionkey_ind on dbo.nation(n_regionkey) with (fillfactor=100, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(20) "create index ps_suppkey_ind on dbo.partsupp(ps_suppkey) with(fillfactor=100, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(21) "create index s_nationkey_ind on dbo.supplier(s_nationkey) with (fillfactor=100, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(22) "create index l_orderkey_ind on dbo.lineitem(l_orderkey) with ( fillfactor=95, sort_in_tempdb=on, maxdop=$maxdop)" - set sql(23) "alter table dbo.customer with nocheck add constraint customer_nation_fk foreign key(c_nationkey) references dbo.nation (n_nationkey)" - set sql(24) "alter table dbo.lineitem with nocheck add constraint lineitem_order_fk foreign key(l_orderkey) references dbo.orders (o_orderkey)" - set sql(25) "alter table dbo.lineitem with nocheck add constraint lineitem_partkey_fk foreign key (l_partkey) references dbo.part(p_partkey)" - set sql(26) "alter table dbo.lineitem with nocheck add constraint lineitem_suppkey_fk foreign key (l_suppkey) references dbo.supplier(s_suppkey)" - set sql(27) "alter table dbo.lineitem with nocheck add constraint lineitem_partsupp_fk foreign key(l_partkey,l_suppkey) references partsupp(ps_partkey, ps_suppkey)" - set sql(28) "alter table dbo.nation with nocheck add constraint nation_region_fk foreign key(n_regionkey) references dbo.region (r_regionkey)" - set sql(29) "alter table dbo.partsupp with nocheck add constraint partsupp_part_fk foreign key(ps_partkey) references dbo.part (p_partkey)" - set sql(30) "alter table dbo.partsupp with nocheck add constraint partsupp_supplier_fk foreign key(ps_suppkey) references dbo.supplier (s_suppkey)" - set sql(31) "alter table dbo.supplier with nocheck add constraint supplier_nation_fk foreign key(s_nationkey) references dbo.nation (n_nationkey)" - set sql(32) "alter table dbo.orders with nocheck add constraint order_customer_fk foreign key(o_custkey) references dbo.customer (c_custkey)" - set sql(33) "alter table dbo.customer check constraint customer_nation_fk" - set sql(34) "alter table dbo.lineitem check constraint lineitem_order_fk" - set sql(35) "alter table dbo.lineitem check constraint lineitem_partkey_fk" - set sql(36) "alter table dbo.lineitem check constraint lineitem_suppkey_fk" - set sql(37) "alter table dbo.lineitem check constraint lineitem_partsupp_fk" - set sql(38) "alter table dbo.nation check constraint nation_region_fk" - set sql(39) "alter table dbo.partsupp check constraint partsupp_part_fk" - set sql(40) "alter table dbo.partsupp check constraint partsupp_part_fk" - set sql(41) "alter table dbo.supplier check constraint supplier_nation_fk" - set sql(42) "alter table dbo.orders check constraint order_customer_fk" - for { set i 1 } { $i <= 42 } { incr i } { + set sql(14) "create index o_orderdate_ind on orders(o_orderdate) with (fillfactor=95, sort_in_tempdb=on, maxdop=$maxdop)" + set sql(15) "create unique index partsupp_pk on dbo.partsupp(ps_partkey, ps_suppkey) with (maxdop=$maxdop)" + set sql(16) "create unique index orders_pk on dbo.orders(o_orderkey) with (fillfactor = 95, maxdop=$maxdop)" + set sql(17) "alter table dbo.customer with nocheck add constraint customer_nation_fk foreign key(c_nationkey) references dbo.nation (n_nationkey)" + set sql(18) "alter table dbo.lineitem with nocheck add constraint lineitem_order_fk foreign key(l_orderkey) references dbo.orders (o_orderkey)" + set sql(19) "alter table dbo.lineitem with nocheck add constraint lineitem_partkey_fk foreign key (l_partkey) references dbo.part(p_partkey)" + set sql(20) "alter table dbo.lineitem with nocheck add constraint lineitem_suppkey_fk foreign key (l_suppkey) references dbo.supplier(s_suppkey)" + set sql(21) "alter table dbo.lineitem with nocheck add constraint lineitem_partsupp_fk foreign key(l_partkey,l_suppkey) references partsupp(ps_partkey, ps_suppkey)" + set sql(22) "alter table dbo.nation with nocheck add constraint nation_region_fk foreign key(n_regionkey) references dbo.region (r_regionkey)" + set sql(23) "alter table dbo.partsupp with nocheck add constraint partsupp_part_fk foreign key(ps_partkey) references dbo.part (p_partkey)" + set sql(24) "alter table dbo.partsupp with nocheck add constraint partsupp_supplier_fk foreign key(ps_suppkey) references dbo.supplier (s_suppkey)" + set sql(25) "alter table dbo.supplier with nocheck add constraint supplier_nation_fk foreign key(s_nationkey) references dbo.nation (n_nationkey)" + set sql(26) "alter table dbo.orders with nocheck add constraint order_customer_fk foreign key(o_custkey) references dbo.customer (c_custkey)" + set sql(27) "alter table dbo.customer check constraint customer_nation_fk" + set sql(28) "alter table dbo.lineitem check constraint lineitem_order_fk" + set sql(29) "alter table dbo.lineitem check constraint lineitem_partkey_fk" + set sql(30) "alter table dbo.lineitem check constraint lineitem_suppkey_fk" + set sql(31) "alter table dbo.lineitem check constraint lineitem_partsupp_fk" + set sql(32) "alter table dbo.nation check constraint nation_region_fk" + set sql(33) "alter table dbo.partsupp check constraint partsupp_part_fk" + set sql(34) "alter table dbo.partsupp check constraint partsupp_part_fk" + set sql(35) "alter table dbo.supplier check constraint supplier_nation_fk" + set sql(36) "alter table dbo.orders check constraint order_customer_fk" + for { set i 1 } { $i <= 36 } { incr i } { $odbc evaldirect $sql($i) } } else {