Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. "Lazy Spool" problem

"Lazy Spool" problem

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bernhard Hiller
    wrote on last edited by
    #1

    A simple query with a left join sues to run quickly on SQL Server, but only with one parameter changed, it takes almost a minute. The query is something like:

    SELECT Table1.*, Table2.*
    FROM Table1 Left JOIN Table2 ON Table1.ID=Table2.Table1ID
    WHERE (Table1.Col1=38 OR Table1.Col1=-1) AND Table1.Col2=0

    That produces around 280 lines of output in a second. When we change Col1=38 to Col1=114, it produces some 320 lines of output, in almost a minute! We looked at the execution plan, and in the second case we found an extra "Lazy Spool" not present in the first query, which was estimate to cost a percent. When I looked at that "Lazy Spool", I found a striking difference between estimated and actual values: Actual Number of Rows:75124744 Estimated Number of Rows: 708724 That is more than a hundred times as much as estimated! Actual Rebinds was 1, and Actual Rewinds 105! Can you guess what went wrong here?

    R J 2 Replies Last reply
    0
    • B Bernhard Hiller

      A simple query with a left join sues to run quickly on SQL Server, but only with one parameter changed, it takes almost a minute. The query is something like:

      SELECT Table1.*, Table2.*
      FROM Table1 Left JOIN Table2 ON Table1.ID=Table2.Table1ID
      WHERE (Table1.Col1=38 OR Table1.Col1=-1) AND Table1.Col2=0

      That produces around 280 lines of output in a second. When we change Col1=38 to Col1=114, it produces some 320 lines of output, in almost a minute! We looked at the execution plan, and in the second case we found an extra "Lazy Spool" not present in the first query, which was estimate to cost a percent. When I looked at that "Lazy Spool", I found a striking difference between estimated and actual values: Actual Number of Rows:75124744 Estimated Number of Rows: 708724 That is more than a hundred times as much as estimated! Actual Rebinds was 1, and Actual Rewinds 105! Can you guess what went wrong here?

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      Bernhard Hiller wrote:

      Can you guess what went wrong here?

      Is that your question or is this a quiz?

      "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

      B 1 Reply Last reply
      0
      • B Bernhard Hiller

        A simple query with a left join sues to run quickly on SQL Server, but only with one parameter changed, it takes almost a minute. The query is something like:

        SELECT Table1.*, Table2.*
        FROM Table1 Left JOIN Table2 ON Table1.ID=Table2.Table1ID
        WHERE (Table1.Col1=38 OR Table1.Col1=-1) AND Table1.Col2=0

        That produces around 280 lines of output in a second. When we change Col1=38 to Col1=114, it produces some 320 lines of output, in almost a minute! We looked at the execution plan, and in the second case we found an extra "Lazy Spool" not present in the first query, which was estimate to cost a percent. When I looked at that "Lazy Spool", I found a striking difference between estimated and actual values: Actual Number of Rows:75124744 Estimated Number of Rows: 708724 That is more than a hundred times as much as estimated! Actual Rebinds was 1, and Actual Rewinds 105! Can you guess what went wrong here?

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #3

        Bernhard Hiller wrote:

        Can you guess what went wrong here?

        Old statistics?

        Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

        B 1 Reply Last reply
        0
        • R R Giskard Reventlov

          Bernhard Hiller wrote:

          Can you guess what went wrong here?

          Is that your question or is this a quiz?

          "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          mark merrens wrote:

          Is ... this a quiz?

          Does it look like that? Perhaps it is. But you did not win the prize of my 5.

          1 Reply Last reply
          0
          • J Jorgen Andersson

            Bernhard Hiller wrote:

            Can you guess what went wrong here?

            Old statistics?

            Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            Thanks for this idea. The statistics did not bring improvement. Eventually an index on column Table1ID of Table2 brought the solution.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups