当select
请求在我的应用中执行并且与insert
执行相同的表并行时,我得到 GenericADOException Timeout expired 异常。此表中有超过1000000个条目。我选择enteties来查看它们,同时新的enteties添加到DB。
会话打开,提交并以insert
确定关闭。
我有所有必要列的索引。我为他们做了reorganize
以防万一它没有帮助。
选择请求如下:
SELECT field1, field2, field3 ... FROM table WHERE fk = some_value
Fluent NHibernate发生异常,因为有时请求需要花费太多时间才能完成。这个错误时有发生,但真的很烦人。
我将IQueryable
用于select
。
在我的情况下,我还能如何提高表现?
实体查询:
INSERT INTO EVENT_LOG
(full_name, event_date, event, description, full_description_zipped, t_number)
VALUES (?, ?, ?, ?, ?, ?);
select SCOPE_IDENTITY()
select eventlogen0_.event_ID as event1_22_, eventlogen0_.full_name
as full2_22_, eventlogen0_.event_date as event3_22_, eventlogen0_.event as event22_,
eventlogen0_.description as descript5_22_, eventlogen0_.full_description_zipped as full6_22_,
eventlogen0_.t_number as t7_22_
from EVENT_LOG eventlogen0_
where eventlogen0_.t_number=?
order by eventlogen0_.event_ID desc
表的sql:
CREATE TABLE [dbo].[EVENT_LOG] (
[event_ID] INT IDENTITY (1, 1) NOT NULL,
[full_name] NVARCHAR (100) NULL,
[event_date] DATETIME CONSTRAINT [DF_EVENT_LOG_event_date] DEFAULT (getdate()) NOT NULL,
[event] NVARCHAR (150) NOT NULL,
[transaction_ID] UNIQUEIDENTIFIER NULL,
[description] NVARCHAR (4000) NULL,
[t_number] NVARCHAR (20) NULL,
[full_description_zipped] NVARCHAR(MAX) NULL,
CONSTRAINT [PK_EVENT_LOG] PRIMARY KEY CLUSTERED ([event_ID] ASC) WITH (FILLFACTOR = 90)
);
GO
CREATE NONCLUSTERED INDEX [NX_EVENT_LOG_T_NUMBER]
ON [dbo].[EVENT_LOG]([t_number] ASC)
INCLUDE ([event_ID]);
GO
CREATE NONCLUSTERED INDEX [NX_EVENT_LOG_EVENT_DATE]
ON [dbo].[EVENT_LOG]([event_date] ASC) WITH (FILLFACTOR = 90);
GO
CREATE NONCLUSTERED INDEX [NX_EVENT_LOG_EVENT]
ON [dbo].[EVENT_LOG]([event] ASC) WITH (FILLFACTOR = 90);
GO
CREATE NONCLUSTERED INDEX [IX_DATE_EVENT_TNUMBER]
ON [dbo].[EVENT_LOG]([event_date] ASC, [event] ASC, [t_number] ASC);
答案 0 :(得分:0)
1000000записейдостаточномного,когдаониотсылаютсяклиенту。 Учитывая,чтотаблицадостаточнотолстая(многополейбольшихразмеров),торекомендуюпростоувеличитьтайм-аутзапросаксерверувклиентскомкоде。 https://msdn.microsoft.com/ru-ru/library/system.data.sqlclient.sqlconnection.connectiontimeout(v=vs.110).aspx