What was your coolest SQL optimization, on a slow performing query?

后端 未结 15 2178
遥遥无期
遥遥无期 2021-02-10 06:45

Just speaking to a colleague of mine. He was walking with a hop in his step, on the way to the coffee machine.

I asked him \"what\'s with the \'swarmy\' walk?\", he said

15条回答
  •  北荒
    北荒 (楼主)
    2021-02-10 07:20

    I had a query that was originally written for SQL Server 6.5, which did not support the SQL 92 join syntax, i.e.

    select foo.baz
    from foo
      left outer join bar
      on foo.a = bar.a
    

    was instead written as

    select foo.baz
    from foo, bar
    where foo.a *= bar.a
    

    The query had been around for a while, and the relevant data had accumulated to make the query run too slow, abut 90 seconds to complete. By the time this problem arose, we had upgraded to SQL Server 7.

    After mucking about with indexes and other Easter-egging, I changed the join syntax to be SQL 92 compliant. The query time dropped to 3 seconds.

    I don't think I'll ever have that feeling again. I was a f%$^ing hero.

提交回复
热议问题