Common examples explain the running status of SQL

Source: Internet
Author: User

The SQL Server sqlos uses schedulersto manage the execution of user requests. sqlos schedulers map to CPUs. assuminga 4-cpu server, there wocould be 4 sqlos schedulers by default. The following diagrams depict
A simplifiedversion of execution model using a single sqlos schedtion. The execution model in Figure 1 depicts how SQL serveruser requests or sessions (denoted by spids) are scheduled for execution.

Figure 1: execution model-running, runnable and suspendedstatus, runnable queue and wait list

Figure 2 shows how SQL Server sessionsrotate between the following statuses:Running(Only one session can be running or executing, per Scheduler ),Runnable
(Sessions waiting for CPU), orSuincluded.Spids with susponded statuses are placedin waiter list until the requested resources are available. If a running sessionneeds a data page that is not in cache, or needs a page that is blocked
Byanother user's lock, the session is moved to the wait list. The next spid or session_idin the runnable queue is scheduled to start running.

Figure 2: execution model-How status changes affect spids

The status change sequence of events is as follows:

  1. Spid60 needs a page not in cache. Thus its status changes from running to susponded with wait type io_completion
  2. Spid60 moved to waiter list
  3. Spid51 moves from runnable queue with a runnable status to running status, spid64 then moves to the top of the runnable queue
  4. Spid56 is waiting for a parallel process to complete. When the parallel process is completed, the status for spid56 changes from suincluded with wait type cxpacket to runnable
  5. Spid56 moved to the bottom of the runnable queue

Figure 3 depicts execution "after" session_ids (or spids) have rotated clockwise due to status changes.

Figure 3: execution model-after status change

The wait list means a thread has to wait for aresource. example of resource waits includes Ios to complete, a lock to bereleased, a memory Grant, and so on. when the sessionis moved to the wait list, a wait type is assigned and time is accumulated. when
Resource becomes available, the thread is moved to the runnable queueand it executes as soon as the CPU is available. The clockwise rotation between running, runnable and surentded States continues until the user request is completed.

For more information, see performance_tuning_waits_queues.doc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.