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

后端 未结 15 2146
遥遥无期
遥遥无期 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:35

    It's all about indexes. And avoiding stupid things that make them useless.

    0 讨论(0)
  • 2021-02-10 07:37

    Splitting one ridiculously long stored procedure, which did a great deal of "if it's after 5 pm, return this bit of sql" and which took in excess of 20 seconds to run, into a set of stored procedures that were called by one controlling sp, and got the times down to subsecond responses.

    0 讨论(0)
  • 2021-02-10 07:39

    Back in the day, I worked on a CICS/DB2 system, written in COBOL. A lot of our queries were doing full table scans (and slow) even though we had all the proper indexes and WHERE clauses.

    It turned out (and I may have this backwards, it's been 15 years) that the problem was that we were using PIC S9(n) COMP in WORKING STORAGE for the query parameters, but DB2 wanted PIC S9(n) COMP-3. By using the wrong data type, DB2 had to do a full table scan in order to convert the values in the database to the value we were passing in. We changed our variable definitions and the queries were able to use the indexes now, which dramatically improved our performance.

    0 讨论(0)
提交回复
热议问题