本文发表在 rolia.net 枫下论坛I've got a table with half a million rows. One of the columns is of type DEC(7,2). Let's call it column A. Now user wants to inquire the table by A - he inputs an amount, then I show the first 300 rows that are greater than that amount, sorting the result set by A.
Because there are half a million rows, performance may be a problem. So I created an index on A. But, interestingly, the system refuses to use that index. It says that it would be more costly to use that index than to use arrival sequence access! So it puts the result set into a temporary file and sort the quarter-million records at run time. The result is a response time of 20 seconds. That's surely not satisfactory.
Then I removed the index and tested again. The reponse time remains the same. And system suggested me to create an index on A. Isn't it funny?
Finally I tried to force the use of the index by making the SORT BY clause the same as the keys of the index. This time the system goes crazy and says it has to create a temporary table for the original table before it can start working on it. Consequently, the reponse time becomes more than 2 minutes!
Now I'm wandering if there is any restriction on using a decimal column as a key. Or maybe there are other ways to approach this issue because only the first 300 rows in the result set are needed.
Guys, give me a hand! I'd appreciate it a lot! btw, I'm using UDB for iSeries.
I may have put this post in the wrong category because my PC can't show Chinese. Dear webmaster please don't delete this post if so. Thanks!更多精彩文章及讨论,请光临枫下论坛 rolia.net
Because there are half a million rows, performance may be a problem. So I created an index on A. But, interestingly, the system refuses to use that index. It says that it would be more costly to use that index than to use arrival sequence access! So it puts the result set into a temporary file and sort the quarter-million records at run time. The result is a response time of 20 seconds. That's surely not satisfactory.
Then I removed the index and tested again. The reponse time remains the same. And system suggested me to create an index on A. Isn't it funny?
Finally I tried to force the use of the index by making the SORT BY clause the same as the keys of the index. This time the system goes crazy and says it has to create a temporary table for the original table before it can start working on it. Consequently, the reponse time becomes more than 2 minutes!
Now I'm wandering if there is any restriction on using a decimal column as a key. Or maybe there are other ways to approach this issue because only the first 300 rows in the result set are needed.
Guys, give me a hand! I'd appreciate it a lot! btw, I'm using UDB for iSeries.
I may have put this post in the wrong category because my PC can't show Chinese. Dear webmaster please don't delete this post if so. Thanks!更多精彩文章及讨论,请光临枫下论坛 rolia.net