If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > put all columns in one index or create one index per column

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-03-09, 02:28
farax_x farax_x is offline
Registered User
 
Join Date: Sep 2009
Posts: 16
put all columns in one index or create one index per column

Hi,
For reach best performance, its better to put all columns in one index or create one index per column that must have index ?
Reply With Quote
  #2 (permalink)  
Old 11-03-09, 04:10
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Farax x - probably neither.
It sounds like you don't know too much about indexes but have heard that having some "speeds things up". it is also true that having some indexes can "slow things down".

I would either read up on indexing in SQL Server, or run all you queries against your database and then run the Database Tuning Advisor to find out what queries are recommended. The former is the better plan, the latter is quick, dirty and cheap but won't give you an optimal set up.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #3 (permalink)  
Old 11-03-09, 05:07
mishaalsy mishaalsy is offline
Registered User
 
Join Date: Aug 2009
Posts: 262
None of above / both / one of above.

depending upon your table structure , data , NOT NUMBER OF ROWS, relation , dml .

best performance comes with no index in sql-server ( unlinke oracle)
and when needed adding up an index to the column as per required by the query .

but now you have an option of index-referencing in select statement . This gives you a robust option to index your query according to your specification.
Reply With Quote
  #4 (permalink)  
Old 11-03-09, 07:52
farax_x farax_x is offline
Registered User
 
Join Date: Sep 2009
Posts: 16
thanx alot for your answer
Quote:
Originally Posted by mishaalsy View Post
None of above / both / one of above.

depending upon your table structure , data , NOT NUMBER OF ROWS, relation , dml .

best performance comes with no index in sql-server ( unlinke oracle)
and when needed adding up an index to the column as per required by the query .

but now you have an option of index-referencing in select statement . This gives you a robust option to index your query according to your specification.
Reply With Quote
  #5 (permalink)  
Old 11-03-09, 09:31
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,002
Quote:
Originally Posted by mishaalsy View Post
best performance comes with no index in sql-server
Come again?
__________________
George
Twitter | Blog
Reply With Quote
  #6 (permalink)  
Old 11-03-09, 09:52
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,556
Quote:
Originally Posted by gvee View Post
Quote:
Originally Posted by mishaalsy View Post
best performance comes with no index in sql-server
Come again?
He said the best performance comes with no index in sql-server.
Wait...what?
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #7 (permalink)  
Old 11-03-09, 09:54
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,556
Quote:
Originally Posted by farax_x View Post
Hi,
For reach best performance, its better to put all columns in one index or create one index per column that must have index ?
Depends on how you are going to search your data.
If you are going to join or filter on one column at a time, create separate indexes.
If you are usually going to join or filter on multiple columns (often the case if you are using natural keys rather than surrogates), then use a composite index.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #8 (permalink)  
Old 11-03-09, 09:57
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
...but the nature of those joins and the nature of those filters, as well as the nature of the data, are also considerations on whether or not you index those columns. There is also the whole clustered Vs nonclustered issue.
I think the OP is of too much an uninformed mind to really be able to make much of that advice.

And I couldn't make sense of much mishaalsy said
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #9 (permalink)  
Old 11-03-09, 10:25
Brett Kaiser Brett Kaiser is offline
SQLTeam Scrub
 
Join Date: Nov 2002
Location: Jersey
Posts: 9,984
Index Intercourse....ummm...intersection!!!
__________________
Brett
8-)

It's a Great Day for America everybody!
My Blog
My SQL Blog dbforums Yak CorralRadio 'Rita
dbForums Member List SQLTeam Member List
It's 5:00 Somewhere Pearls
The physical order of data in a database has no meaning.
Reply With Quote
  #10 (permalink)  
Old 11-03-09, 11:19
farax_x farax_x is offline
Registered User
 
Join Date: Sep 2009
Posts: 16
Quote:
Originally Posted by pootle flump View Post
Farax x - probably neither.
It sounds like you don't know too much about indexes but have heard that having some "speeds things up". it is also true that having some indexes can "slow things down".

I would either read up on indexing in SQL Server, or run all you queries against your database and then run the Database Tuning Advisor to find out what queries are recommended. The former is the better plan, the latter is quick, dirty and cheap but won't give you an optimal set up.
sorry, may be i explain my question badly.I have a table with 10 million records, and i created Separate index for each index-needed columns . my question is :
its better put all columns together in one index or this situation is the best.
Reply With Quote
  #11 (permalink)  
Old 11-03-09, 11:23
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Again, it depends. I'm afraid there is no "oh it's best to have them all in one column" or "it's best to have them all in different columns".

Indexing is difficult if you don't know a great deal about it but easy when you do. You would be best to read the BoL entries on indexing and then try asking something more specific.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #12 (permalink)  
Old 11-03-09, 11:37
farax_x farax_x is offline
Registered User
 
Join Date: Sep 2009
Posts: 16
Quote:
Originally Posted by pootle flump View Post
Again, it depends. I'm afraid there is no "oh it's best to have them all in one column" or "it's best to have them all in different columns".

Indexing is difficult if you don't know a great deal about it but easy when you do. You would be best to read the BoL entries on indexing and then try asking something more specific.
can u tell me, when should put several column in one index ?
Reply With Quote
  #13 (permalink)  
Old 11-03-09, 11:38
Brett Kaiser Brett Kaiser is offline
SQLTeam Scrub
 
Join Date: Nov 2002
Location: Jersey
Posts: 9,984
Want to post the DDL and some sample queries you are using?
__________________
Brett
8-)

It's a Great Day for America everybody!
My Blog
My SQL Blog dbforums Yak CorralRadio 'Rita
dbForums Member List SQLTeam Member List
It's 5:00 Somewhere Pearls
The physical order of data in a database has no meaning.
Reply With Quote
  #14 (permalink)  
Old 11-03-09, 13:13
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,556
Quote:
Originally Posted by farax_x View Post
can u tell me, when should put several column in one index ?
Uhm....I already did. Read my post.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #15 (permalink)  
Old 11-03-09, 14:04
Brett Kaiser Brett Kaiser is offline
SQLTeam Scrub
 
Join Date: Nov 2002
Location: Jersey
Posts: 9,984
OK, besides all the fun and games...

Understand 1 thing

Only the 1st column will make the optimizer decide what index to use

So, putting all the columns in an index, lets say from a phonebook table is useless, if the list of columns are phone_num, Last_name, first_name, ect

AND you were looking up by last name

it would NEVER use that index and would scan...it MIGHT scan the index depending on the number of columns in your select vs. the columns in the table, vs. the columns in the index

So you see....we need to know what the barrel of data is, and how you want to go after it

There's some exotic stuff like merry-go-round scans...but don't think about

The Index Intersection thing however might be beneficial

But you can do some reading

Understanding SQL Server Indexing

SQL Server Index Basics

General Tips on Optimizing SQL Server Indexes

SQL Server Indexes: The Basics - SQLTeam.com
__________________
Brett
8-)

It's a Great Day for America everybody!
My Blog
My SQL Blog dbforums Yak CorralRadio 'Rita
dbForums Member List SQLTeam Member List
It's 5:00 Somewhere Pearls
The physical order of data in a database has no meaning.
Reply With Quote
Reply

Tags
index

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On