I have a column defined as Number (10,3) and this column is indexed. I was wondering if I convert this column to be an integer, will the index perform better on it. I will have to multiple by 10^7 and do a divide by 10^7 in my code for it. But i don’t know if it is necessary?
Thanks,
It’s almost certainly not going to be an appreciable difference.
The index may be slightly more compact because the integer representations may be slightly smaller than the fixed point representation. For example, the number 1234 requires 3 bytes of storage while the number 1.234 requires 4 bytes of storage. Occasionally, the reverse will be true and the fixed point value will require less storage, but it’s 100 times more likely that the integer representation will be smaller than the reverse. You can see that yourself by populating a table with the first 1 million integers and the first million integers divided by 1000.
While the index is going to be slighly more compact, that would only come into play if you’re doing some extensive range scans or fast full scans on the index structure. It is very unlikely that there would be fewer levels in the index on the integer values so single-row lookups would require just as much I/O. And it is pretty rare that you’d want to do large scale range scans on an index. The fact that the data is more compact may also tend to increase contention on certain blocks.
My guess, therefore, is that the index would use slightly less space on disk but that you’d be hard-pressed to notice a performance difference. And if you’re doing additional multiplications and divisions every time, the extra CPU that will consume is likely to cancel whatever marginal I/O benefit you might get. If your application happens to do a lot more index fast full scans than the average, you might see some reduced I/O.