Hide Forgot
> Description of problem: Stored Procedure dbo.dwh_history_aggregate_level fails to execute successfully. > Version-Release number of selected component (if applicable): RHEV-M 4.5.4.51796 (2.2.4) > How reproducible: Always. > Steps to Reproduce: 1. Insert several records onto the dbo.vm_disk_history table so that SUM (read_rate) and/or SUM (write_rate) exceed 2^32. 2. Execute SP with @AggrStart and @AggrGap providing a range so that SUM (read_rate) and/or SUM (write_rate) still exceed 2^32. > Actual results: Error 8115, Level 16, State 2, Procedure dwh_history_aggregate_level, Line 87, Message: Arithmetic overflow error converting expression to data type int. > Expected results: Successful execution of the SP. > Additional info: Issue is triggered by the following SQL statement on dwh_history_aggregate_level, lines 90-97: -- insert into vm_disk_history select @Aggregeation_level, @AggrStart, vm_guid, image_guid,MAX(actual_size) as actual_size_max, MAX(size) as size,disk_interface,disk_type,imageStatus, AVG(read_rate) AS read_rate_avg, AVG(write_rate) AS write_rate_avg FROM dbo.vm_disk_history WHERE history_datetime>=@AggrStart and history_datetime<@AggrEnd GROUP BY vm_guid, image_guid,imageStatus,disk_interface,disk_type -- Columns read_rate and write_rate on table vm_disk_history are of type int. According to http://msdn.microsoft.com/en-us/library/ms177677%28v=SQL.90%29.aspx: 'The return type is determined by the type of the evaluated result of expression.' So for integer data types, the return type will be 'int'. As AVG () will attempt to return an 'int' if input data type is int, and the sum of all read_rate values exceed 4 bytes length (see http://msdn.microsoft.com/en-us/library/ms187745%28v=SQL.100%29.aspx for data type limits), the call Furthermore, the following is mentioned for SQL Server 2008's AVG () (http://msdn.microsoft.com/en-us/library/ms177677%28v=SQL.100%29.aspx): 'AVG () computes the average of a set of values by dividing the sum of those values by the count of nonnull values. If the sum exceeds the maximum value for the data type of the return value an error will be returned.'
Workaround: Replace line 94: AVG(read_rate) AS read_rate_avg, AVG(write_rate) AS write_rate_avg With AVG(cast(read_rate as bigint)) AS read_rate_avg, AVG(cast(write_rate as bigint)) AS write_rate_avg Attaching proposed patch.
Created attachment 555083 [details] Patched dwh_history_aggregate_level Stored Procedure
A fix for this issue was pushed upstream and available in the link: http://gerrit.ovirt.org/1254 Yaniv
Fixed, 3.1/si24.1 I have ran on 2 different setups for couple of days big numbers for Write Rate in Bytes -> for vm_disk_history views And data is ok and aggregated samples/hourly/daily Fixed, 3.1/si24.1