多表联合查询,怎么提高查询性能。

dys_198102 2010-01-27 06:24:53
SELECT dbo.order_detail.doc_no, dbo.Product_Master.Model, dbo.Product_Master.Color,
dbo.order_detail.qty * dbo.order_detail.unit_price AS total_price,
dbo.Product_Master.description, dbo.Product_Master.stop_date,
dbo.workflow_detail.Result, dbo.workflow_detail.wf_no, dbo.So_Master.so_no,
dbo.So_Master.customer_code, dbo.So_Master.customer_name,
dbo.So_Master.so_date, dbo.So_Master.sales, dbo.order_detail.unit_price,
dbo.So_Master.trans_fee, dbo.So_Master.ignore, dbo.So_Master.financial,
dbo.So_Master.payment1, dbo.So_Master.cartage, dbo.So_Master.curr,
dbo.So_Master.tax, dbo.So_Master.TOTALAMOUNT
FROM dbo.Customer_Master INNER JOIN
dbo.So_Master ON
dbo.Customer_Master.customer_code = dbo.So_Master.customer_code INNER JOIN
dbo.workflow_master INNER JOIN
dbo.workflow_detail ON
dbo.workflow_master.wf_no = dbo.workflow_detail.wf_no INNER JOIN
dbo.Product_Master INNER JOIN
dbo.order_detail ON dbo.Product_Master.Part_no = dbo.order_detail.part_no ON
dbo.workflow_master.doc_no = dbo.order_detail.doc_no ON
dbo.So_Master.so_no = dbo.order_detail.doc_no
这是我做的最基本的查询,求高手指点,提高其查询性能
...全文
443 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
dys_198102 2010-01-28
  • 打赏
  • 举报
回复
还没用过索引,常用的多表联合查询的sql语句:
select table1.ID from table1 inner join table2 on table1.ID=table2.ID
where table2.col2='xxx'

改进后:
select a.ID from table1 a,
(select col1,ID from table2 where col2='xxx') b
where a.ID=b.ID
看看这个怎么按这个优化
林三一 2010-01-28
  • 打赏
  • 举报
回复
1. 为连接字段添加索引
2. 注意表连接的先后顺序

支持
wuzhicheng5 2010-01-28
  • 打赏
  • 举报
回复
1. 为连接字段添加索引
2. 注意表连接的先后顺序

支持
iStringTheory 2010-01-28
  • 打赏
  • 举报
回复
你可以在sqlserver里面查看下执行计划,根据执行计划来优化
qq254242213 2010-01-28
  • 打赏
  • 举报
回复
dui
zw_548498 2010-01-28
  • 打赏
  • 举报
回复
做个视图不是更好吗,
bychgh 2010-01-28
  • 打赏
  • 举报
回复
学习
dys_198102 2010-01-28
  • 打赏
  • 举报
回复
谁帮我优化一下,谢谢急啊。。。
wuyq11 2010-01-27
  • 打赏
  • 举报
回复
分区,设置相应的索引
建立主键
dys_198102 2010-01-27
  • 打赏
  • 举报
回复
if keyword <> "" then
SQLComm=SQLComm & " and (Scustomer_name like N'%" & keyword & "%' or so_no like '%" & keyword & "%')"
end if
if account <> "t" then
SQLComm = SQLComm & "and sales = '"& account &"' "
end if
if stype <> "t" then
SQLComm = SQLComm & "and Result='" & stype & "'"
end if
if Ignore_type = "N" then
SQLComm = SQLComm & " And ignore is null "
end if
if Financial_type = "N" then
SQLComm = SQLComm & " And financial is null "
end if
SQLComm = SQLComm & " Order By so_date Desc, so_no Desc"
if Request.Form <> "" then
set rsCate = DBConn.Execute(SQLComm)
else
set rsCate = DBConn.Execute("select so_no from [so_master] where 1 <> 1 ")
end if
我后面是有条件的。但还是很慢,大家帮忙把上边的sql优化一下
samuellei 2010-01-27
  • 打赏
  • 举报
回复
1. 为连接字段添加索引
2. 注意表连接的先后顺序
xiaogug01 2010-01-27
  • 打赏
  • 举报
回复
最好加个条件能快点吧。
波导终结者 2010-01-27
  • 打赏
  • 举报
回复
你不用where限定任何条件?那这样的话,这么多表笛卡尔乘积,不慢才怪。只用到需要的数据来join,可以大大提高效率。

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧