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

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

提交回复
热议问题