microsoft / tigertoolbox

Toolbox repository for Tiger team
http://aka.ms/sqlserverteam
Other
1.45k stars 734 forks source link

Arithmetic overflows in view_IndexInformation_CurrentDB; No data output #306

Open Hedrik opened 6 months ago

Hedrik commented 6 months ago

Freshly downloaded from GitHub. No usage instructions found, so I just added a 'USE {Db}' at the top and ran it. Here is the relevant part of the message output - I suspect that the script may need to be updated to use the bigint type instead of int - I will report back if I attempt again after changing to bigint, though given that it took 6 and 1/2 hours to run, I may just wait on that...: (then again, I don't see anything even possible in the region of the line reported as having the error, so...)

.
.
.
Msg 8115, Level 16, State 2, Line 416
Arithmetic overflow error converting expression to data type int.
The statement has been terminated.
Msg 8115, Level 16, State 2, Line 416
Arithmetic overflow error converting expression to data type int.
The statement has been terminated.
Msg 8115, Level 16, State 2, Line 416
Arithmetic overflow error converting expression to data type int.
The statement has been terminated.
Msg 8115, Level 16, State 2, Line 416
Arithmetic overflow error converting expression to data type int.
The statement has been terminated.
.
.
.
Msg 8152, Level 16, State 10, Line 3
String or binary data would be truncated.

And the result had no data:

image

matthiaslueken commented 1 week ago

Same, the overflow happens when aggregating the record_count on lines 424 - 423:

SUM(ISNULL(ps.record_count,0)),
SUM(ISNULL(ps.forwarded_record_count,0)) -- for heaps

Solution: change the datatype of the temp table to bigint (lines 86 - 96):

CREATE TABLE #tmpIPS (
    [database_id] int,
    [object_id] int,
    [index_id] int,
    [partition_number] int,
    fragmentation DECIMAL(18,3),
    [page_count] bigint,
    [size_MB] DECIMAL(26,3),
    record_count **bigint**,
    forwarded_record_count **bigint** NULL,
    CONSTRAINT PK_IPS PRIMARY KEY CLUSTERED(database_id, [object_id], [index_id], [partition_number]))