第二步:优化临时表 大多数临时表的使用是简单的,很少需要优化。但需要对临时表进行复杂的访问则、 应通过使用多个过程或批处理来把表的创建和索引分开。以下两种技术可以改善临时表的优化 1、在临时表上创建索引 1)临时表必须存在 2)统计页必须存在(即不能在空表上创建索引) 2、把对临时表的复杂的使用分散到多个批处理或过程中,以便为优化器提供信息 下面的这个过程需要进行优化: create proc base_proc as select into #huge_result from auths select from article, #huge_result where article.author_code= #huge_result.author_code and sex=”0”
使用两个过程可以得到更好的性能 1) create proc base_proc as select into #huge_result from auths exec select_proc
2) create proc select_proc as select from article,#huge_result where article.author_code=#huge_result.author_code and sex=”0”