Repository navigation
Read dscale and round result to that precision. Fixes #1466 - #1915
Conversation
|
Thanks for fixing the issue! Could you add a test or modify |
|
I'll check into that. |
|
@roji Let's have that fix now and improve performance later. I know you are interested in performance, but there is a much more terrible thing. Just take a look on |
|
Less than 1.5 seconds to randomly generate 2.5 Million numbers, divide them by 1000, round them to two decimal places, to me doesn't seem too bad since the rounding will be less than that. https://dotnetfiddle.net/93lYdb |
|
However, there is another issue. While this fix is better than the current operation, it could be improved. Columns of type For instance:
|
|
For what it is worth, So I'm not sure how we could get the actual column scale currently . |
I'm having a hard time trying to think of a test case that isn't already covered by the existing tests. I think this PR is ready to be merged "as is" since it improves the quality of the returned value and fixes a bug, though it might sometimes add about 90ns to the read time of a numeric column. (see updated fiddle) |
|
If it's really just 90ns than I guess it should be ok, but I'd really prefer seeing a proper BenchmarkDotNet benchmark (including memory allocations) of before and after rather than a hand-rolled StopWatch-based benchmark. @StillLearnin I'm not sure I agree that the scale defined on the However, you do raise an unrelated but important point, of the PostgresType not expressing the precision/scale, can you please open a separate issue on this? |
|
Excellent explanation. I'll open a new ticket and look into producing a "proper" benchmark. |
|
@StillLearnin ok great. I'm actually fine with this PR, it would just be good to run a specific BenchmarkDotNet benchmark that exercises reading decimals (see the test/Npgsql.Benchmarks project). You don't even have to include the benchmark in the PR, just post the code you used here along with the results (before vs. after), that should be enough to document things. |
[Config(typeof(Config))]
public class GetFieldValue
{
readonly NpgsqlConnection _conn;
readonly NpgsqlCommand _cmd;
readonly NpgsqlDataReader _reader;
public GetFieldValue()
{
_conn = BenchmarkEnvironment.OpenConnection();
_cmd = new NpgsqlCommand("SELECT 1.2::numeric", _conn);
_reader = _cmd.ExecuteReader();
_reader.Read();
}
[Benchmark]
public void ReadDecimal() => _reader.GetFieldValue<decimal>(0);
class Config : ManualConfig
{
public Config() => Add(StatisticColumn.OperationsPerSecond);
}
}
|
|
@YohDeadfall thanks for getting that done for me. I'm crazy busy and hadn't gotten to try it yet. Looks like it's actually less than 90 ns increase so we should be good to go! |
|
Looks good, thanks @YohDeadfall. By the way I systematically use MemoryDiagnoser to make sure how many allocations are added, if at all (in this case I'm pretty sure I guess the only thing missing is a test that demonstrates what this PR does and ensures no regressions occur in the future - that Npgsql returns 1.2 and not 1.2000 or anything else. @StillLearnin if you could add this that would be great, other @YohDeadfall I'm OK with merging. |
|
Sounds good. I’ll add it today. |
… decimals in the output.
|
Thanks @StillLearnin! |
No description provided.