dbTalk Databases Forums  

Table not optimized or what ?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Table not optimized or what ? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
MAB
 
Posts: n/a

Default Table not optimized or what ? - 09-04-2003 , 12:44 AM






I have two tables in SQL 6.5 database with identical fields and indexes. One
contains the data of August 2003 and other July 2003. Now the august table
is larger ( about 40000 more rows ) than the july table but i've noticed
that the same queries perform much faster on the august table than the july
table. Ive tried this with many different queries so i'm wondering whats the
reason behind this. Is there a way to optimize a table? Remember , I'm using
SQL 6.5


thx



Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Table not optimized or what ? - 09-04-2003 , 02:04 AM






MAB (IVZXKLCJFSFLSDFA (AT) yahoo (DOT) com) writes:
Quote:
I have two tables in SQL 6.5 database with identical fields and indexes.
One contains the data of August 2003 and other July 2003. Now the august
table is larger ( about 40000 more rows ) than the july table but i've
noticed that the same queries perform much faster on the august table
than the july table. Ive tried this with many different queries so i'm
wondering whats the reason behind this. Is there a way to optimize a
table? Remember , I'm using SQL 6.5
Without seeing the CREATE TABLE and CREATE INDEX statemetns for the tables
it is difficult to tell. But one possibilty is that the July table suffers
more from fragmentation. DBCC SHOWCONTIG can give some information. With
DBCC DBREINDEX you can rebuild the indexes to reduce fragmentation.


--
Erland Sommarskog, SQL Server MVP, sommar (AT) algonet (DOT) se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


Reply With Quote
  #3  
Old   
MAB
 
Posts: n/a

Default Re: Table not optimized or what ? - 09-04-2003 , 04:59 AM




Erland Sommarskog <sommar (AT) algonet (DOT) se> wrote

Quote:
MAB (IVZXKLCJFSFLSDFA (AT) yahoo (DOT) com) writes:
I have two tables in SQL 6.5 database with identical fields and indexes.
One contains the data of August 2003 and other July 2003. Now the august
table is larger ( about 40000 more rows ) than the july table but i've
noticed that the same queries perform much faster on the august table
than the july table. Ive tried this with many different queries so i'm
wondering whats the reason behind this. Is there a way to optimize a
table? Remember , I'm using SQL 6.5

Without seeing the CREATE TABLE and CREATE INDEX statemetns for the tables
it is difficult to tell. But one possibilty is that the July table suffers
more from fragmentation. DBCC SHOWCONTIG can give some information. With
DBCC DBREINDEX you can rebuild the indexes to reduce fragmentation.
CREATE TABLE dbo.Aug2003Calls (
NASIdentifier varchar (16) NOT NULL ,
NASPort int NOT NULL ,
AcctSessionID varchar (10) NOT NULL ,
AcctStatusType tinyint NOT NULL ,
CallDate smalldatetime NOT NULL ,
UserName varchar (32) NOT NULL ,
UserService tinyint NULL ,
AcctDelayTime int NULL ,
AcctSessionTime int NULL ,
FramedProtocol int NULL ,
FramedAddress varchar (16) NULL ,
AcctInputOctets int NULL ,
AcctOutputOctets int NULL ,
AcctTerminateCause tinyint NULL ,
NASPortType tinyint NULL ,
NASPortDNIS varchar (10) NULL ,
CallerId varchar (16) NULL ,
FramedCompression int NULL ,
FramedNetmask int NULL ,
ModemSlotNo int NULL ,
ModemPortNo int NULL ,
XmitRate int NULL ,
AscendDataRate int NULL ,
AscendDisconnectCause int NULL ,
AscendConnectProgress int NULL ,
AcctLinkCount int NULL ,
AscendModemShelfNo int NULL
)
GO

CREATE INDEX idxAug2003Calls ON dbo.Aug2003Calls(CallDate, UserName)
GO


CREATE TABLE dbo.Jul2003Calls (
NASIdentifier varchar (16) NOT NULL ,
NASPort int NOT NULL ,
AcctSessionID varchar (10) NOT NULL ,
AcctStatusType tinyint NOT NULL ,
CallDate smalldatetime NOT NULL ,
UserName varchar (32) NOT NULL ,
UserService tinyint NULL ,
AcctDelayTime int NULL ,
AcctSessionTime int NULL ,
FramedProtocol int NULL ,
FramedAddress varchar (16) NULL ,
AcctInputOctets int NULL ,
AcctOutputOctets int NULL ,
AcctTerminateCause tinyint NULL ,
NASPortType tinyint NULL ,
NASPortDNIS varchar (10) NULL ,
CallerId varchar (16) NULL ,
FramedCompression int NULL ,
FramedNetmask int NULL ,
ModemSlotNo int NULL ,
ModemPortNo int NULL ,
XmitRate int NULL ,
AscendDataRate int NULL ,
AscendDisconnectCause int NULL ,
AscendConnectProgress int NULL ,
AcctLinkCount int NULL ,
AscendModemShelfNo int NULL
)
GO

CREATE INDEX idxJul2003Calls ON dbo.Jul2003Calls(CallDate, UserName)
GO







Reply With Quote
  #4  
Old   
Gert-Jan Strik
 
Posts: n/a

Default Re: Table not optimized or what ? - 09-04-2003 , 02:08 PM



With SQL 6.5, it is very important that you create a clustered index on
each table. In this case, you could change your CREATE INDEX ... into
CREATE CLUSTERED INDEX ...

Without a clustered index, running DBCC DBREINDEX will not eliminate the
(possible) fragmentation.

Hope this helps,
Gert-Jan


MAB wrote:
Quote:
Erland Sommarskog <sommar (AT) algonet (DOT) se> wrote in message
news:Xns93EC5C285609EYazorman (AT) 127 (DOT) 0.0.1...
MAB (IVZXKLCJFSFLSDFA (AT) yahoo (DOT) com) writes:
I have two tables in SQL 6.5 database with identical fields and indexes.
One contains the data of August 2003 and other July 2003. Now the august
table is larger ( about 40000 more rows ) than the july table but i've
noticed that the same queries perform much faster on the august table
than the july table. Ive tried this with many different queries so i'm
wondering whats the reason behind this. Is there a way to optimize a
table? Remember , I'm using SQL 6.5

Without seeing the CREATE TABLE and CREATE INDEX statemetns for the tables
it is difficult to tell. But one possibilty is that the July table suffers
more from fragmentation. DBCC SHOWCONTIG can give some information. With
DBCC DBREINDEX you can rebuild the indexes to reduce fragmentation.

CREATE TABLE dbo.Aug2003Calls (
NASIdentifier varchar (16) NOT NULL ,
NASPort int NOT NULL ,
AcctSessionID varchar (10) NOT NULL ,
AcctStatusType tinyint NOT NULL ,
CallDate smalldatetime NOT NULL ,
UserName varchar (32) NOT NULL ,
UserService tinyint NULL ,
AcctDelayTime int NULL ,
AcctSessionTime int NULL ,
FramedProtocol int NULL ,
FramedAddress varchar (16) NULL ,
AcctInputOctets int NULL ,
AcctOutputOctets int NULL ,
AcctTerminateCause tinyint NULL ,
NASPortType tinyint NULL ,
NASPortDNIS varchar (10) NULL ,
CallerId varchar (16) NULL ,
FramedCompression int NULL ,
FramedNetmask int NULL ,
ModemSlotNo int NULL ,
ModemPortNo int NULL ,
XmitRate int NULL ,
AscendDataRate int NULL ,
AscendDisconnectCause int NULL ,
AscendConnectProgress int NULL ,
AcctLinkCount int NULL ,
AscendModemShelfNo int NULL
)
GO

CREATE INDEX idxAug2003Calls ON dbo.Aug2003Calls(CallDate, UserName)
GO

CREATE TABLE dbo.Jul2003Calls (
NASIdentifier varchar (16) NOT NULL ,
NASPort int NOT NULL ,
AcctSessionID varchar (10) NOT NULL ,
AcctStatusType tinyint NOT NULL ,
CallDate smalldatetime NOT NULL ,
UserName varchar (32) NOT NULL ,
UserService tinyint NULL ,
AcctDelayTime int NULL ,
AcctSessionTime int NULL ,
FramedProtocol int NULL ,
FramedAddress varchar (16) NULL ,
AcctInputOctets int NULL ,
AcctOutputOctets int NULL ,
AcctTerminateCause tinyint NULL ,
NASPortType tinyint NULL ,
NASPortDNIS varchar (10) NULL ,
CallerId varchar (16) NULL ,
FramedCompression int NULL ,
FramedNetmask int NULL ,
ModemSlotNo int NULL ,
ModemPortNo int NULL ,
XmitRate int NULL ,
AscendDataRate int NULL ,
AscendDisconnectCause int NULL ,
AscendConnectProgress int NULL ,
AcctLinkCount int NULL ,
AscendModemShelfNo int NULL
)
GO

CREATE INDEX idxJul2003Calls ON dbo.Jul2003Calls(CallDate, UserName)
GO

Reply With Quote
  #5  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Table not optimized or what ? - 09-04-2003 , 04:24 PM



MAB (IVZXKLCJFSFLSDFA (AT) yahoo (DOT) com) writes:
Quote:
CREATE TABLE dbo.Aug2003Calls (
...
)
GO

CREATE INDEX idxAug2003Calls ON dbo.Aug2003Calls(CallDate, UserName)
GO


CREATE TABLE dbo.Jul2003Calls (
...
GO

CREATE INDEX idxJul2003Calls ON dbo.Jul2003Calls(CallDate, UserName)
GO
I can only echo Gert-Jan's suggestion to add a clustered index. Overall
a single non-clustered on a table which appears to be used for statistical
purposes appears to me overly modest.


--
Erland Sommarskog, SQL Server MVP, sommar (AT) algonet (DOT) se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.