Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Index Location? Expand / Collapse
Author
Message
Posted Monday, September 14, 2009 5:01 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 11, 2014 12:39 PM
Points: 310, Visits: 659
Index Location?

I have four filegroup FG1, FG2, FG3, FG4
Can anyone tell me in which filegroup my index will be located. I think this would be in the same filegroup where my table is located. M I correct?
This is told that the system file reside in primary filegroup only. This there any chance that the system files can be on any other secondary file?

-LK
Post #787324
Posted Monday, September 14, 2009 5:30 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, December 1, 2014 7:30 AM
Points: 2,128, Visits: 5,565
When you create the index, you can specify the file group that you want it be on. If you don’t specify where to create the index, it will be created on the same file group that the index’s table exists on.
Most system objects will be on the primary file group, but there are some system objects that will be on every file. For example GAM pages, SGAM pages, etc’ will be on every data file. System tables (such as sys.objects, sys.database_files, etc)’ will always reside on the primary file group.

Adi


--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #787344
Posted Monday, September 14, 2009 7:06 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 11, 2014 12:39 PM
Points: 310, Visits: 659
Adi here is one twist according to BOL:

"Because the leaf level of a clustered index and the data pages are the same by definition, creating a clustered index and using the ON partition_scheme_name or ON filegroup_name clause effectively moves a table from the filegroup on which the table was created to the new partition scheme or filegroup."

It means that the filegroup for clustered index and table will remain same. The non clustered indexes can be placed on a different filegroup.

-LK
Post #787418
Posted Monday, September 14, 2009 7:15 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,065, Visits: 4,639
luckysql.kinda (9/14/2009)
Adi here is one twist
that's not a twist, that's a "by design feature"


_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #787428
Posted Monday, September 14, 2009 7:52 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, December 1, 2014 7:30 AM
Points: 2,128, Visits: 5,565
This is done on purpose. When you create a clustered index on a heap you might want to move the table to a different file group, but you might want to keep the table on the same file group that it was created on. The table and clustered index have to be on the same file group, but when you create the clustered index if you won’t specify it’s location, it will be created on the same file group as the table. If you will specify a specific file group, it will be created on that file group and the table will be moved to this file group. The only difference when you create a clustered index or a nonclustered index, is that the table might be moved, but this has nothing to do with the way that the server “decides” on which file group the index will be created. At both cases (creating clustered and nonclustered index) the way this “decision” is dictated to the server by the user’s input.

Adi


--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #787472
Posted Monday, September 14, 2009 9:27 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,065, Visits: 4,639
Adi Cohn (9/14/2009)
This is done on purpose. When you create a clustered index on a heap you might want to move the table to a different file group, but you might want to keep the table on the same file group that it was created on. The table and clustered index have to be on the same file group, but when you create the clustered index if you won’t specify it’s location, it will be created on the same file group as the table. If you will specify a specific file group, it will be created on that file group and the table will be moved to this file group. The only difference when you create a clustered index or a nonclustered index, is that the table might be moved, but this has nothing to do with the way that the server “decides” on which file group the index will be created. At both cases (creating clustered and nonclustered index) the way this “decision” is dictated to the server by the user’s input.

Adi


I'm sorry but as written this is wrong.

The reason why a clustered index ALWAYS goes to the same filegroup the table goes is because the leaf level of the index is actually sitting inside the base table.


_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #787555
Posted Monday, September 14, 2009 9:49 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, December 1, 2014 7:30 AM
Points: 2,128, Visits: 5,565

I'm sorry but as written this is wrong.

The reason why a clustered index ALWAYS goes to the same filegroup the table goes is because the leaf level of the index is actually sitting inside the base table.


I never claimed that the clustered index will be on a different file group then the table. I do claim however that that when I create a clustered index, it doesn’t have to be created the same file group that the table already exists on. Of course when I create it on a different file group, the table will be transferred to the file group that the new clustered index will be created on. This means that sometime the clustered index will be created on the same file group as the table, but other times it will be created on a different file group and the table will be moved to this file group. Here is a small demo, that shows it:
--Creating a database with few file groups
CREATE DATABASE TestDB
ON
PRIMARY
(NAME = PrimaryFile,
FILENAME = 'c:\TestDB.mdf',
SIZE = 100MB),
FILEGROUP DefaultFileGroup
( NAME = DefaultFile,
FILENAME = 'c:\DefaultFile.ndf',
SIZE = 100MB)
LOG ON
(NAME = DemoDBLog,
FILENAME = 'c:\TestDB.ldf',
SIZE = 100MB)
go


use TestDB
go
-- Setting the default file group
ALTER DATABASE TestDB
MODIFY FILEGROUP DefaultFileGroup default
go

--Creating a demo table in the default file group
create table MyTable (i int not null) on DefaultFileGroup
go

--see that the table is created on the DefaultFileGroup
exec sp_help MyTable

--Adding a clustered index without speciying where it will be located
create clustered index cix_MyTable_i on MyTable (i) on [primary]
go

--The table is now on the primary data file and not on the default data file
sp_help MyTable

--cleanup
use master
go
drop database TestDB

Adi


--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #787574
Posted Tuesday, September 15, 2009 5:02 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 11, 2014 12:39 PM
Points: 310, Visits: 659
Awesome example Adi. Thanks

-lk
Post #788062
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse