Table in sql server 2017 takes alot of time to update/insert few rows

mahag 1 Reputation point
2020-08-24T06:59:59.057+00:00

Hello
I have a table in sql server 2017 that has around half million records and it is constantly used via website.
Select statement are very fast over it or over its views,but update/insert of 1 or 2 rows takes a lot of time sometimes 1 row needs 15 minutes as if table is busy.
I have other tables that have more rows but less used that don't have this issue.

This table has 1 primary key(1 field integer type) and other 6 non unique,non clustered indexes( some of them are added after doing a sqlprofiler analysis and it gave suggestions to add them).

It has 40 views over it.Only one of them has a clustered index that was created in order to add to it full text index.
Does the high number of views (even without indexes) affects the table update/insert?Or is it the number of indexes?Or both combined?

When running execution plan over one insert shows that :

  • 77 % of the cost is over "clustered index insert" that shows all of the indexes over the table
  • 12 % of the cost is over "clustered index merged" from the view that has index over it
  • 8 % of the cost is over "clustered index insert" that show the index of the view
  • 1 % : "clustered index seek" over full text index of the view
  • 1 % : "clustered index seek" over primary key on another table that is joined with the indexed view

Initially the table had more non clustered indexes,I deleted around 5 of them and retried the insert with execution plan.The performance issue stayed the only difference is that the cost % over all indexes dropped a bit each time i removed an index

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,850 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,559 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Tom Cooper 8,466 Reputation points
    2020-08-24T08:03:12.277+00:00

    A view with an index will slow down inserts/updates. But the non-indexed views you have have no effect on inserts/updates.
    From your description, I suspect your problem is blocking.

    Tom

    0 comments No comments

  2. Erland Sommarskog 102.1K Reputation points MVP
    2020-08-24T22:00:45.737+00:00

    As Tom says, the issue could be blocking. To take that out of the equation, restore the database on a test server and try the insert. And try it with and without the indexed view.

    Keep in mind that the percentages you see are based on estimates, and they can be flat wrong with regards to reality.

    0 comments No comments

  3. m 4,271 Reputation points
    2020-08-25T05:48:59.207+00:00

    Hi @mahag ,

    Do you test by referencing @Tom Cooper ’s and @Erland Sommarskog ’s replies?
    Execute code as next and then update here:

    select * from master.sys.sysprocesses

    More information: https://support.microsoft.com/en-us/help/224453/inf-understanding-and-resolving-sql-server-blocking-problems

    BR,
    Mia
    If the reply is helped, please do “Accept Answer”.--Mia

    0 comments No comments

  4. m 4,271 Reputation points
    2020-08-26T01:32:04.37+00:00

    Hi @mahag ,

    Is the reply helpful?

    BR,
    Mia
    If the reply is helped,please do "Accept Answer".--Mia

    0 comments No comments

  5. m 4,271 Reputation points
    2020-08-27T09:36:13.22+00:00

    Hi @mahag ,

    Is the reply helpful?

    BR,
    Mia
    If the reply is helped,please do "Accept Answer".--Mia

    0 comments No comments