Store Procedure Problem

  • When i am running first time sp it will take 30 sec and second time it will execute 1 sec.
    My problem is yesterday i am running my report using front end application it will executive success fully(store procedure exe time is 1 sec).but today i am insert some records in the table and running the my report using front end application it will display the time out error and my table have 800000 records.Please check the below my store procedure.How solve the my probelm.

    USE [XmlTracker]
    GO
    /****** Object: StoredProcedure [dbo].[GetXMLDataCHanges]  Script Date: 10-08-2017 19:02:57 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    ALTER procedure [dbo].[GetXMLDataCHanges]
    (
    @uid int
    )
    as
    Begin
    select Element,convert(varchar(10),[Previous Date],127) as [Previous Date],[Node Name],
    [Out],convert(varchar(10),[Current Date],127) as [Current Date],[In]
    from xmlchanges
    where uid=@uid
    end

  • How many records did you insert before running the SP another time? If it was a significant amount, then it will greatly affect index fragmentation. Rebuilding the index for the 'uid' field might help with that. If there isn't an index on the uid, then you'll definitely want that.

    What performance tier is your database? If it's Basic, then I believe you're still using shared resources and performance can greatly vary.

  • before running sp we insert 50000 records and table already have index on uid.

    Regards
    Pols

  • Have you checked the query plan or index fragmentation yet? Those 50000 records might have pushed the fragmentation to the point where it might start running scans instead of seeks.

  • query plan and fragmentation good.

    regards
    pols

  • I'd check statistics first before worrying about index fragmentation.

    SELECT SCHEMA_NAME(o.schema_id) AS SchemaName, o.name AS TableName, i.name AS IndexName,
        s.name AS StatsName, STATS_DATE(s.object_id, s.stats_id) AS StatsDate,
        si.rowmodctr AS RecordsModified, si.rowcnt AS TotalRecords, si.rowmodctr*100.0/si.rowcnt AS pct
      FROM sys.objects o
        INNER JOIN sys.stats s ON o.object_id = s.object_id
        LEFT OUTER JOIN sys.indexes i ON o.object_id = i.object_id
        LEFT OUTER JOIN sys.sysindexes si ON i.object_id = si.id AND i.index_id = si.indid
      WHERE o.type = 'U'
        AND o.name = 'xmlchanges'

  • Please check the attache file for above result data.

    Regards
    Pols

  • my azure database is Basic 2GB only and reaming space 600MB.but still my problem not solve.

    regards
    pols

  • What have you tried to resolve this?  The statistics don't look out of date, but you haven't actually given us the table and index definitions, or the execution plan.  We'd probably need to see those to help you out much further.

  • If you're using Basic, you could be running into a resource constraint. Have you tried looking at the Azure portal to see whether memory, CPU, or IO are getting pegged?

  • How many records would you expect to be returned by this: where uid=@uid

    Is it one (or a few) or large numbers? The query itself as posted is very simple. Assuming a clustered index on the uid column and a small data set, you should be seeing a seek running fairly quickly. If it's a nonclustered index on uid, then you'd still see a seek if it's only a few rows combined with a key lookup or rid lookup. However, if there is no index on uid or it's returning a bunch of rows, then you're going to see a scan. If it's a bunch of rows, there may not be much that can be done to help. If it's just a missing or incorrect index, that can be fixed.

    Also, it could just be network latency if you're testing the retrieval from Azure from your client and your client is not also running in Azure (by the way, that counts as data egress and will cost money).

    We're working off of a very limited set of data here (the query). Getting the table structure, including indexes, keys, constraints, and an execution plan (preferably the "actual" plan), would make a big difference. Assuming you're on SQL Server 2016 SP1 or greater, the actual plan of the execution plan will have the run time query performance included in the plan, so you won't have to capture the query metrics separately.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 11 posts - 1 through 10 (of 10 total)

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