Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Execution Plan

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2004-08-12 : 08:58:18
Hi,
I would like to optimize a table which has about 50 Million records and increasing daily.
I was thinking of putting indexes in it.
I would also like to use the execution plan to see if it can suggest anything. What is the best way to take advantage of the execution plan, etc.
Thanks

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-08-12 : 09:12:33
"I was thinking of putting indexes in it."...think a lot more...it's a MAJOR must....both for performance and referential integrity...
"execution plan"....remove/minimise index/table scans....they are real bad news.

post sample code + ddl of the tables involved in the queries....and we should get you moving faster.
Go to Top of Page

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2004-08-12 : 10:07:08
what is ddl please?
Go to Top of Page

n/a
deleted

35 Posts

Posted - 2004-08-12 : 10:09:06
You might also want to look into horizontally partitioning the table and read up on Federated Databases. These require some programing, but can GREATLY increase speed of the database.

HTH
Paul
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-12 : 10:09:14
ddl is table schema (structure)

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-12 : 10:10:30
ddl is table schema (structure)

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-08-12 : 10:12:17
fmardani, post a create table statement and some inserts to give us some sample data. ddl would be the create table. dml would be the insert statements.

data definition
data modification

What is this table used for? Do you mean it doesn't have ANY indexes on it, or you just want to research what would be the optimum indexes.


MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2004-08-12 : 10:43:45
There are two tables that are joined together.
T_Headers --> contains nID (PK) clustered, tDateofData (datetime) non-clustered
This table is joined to T_Gcus --> contains fields --> nID (PK) clustered, HeaderID non-clustered,
10 more fields...

T_Headers is joined to T_Gcus via nID, i.e

select
h.tDateOfData, g.*
from
T_GcusA as g inner join T_Headers as h on g.HeaderID = h.nID
where
h.tDateOfData = '31 Dec 2003' and
g.AccountNumber = 'x123456' and
g.CusipNumber = 'P5432'

what indexes and which fields in which tables do I put them?

Currently I have placed indexes in these tables as described on top.
Thanks guys
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-08-12 : 10:51:09
speed will be improved with indices that support some or all of the the columns referenced in the joins + where conditions.

also....it is good SQL programming practice NOT to use the code format "select * from table"...instead...being particular with a style of "select col1, col2, col3, etc from table"...may enable indices to be used.
Go to Top of Page

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2004-08-12 : 10:58:05
Andrew,
Thanks for the input but my main query is where to place the indexes correctly based on my query. And also if it is any use, how can I benefit from execution plan?
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-08-12 : 11:00:21
So, basically, you are missing indexes on these columns:

h.tDateOfData = '31 Dec 2003' and
g.AccountNumber = 'x123456' and
g.CusipNumber = 'P5432'

You need to determine if these are used a lot. If so, and the increased performance in selects would outweigh the decrease in insert, update, and delete actions, then put indexes on them. On a fifty million row table, I would think this query would be incredibly slow without indexes on these columns.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2004-08-12 : 11:08:09
Yes derrik, I already have non-clustered indexes on the three mentioned columns.
Go to Top of Page

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2004-08-12 : 11:23:54
Hi guys,
It seems that I can not get the query any quicker than the way it is now (Which is kind of acceptable).
So thanks for your inputs ;-)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-08-13 : 08:12:16
I presume you ahve indexes on g.HeaderID and h.nID (the later is probably a PK anyway)

You could try making a composite index of h.tDateOfData + h.nID as SQL might be able to "cover" the use of the T_Headers table from the index

Perhaps horizontally partitioning your data would help.

Seeing the Query and the Query Plan would help make suggestions.

Kristen
Go to Top of Page
   

- Advertisement -