Disclaimer: I am not an MSSQL dba....
I have used two sql queries presented elsewhere on stackoverflow [1]: https://stackoverflow.com/a/7892349/2195559 [2]: https://stackoverflow.com/a/17600911/2195559
[1] claims to show the total space used by a table and its indexes [2] claims to show the total space used by an index
So looking at my largest table:
[1] gives UsedSpaceKB = 58757504 . So the table and indexes are 56GB
[2] gives Indexsize(KB) = 55166168 for the largest index on that same table (there are some others on the same table - but they are tiny in comparison). So the largest index is 52GB
[1] - [2] (for indexes on the same table) = 4GB.
So IF [1] and [2] are correct and I have understood the output then I have a 4GB table with a 52GB primary key index on it.
Questions:
- have I understood [1] and [2] correctly?
- if so then how can I have a pk index that is 52GB on a table that is itself just 4GB? We use nightly batch jobs to remove old rows in this table (its an audit log), is it possible that the index is not being reduced when rows are removed from the table?
- what's the simplest & quickest way to clear this index - drop and build or is there some more efficient mechanism?
The ddl for the table and pk index are
CREATE TABLE "YYY"."XXX_audit"
(
id numeric(19,0) PRIMARY KEY,
version numeric(19,0),
compressed_response image,
date_created datetime,
duration numeric(19,0),
request text,
response text,
session_id varchar(255),
uid varchar(255),
webservice_uri varchar(255),
event_id varchar(36)
)
GO
CREATE UNIQUE INDEX PK__XXX_audit__6CC31A31 ON "YYY"."XXX_audit"(id)