我在數據庫中有兩個表:tb_CampaignLead
和tb_Feed
。兩個表都有成千上萬的行,並且每個主鍵上都有一個索引。 tb_CampaignLead
擁有比tb_Feed
多20%的數據。對於SELECT *
,仍然tb_Feed
比tb_CampaignLead
慢6倍。誰能告訴我爲什麼tb_Feed
這麼慢。該表結構如下:數據庫表緩慢
CREATE TABLE [dbo].[tb_Feed](
[FeedID] [uniqueidentifier] NOT NULL,
[DateCreated] [smalldatetime] NULL,
[LeadSourceID] [int] NULL,
[RawLeadURL] [nvarchar](max) NULL,
[CostPerEnquiry] [money] NULL,
[ResultText] [nvarchar](max) NULL,
[SrcResultText] [nvarchar](max) NULL,
[SrcResult] [bit] NULL,
[Encrypted] [bit] NULL,
[ProductID] [int] NULL,
CONSTRAINT [PK_tb_Feed] PRIMARY KEY CLUSTERED
CREATE TABLE [dbo].[tb_CampaignLead](
[LeadID] [uniqueidentifier] NOT NULL,
[FeedID] [uniqueidentifier] NOT NULL,
[CampaignID] [int] NOT NULL,
[ProductID] [int] NOT NULL,
[CompanyID] [int] NOT NULL,
[LeadSourceID] [int] NOT NULL,
[DateCreated] [smalldatetime] NULL,
[LeadTextEmail] [nvarchar](max) NULL,
[LeadTextOther] [nvarchar](max) NULL,
[DateSent] [smalldatetime] NULL,
[EmailResponse] [nvarchar](max) NULL,
[OtherResponse] [nvarchar](max) NULL,
[EmailOK] [bit] NULL,
[OtherOK] [bit] NULL,
[ResultPass] [bit] NULL,
[L_Title] [nvarchar](50) NULL,
[L_Email] [nvarchar](100) NULL,
[L_Firstname] [nvarchar](max) NULL,
[L_Surname] [nvarchar](max) NULL,
[L_Address1] [nvarchar](max) NULL,
[L_Address2] [nvarchar](max) NULL,
[L_Address3] [nvarchar](max) NULL,
[L_TownCity] [nvarchar](max) NULL,
[L_AreaRegion] [nvarchar](max) NULL,
[L_Country] [nvarchar](max) NULL,
[L_PostCode] [nvarchar](50) NULL,
[L_Telephone1] [nvarchar](50) NULL,
[L_Telephone2] [nvarchar](50) NULL,
[L_DOB] [smalldatetime] NULL,
[L_Extra1] [nvarchar](max) NULL,
[L_Extra2] [nvarchar](max) NULL,
[L_Extra3] [nvarchar](max) NULL,
[L_Extra4] [nvarchar](max) NULL,
[L_Extra5] [nvarchar](max) NULL,
[L_Extra6] [nvarchar](max) NULL,
[L_Extra7] [nvarchar](max) NULL,
[L_Extra8] [nvarchar](max) NULL,
[L_Extra9] [nvarchar](max) NULL,
[L_Extra10] [nvarchar](max) NULL,
[L_Extra11] [nvarchar](max) NULL,
[L_Extra12] [nvarchar](max) NULL,
[L_Extra13] [nvarchar](max) NULL,
[L_Extra14] [nvarchar](max) NULL,
[L_Extra15] [nvarchar](max) NULL,
[L_Extra16] [nvarchar](max) NULL,
[L_Extra17] [nvarchar](max) NULL,
[L_Extra18] [nvarchar](max) NULL,
[L_Extra19] [nvarchar](max) NULL,
[L_Extra20] [nvarchar](max) NULL,
[SourceCost] [money] NULL,
[CampaignCost] [money] NULL,
[DeliveredPass] [bit] NULL,
[FieldReqBWAND] [int] NULL,
[FieldSuppliedBWAND] [int] NULL,
[FilterBWAND] [int] NULL,
[FilterPassBWAND] [int] NULL,
[OPFilterBWAND] [int] NULL,
[OPFilterPassBWAND] [int] NULL,
[ProcessBWAND] [int] NULL,
[ProcessPassBWAND] [int] NULL,
[L_MobileNetwork] [nvarchar](max) NULL,
[SrcResultPass] [bit] NULL,
CONSTRAINT [PK_tb_CampaignLead] PRIMARY KEY CLUSTERED
你需要給我們更多的信息。對於初學者來說,什麼RDBMS(看起來像SQL Server)?什麼是您的存儲配置? – squillman
首先,你如何在這兩個表上執行和測量'SELECT *'。明確描述你如何確定這一點。其次,這兩個表的行數和數據空間(不包括索引)是什麼?您可以通過右鍵單擊資源管理器窗格中的數據庫,然後選擇Reports ..Disk Usage by Table,在Management Studio(SSMS)中獲取表信息。查看「Data(KB)」列,並告訴我們這兩個表的含義。 – RBarryYoung
@squillman是的,我正在使用SQL Server 2008 R2。你能解釋一下你的存儲配置是什麼意思嗎? – user2478704