查询耗时太长

时间:2016-02-03 07:35:06

标签: sql sql-server-2008 tsql optimization

我们的SQL数据库中有超过1亿条记录,我们正在尝试处理它们。我们有一个由供应商准备的脚本,但它花了太长时间。我不是程序员,但这看起来是一种非常低效的方法。有人可以帮忙吗?

我在ACCESS中编程了一点,但它看起来像嵌套的CONVERT,所有这些操作都在杀死系统。我们运行了8个小时,甚至没有处理所有记录的1%。

Create view Base_List as
SELECT
  Archive.dbo.Inum_location.inum,
  Archive.dbo.Media.name as media_name,
  Archive.dbo.Media.physical_device,
  Archive.dbo.Container.path,
  Archive.dbo.Container.length,
  CentralContact.dbo.Sessions_pd.p1_value,
  CentralContact.dbo.Sessions_pd.p2_value,
  CentralContact.dbo.Sessions_pd.p3_value,
  CentralContact.dbo.Sessions_pd.contact_id
FROM
          CentralContact.dbo.Sessions INNER JOIN
          Archive.dbo.Inum_location INNER JOIN
          Archive.dbo.Container ON Inum_location.container_id = Container.container_id ON CONVERT(bigint, CONVERT(varchar,
          CentralContact.dbo.Sessions.audio_module_no) + RIGHT('000000000' + CONVERT(varchar, CentralContact.dbo.Sessions.audio_ch_no), 9))
          = Inum_location.inum INNER JOIN
          CentralContact.dbo.Sessions_pd ON CentralContact.dbo.Sessions.dbs_id = CentralContact.dbo.Sessions_pd.dbs_id AND
          CentralContact.dbo.Sessions.sid = CentralContact.dbo.Sessions_pd.sid     INNER JOIN
              Archive.dbo.Media ON Inum_location.media_id = Media.media_id;

SELECT
  A1_CAP0_UCS.*,
  Base_List.*
FROM
  A2_CAP0_UCS
  LEFT OUTER JOIN Base_List ON
  A2_CAP0_UCS.[Column 3] = Base_List.p1_value;

0 个答案:

没有答案