Honestly the output of sp_spaceused is not clear and
confusing.
how to get the size of the table from this output?
how to get the size of the indexes from this output?
what is index_size in the last line? it is < (total indexes
size column)
how to get the 10 largest tables? 10 largest indexes?
thank you very much.
sp_spaceused 'MY_TABLE',1
go
index_name size reserved unused
------------------- ---------- ---------- ----------
MY_TABLE 0 KB 105952 KB 10148 KB
MY_TABLE_INDX 26488 KB 27952 KB 1464 KB
tMY_TABLE_INDX 46839048 K 49802000 K 2962952 KB
(1 row affected)
name rowtotal reserved data
index_size unused
---------------- ----------- ---------------
--------------- --------------- ---------------
MY_TABLE 1138318 49935904 KB 95804 KB
46865536 KB 2974564 KB
The bottom line is the summary for the entire table. The total amount
of space allocated to this table is 49935904 KB, of which 1138318 KB is
not currently being used. (space is allocated in 8-page extents, a page
is used if anything is being stored on it, so you can have extents with
1 used page and 7 unused, etc.)
The table has only one real index, "MY_TABLE_INDX". It has 27952 KB
reserved, of which 26488 is used and 1464 is unused. ("(used) size" +
"unused" = "total reserved"
TEXT/IMAGE data is stored under index-id (indid) 255. That is the
tMY_TABLE_INDX line.
The index_size value on the last line is the sum of the "used" values
for all indexes including the text/image columns.
To get the 10 largest tables, use a query something like
select
top 10
object_name(id) as "table_name",
reserved_pages(db_id(), id)
from
sysindexes
where
indid in (0,1)
order by
reserved_pages(db_id(),id)
desc
go
To get the 10 largest indexes, excluding text/image:
select
top 10
object_name(id) as "table_name",
name as "index_name",
reserved_pages(db_id(), id, indid)
from
sysindexes
where
-- exclude heap data (0) and text/image (255)
indid between 1 and 254
order by
reserved_pages(db_id(), id, indid)
desc
go
Hi, which version has function 'reserved_pages', I got an error on my
envrioment.
Msg 14216, Level 16, State 1:
Server 'S01ABC1', Line 1:
Function 'reserved_pages' not found. If this is a SQLJ function, use
sp_help to
check whether the object exists (sp_help may produce a large amount of
output).
Brets code appears to be for 15.x and I suspect that you are on an earlier
version. (Suggestion: always provide the server version.) Pre-15.x would
use "reserved_pgs (id,ioampg)". However, I don't see an indid argument (nor
a dbid argument) for reserved_pgs ().
The 'changes' consist of a) different spelling and b) different input parameters. Details can be found in the New
Features and Reference manuals.
Yes, yes, and yes.
Bret's code is an excellent starting point, but I doubt he was
providing something that works in all conditions, or that is intended
to handle the data/index issues. One has to understand the query and
the sysobjects/sysindexes structures.
> Pre-15.x would use "reserved_pgs (id,ioampg)". However, I don't see
> an indid argument (nor
> a dbid argument) for reserved_pgs ().
For 15.0:
select ... reserved_pages (dbid, id [,indid [,ptnid] ] ) from sysindexes
For pre- 15.0:
select ... reserved_pgs (id, { doampg | ioampg } ) from
dbname..sysindexes where indid = xyz
Choose indid 0 or 1 and Doampg to get reserved pages for DATA
Choose indid > 0 and Ioampg to get reserved pages for each INDEX
Remember indid = 1 is a true APL/CI (DPL or DRL "clustered" indices are
not clustered as term existed before their advent and meant something
rather specific; this is reflected in the fact that such indids are NOT
1). The 15.0 function may look "cleaner" but it is not, you still have
to mess with the returns (ala pre-15.0) to separate the data/index
values.
--
Cheers
Derek
Senior Sybase DBA / Information Architect
Copyright © 2008 Software Gems Pty Ltd
--
Tired of databases that are more cost than benefit ? Wondering why you
cannot get Sybase performance from Sybase ? Find out
I am using 12.5.4
can we translate the sql query from 15 to 12.5.4?
thanks
<Samuel> wrote in message news:496df774.431...@sybase.com...
thanks
> Copyright Š 2008 Software Gems Pty Ltd