August 28, 2010 at 3:11 am
Hi,
I am creating a table of row size char(1000) as below.
create table Optimised(id char(1000))
i am insert values 1,2,3,4.....
insert into Optimised values('1')
insert into Optimised values('2')
insert into Optimised values('3')
insert into Optimised values('4')
insert into Optimised values('5')
insert into Optimised values('6')
insert into Optimised values('7')
insert into Optimised values('8')
After inserting value '7', sp_spaceused shows reserved:16KB and data:8KB which is expected. But when i insert next value '8' then sp_spaceused shows reserved:24KB and data:16KB. How the last insert increase the page size to 16KB since still i have used only 8000 bytes which is in 8KB?
Can anyone pls explain this..
Thanks
Gopi
August 28, 2010 at 4:46 am
Cannot remember details (its probably in BOL) but each page has a header as well at least taking up bytes, so the 8th row did not fit and went onto a new page.
see how much space is wasted if columns are not defined carefully.
---------------------------------------------------------------------
August 28, 2010 at 8:27 am
The last row inserted causes SQL Server to allocate a new 8K page for your table, this means your table now has two 8K pages therefore its size is 16K. The unused column could read 8K.
MCITP SQL Server 2005/2008 DBA/DBD
August 28, 2010 at 8:47 am
Each Page has overhead as george said. Due to the overhead, you would be creating a new page on the 8th insert.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
August 28, 2010 at 10:31 am
Hi,
Thanks for the update.
Still few more clarification needed.
We have 8192 bytes of page. 96 bytes is used for header information.In my above example 16 bytes will be reserved for offset storage. Still we have 8080 bytes remaining. But how i am unable to store last record in the same page since it takes only 8000 bytes totally? Can you pls explian how the memory is used in my example and the reason how the last insert use next page.
Thanks in advance.
Gopi
August 28, 2010 at 11:17 am
This article may be of interest. There is more overhead imposed by the internals of SQL server than what you listed.
http://www.sqlservercentral.com/articles/Miscellaneous/pagesize/497/
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
August 28, 2010 at 11:18 am
Gopinath Srirangan (8/28/2010)
Hi,I am creating a table of row size char(1000) as below.
create table Optimised(id char(1000))
i am insert values 1,2,3,4.....
insert into Optimised values('1')
insert into Optimised values('2')
insert into Optimised values('3')
insert into Optimised values('4')
insert into Optimised values('5')
insert into Optimised values('6')
insert into Optimised values('7')
insert into Optimised values('8')
After inserting value '7', sp_spaceused shows reserved:16KB and data:8KB which is expected. But when i insert next value '8' then sp_spaceused shows reserved:24KB and data:16KB. How the last insert increase the page size to 16KB since still i have used only 8000 bytes which is in 8KB?
Can anyone pls explain this..
Thanks
Gopi
Perhaps this will explain it...
1000 bytes per row.
4 bytes row header over head per row.
3 bytes (in this case) for the Null bitmap.
2 bytes for the row's entry in the slot array of the page.
-----
1009 * 8 = 8072 bytes... 12 more than a page will hold (8060).
--Jeff Moden
Change is inevitable... Change for the better is not.
August 28, 2010 at 11:21 am
Jeff Moden (8/28/2010)
Gopinath Srirangan (8/28/2010)
Hi,I am creating a table of row size char(1000) as below.
create table Optimised(id char(1000))
i am insert values 1,2,3,4.....
insert into Optimised values('1')
insert into Optimised values('2')
insert into Optimised values('3')
insert into Optimised values('4')
insert into Optimised values('5')
insert into Optimised values('6')
insert into Optimised values('7')
insert into Optimised values('8')
After inserting value '7', sp_spaceused shows reserved:16KB and data:8KB which is expected. But when i insert next value '8' then sp_spaceused shows reserved:24KB and data:16KB. How the last insert increase the page size to 16KB since still i have used only 8000 bytes which is in 8KB?
Can anyone pls explain this..
Thanks
Gopi
Perhaps this will explain it...
1000 bytes per row.
4 bytes row header over head per row.
3 bytes (in this case) for the Null bitmap.
2 bytes for the row's entry in the slot array of the page.
-----
1009 * 8 = 8072 bytes... 12 more than a page will hold (8060).
Thanks Jeff for outlining it so well.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
August 28, 2010 at 11:40 am
CirquedeSQLeil (8/28/2010)
Thanks Jeff for outlining it so well.
I may have made a slight mistake but the end result is the same. Let me figure out the mistake.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 28, 2010 at 12:10 pm
Heh... nah... I thought I made a mistake but I was... ummm.. mistaken. 🙂
The mistake is in BOL. They claim that there are 8096 bytes per row in that article. If there were, the 8 rows would fit on a single page.
{edit} There are 8096 bytes per row but they didn't account for the extra 36 bytes in any of the calculations according to the link Jason posted.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 28, 2010 at 1:39 pm
It appears I also made a mistake, I totally misunderstood the initial question.
I'm not going to go back over Jeff Moden's answer it's correct. However if you would like analyse this yourself you can use the following code:
--Find page number
DBCC IND ([DatabaseName], [TableName], -1)
--Find FileID
SELECT * FROM sys.database_files
--Read page
DBCC TRACEON(3604)
GO
DBCC PAGE([DatabaseName], [FileID], [Page], 1)
MCITP SQL Server 2005/2008 DBA/DBD
August 28, 2010 at 1:55 pm
It's always fun to look at that stuff at the byte level. Thanks for posting it, Brian. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
November 24, 2013 at 4:48 pm
November 25, 2013 at 1:27 am
Please note: 3 year old thread
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply