编辑:我们正在移动服务器,我刚刚在新服务器上进行了测试。那里没有性能问题。这似乎归结为一个动力不足、组织不善的服务器。
昨晚我们的一个进程突然运行得很慢。缓慢的步骤被追踪到一个表上的更新语句,该表被承认不是太聪明地索引。
所以今天我已经为所有涉及的表添加了索引,但我的性能仍然很糟糕。我真的不明白——可能我还在做一些不太聪明的事情。欢迎任何建议。
更新如下:
update test_HDM_RTT
set patient_district_no = b.legacy_number
from test_HDM_RTT a
inner join PHD.migration.PatScope b
on a.patient_pas_no = b.TrustNumber
patscope 是 2474147 行,test_hdm_rtt 是 815278
表的定义:
CREATE TABLE [dbo].[test_HDM_RTT](
[pk_episode_id] [int] NULL,
[pk_event_id] [int] NOT NULL,
[activity_date] [datetime] NULL,
[activity_datetime] [datetime] NULL,
[activity_subtype1] [nvarchar](50) NULL,
[activity_subtype1_code] [nvarchar](50) NULL,
[activity_subtype2] [nvarchar](50) NULL,
[activity_subtype2_code] [nvarchar](50) NULL,
[activity_type] [nvarchar](50) NULL,
[activity_type_code] [nvarchar](50) NULL,
[clock_start_date] [datetime] NULL,
[clock_stop_date] [datetime] NULL,
[dir_code] [nvarchar](10) NULL,
[div_code] [nvarchar](10) NULL,
[episode_id_ext] [nvarchar](50) NULL,
[episode_id_appt] [nvarchar](50) NULL,
[episode_id_ref] [nvarchar](50) NULL,
[episode_id_ref_medway] [nvarchar](50) NULL,
[episode_id_wl] [nvarchar](50) NULL,
[erod] [datetime] NULL,
[nhs_number] [nvarchar](20) NULL,
[patient_id] [int] NULL,
[patient_district_no] [nvarchar](20) NULL,
[patient_pas_no] [nvarchar](50) NULL,
[pathway_id] [nvarchar](50) NULL,
[pct_code] [nvarchar](10) NULL,
[ref_source_code] [nvarchar](10) NULL,
[rtt_episode_id] [nvarchar](50) NULL,
[rtt_outcome_code] [nvarchar](50) NULL,
[rtt_outcome_desc] [nvarchar](50) NULL,
[rtt_start_date] [datetime] NULL,
[rtt_start_ind] [nvarchar](10) NULL,
[rtt_stop_date] [datetime] NULL,
[site_code] [nvarchar](10) NULL,
[spec_natcode] [nvarchar](10) NULL,
[spec_pascode] [nvarchar](10) NULL,
[transfer_text] [nvarchar](100) NULL,
[op_rtt_count] [int] NULL,
[app_rec_date] [datetime] NULL,
[cons_code] [varchar](10) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
USE [PIP]
/****** Object: Index [pk_event_id_clustered] Script Date: 03/06/2013 14:46:52 ******/
CREATE CLUSTERED INDEX [pk_event_id_clustered] ON [dbo].[test_HDM_RTT]
(
[pk_event_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
USE [PIP]
/****** Object: Index [idx_episode_id_appt] Script Date: 03/06/2013 14:46:52 ******/
CREATE NONCLUSTERED INDEX [idx_episode_id_appt] ON [dbo].[test_HDM_RTT]
(
[episode_id_appt] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
USE [PIP]
/****** Object: Index [idx_episode_id_ref] Script Date: 03/06/2013 14:46:52 ******/
CREATE NONCLUSTERED INDEX [idx_episode_id_ref] ON [dbo].[test_HDM_RTT]
(
[episode_id_ref] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
USE [PIP]
/****** Object: Index [idx_episode_id_wl] Script Date: 03/06/2013 14:46:52 ******/
CREATE NONCLUSTERED INDEX [idx_episode_id_wl] ON [dbo].[test_HDM_RTT]
(
[episode_id_wl] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
USE [PIP]
/****** Object: Index [patient_pas_no] Script Date: 03/06/2013 14:46:52 ******/
CREATE NONCLUSTERED INDEX [patient_pas_no] ON [dbo].[test_HDM_RTT]
(
[patient_pas_no] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
和
USE [PHD]
GO
/****** Object: Table [migration].[PatScope] Script Date: 03/06/2013 14:47:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [migration].[PatScope](
[RID] [varchar](7) NOT NULL,
[Number] [varchar](17) NOT NULL,
[TrustNumber] [varchar](10) NULL,
[NumberType] [nvarchar](10) NULL,
[legacy_number] [varchar](10) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
USE [PHD]
/****** Object: Index [TrustNoClustered] Script Date: 03/06/2013 14:47:57 ******/
CREATE CLUSTERED INDEX [TrustNoClustered] ON [migration].[PatScope]
(
[TrustNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
USE [PHD]
/****** Object: Index [TrustNo] Script Date: 03/06/2013 14:47:57 ******/
CREATE NONCLUSTERED INDEX [TrustNo] ON [migration].[PatScope]
(
[TrustNumber] ASC,
[Number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
USE [PHD]
/****** Object: Index [TrustNumber_legacy_lookup] Script Date: 03/06/2013 14:47:57 ******/
CREATE UNIQUE NONCLUSTERED INDEX [TrustNumber_legacy_lookup] ON [migration].[PatScope]
(
[TrustNumber] ASC,
[legacy_number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO