3
I’m doing a stress test on an app I’m developing. I added a few million records to a table, which is what it will have in about 5 years of use. I use Entity Framework. By counting the records of a query, It took a long time to occur. I thought it was an EF problem. However when making a trace in SQL Server and running the query directly in the database I noticed that the delay is in SQL Server itself.
Look at the following query example, similar to the one generated by the RU, but much simpler and still takes a long time:
select count(1) from tbMovimentoConta where con_codigo_fk = 1 and mcon_data >= '2017-01-01' and mcon_data <= '2018-01-01'
Result: 1,162,158 records
Time: 24 seconds
Repeating the query is instantaneous, I think because of the cache. But clearing the cache with the command DBCC DROPCLEANBUFFERS
will take about 25 seconds again.
The field con_codigo_fk
used in the where
of the above query is a foreign key and has index.
The field mcon_data
also used in where
of the above query also has index.
This table has 4 more foreign key indexes, and two more indexes for the fields mcon_dataExclusao
and mcon_dataInclusao
which are used in research.
Script of the column index mcon_data
to analyze and point out any possible flaw in it.
CREATE NONCLUSTERED INDEX [ix_mcon_data] ON [dbo].[tbMovimentoConta]
(
[mcon_data] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO
Is it normal to wait for this amount of records? It doesn’t seem so big to me. I don’t know if it’s the amount of indexes, or the way they were created. I’m investigating.
Computer Configuration: 8GB RAM and Core I7
I didn’t understand "Without a proper record is normal".
– user26552
Didn’t you ask if it’s normal to be slow? Indexes make all the difference, if you don’t have a suitable one, it’s normal to be slow.
– Maniero
So. Indexes do, but apparently they’re not helping. I’m studying the other answers to see if it gives a light. It’s a complex subject. This table has a PK that is auto-increment. I will try to add the other fields in the key then. At these times there is a DBA specialization missing.
– user26552
Your question does not show. If they are not helping they are inadequate, as I said.
– Maniero