Azure sql db instance is taking very long time for a simple select query . How can we improve his ?

Amar Agnihotri 921 Reputation points
2023-01-28T17:51:51.29+00:00

Hi,

I have this azure sql db instance

User's image

I am having table in database which is having only 12000 rows. A week ago everything was working fine but suddenly since last 3 days even select query is taking very long time . See the snap. For fetching the 12000 rows it took almost 11 minutes

User's image

Here is my azure sql db settings

User's image

What happened to my azure sql db ? How can i improve the performance ?

Azure SQL Database
0 comments No comments
{count} vote

Accepted answer
  1. Alberto Morillo 34,151 Reputation points MVP
    2023-01-29T01:40:19.5633333+00:00

    Before you investigate any further, could you please update statistics and defragment indexes using Ola Hallengren scripts and let us know if that improved performance. Donwload the scripts (IndexOptimize.sql and CommandExecute.sql) from here.

    EXECUTE dbo.IndexOptimize @Databases = 'USER_DATABASES',@FragmentationLow = NULL,@FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',@FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',@FragmentationLevel1 = 5,@FragmentationLevel2 = 30,@UpdateStatistics = 'ALL',@OnlyModifiedStatistics = 'Y'
    

    One thing you need to know is the following:

    Memory for serverless databases is reclaimed more frequently than for provisioned compute databases. This behavior is important to control costs in serverless and can impact performance.

    Source: Serverless documentation.

    The above excerpt from the Serverless documentation, is telling you that after some time you execute a query and it will have to bring pages of data from disk to memory (producing waits like PAGEIOLATCH and MEMORY_ALLOCATION_EXT) , instead of finding them on the memory cache, and that will impact performance. Adding to that, you have only one core assigned to the serverless database, all your queries will not use parallelism.

    If the above does not help, could you please share the execution plan of the query and let us know the top waits when you execute the query using (use instructions provided on this article).


2 additional answers

Sort by: Most helpful
  1. Oury Ba-MSFT 19,806 Reputation points Microsoft Employee
    2023-01-30T22:15:13.74+00:00

    Hi Amar Agnihotri Thank you for reaching out.

    Did you had the chance to check out @Alberto Morillo answer above. Let us know if that was helpful. In addition to that you could also consider increasing the service tier. To start usually anywhere between 2-4 levels up should help. Please let us know the progress.

    Regards,

    Oury

    0 comments No comments

  2. Simon Harrison 0 Reputation points
    2023-05-30T01:25:35.79+00:00

    I have the same problem with a slightly larger table ~ 400,000

    For months a full read (select <list of columns> from <table>) completed in a few seconds.

    Suddenly it takes 15 minutes.

    I have applied all the answer suggestions, but nothing makes a difference.

    The retrieval strategy is a Clustered Index Scan, which seems inappropriate for a full table select, where it doesn't need to go via an index at all.

    Why the sudden change (for the worse)?

    live query (in progress)


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.