Blocking Issue:Insert blocking select statements

  • I have a table 'accounts'.One of my select query in side a stored procedure 'EOD_Report' is is blocking the insert query defined in another stored procedure named 'login'.

    Whenever 'EOD_Summary' stored procedure runs ,all our application freezes and users are not able to login.Since the EOD_Report takes min 45 min to execute we are facing business loss.

    Is there is a way to avoid this or change the Isolation level which may help to run the insert statement simultaneously along with select.

  • Can you schedule the 2 jobs so they don't conflict ? If they are both EOD jobs, maybe they should run consecutively ?

  • 1. Try to create an appropriate index so that the Report Stored Proc doesn't nun for 45 mins and thereby reducing the blocing time

    2. OR Try to use read comitted snapshot isolation level which uses row versioning. Please note that this puts an additional load on the TempDB. So test before you use this.

    Thank You

    Best Regards,

    SQLBuddy

  • If you can afford dirty reads then use with nolock

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • can you see the execution plan for this slowness, i.e., where the resources are consuming most.

    Also just a suggestion to try, if you have select query in your SP, just run the query with hint.

    Like select...............from tablename where conditions(if applicable)

    with recompile.

    Also try to recompile your SP. Might be stats are not updated in those table.

    Check the index fregmentation level of the tables used in SP.

    ----------
    Ashish

  • Review the execution plan of that SP and the access mode of that particular table. Could be a table level lock due to full-table scan. Add appropriate index to eliminate the table scan. Don't think resource is a problem, until unless the CPU utilizaiton is constantly high for whole blocking period.

  • The reason large select is blocking is due to lock-escalation. In SQLServer2008, you can disable lock-escalation by command set lock-escalation disable. How big is your select? How many tables? Have you measured IO and time? You should try to tune that SP to see if you can minimize the resource usage, optimize the query.

    For performance tuning, please see my SQLsaturday#57 presentation. (too much to mention)

    I solved this kind of problem before (in a poor-man's 2005 environment) by producing the select into a physical table over night (like Oracle materialized view, extra GB space needed in my case). It won't be real-time though. If you have to, you can utilize database snapshot for the report queries. Obviously, warehouse queries should be handled separated from OLTP queries.

    Snapshot isolation utilizes row-versioning instead of locking, but be prepared with tempdb resource depending on how large is your select query, and whether you are near or out of IO capacity.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply