I have a table with a column called Frequency (numeric). The user wants to do a simple search, for example,
WHERE Frequency BETWEEN 500 AND 600
The table is very large (4 million records) and I have to do some joins. I found out, the hard way, that the search runs 10 times faster if the Frequency column is Double rather than Decimal.
I've been afraid to use Double because I got burned on it once, about a year ago. I was comparing the "same" number against a Double column, that is,
WHERE Amount = 10
but it proved false because the Double column was storing the Amount as 10.0000001 (or something like that ). I suppose one solution would be to do a rounding to 2 digits:
WHERE Round(Amount, 2) = 10
but the problem with rounding is, Don't I lose the speed of using the index? I can't afford to forfeit index speed, since the table is so large.
So my question is this. Is there a safe way to use Double (i.e. safe from errors such as 10 <> 10.0000001) without losing index speed?
WHERE Frequency BETWEEN 500 AND 600
The table is very large (4 million records) and I have to do some joins. I found out, the hard way, that the search runs 10 times faster if the Frequency column is Double rather than Decimal.
I've been afraid to use Double because I got burned on it once, about a year ago. I was comparing the "same" number against a Double column, that is,
WHERE Amount = 10
but it proved false because the Double column was storing the Amount as 10.0000001 (or something like that ). I suppose one solution would be to do a rounding to 2 digits:
WHERE Round(Amount, 2) = 10
but the problem with rounding is, Don't I lose the speed of using the index? I can't afford to forfeit index speed, since the table is so large.
So my question is this. Is there a safe way to use Double (i.e. safe from errors such as 10 <> 10.0000001) without losing index speed?