views:

70

answers:

1

Hi folks,

I'm using sql server 2008 and have started to find using Indexed Views are helping me speed up some of my queries ... as my schema isn't basic.

So, if i have a table that is the following...

**ParentTable
ParentId INT PK IDENTITY
Name VARCHAR(MAX)

**ChildTable
ChildId INT PK IDENTITY
ParentId INT (FK to the table above)
Name VARCHAR(MAX)
Boundary GEOGRAPHY
CentrePoint GEOGRAPHY
CentrePointFlattened GEOMETRY

So for each row in the parent table, it can have zero to many children.

Firstly, if I make an index'd view of the children, it won't work if the ParentId filed can be nullable. So i need to make it required.

Now the question.

I have an index view of the children table inner join'd to the parent table (note i'm only indexing some of the fields from either table)...

(pseduo sql code)
ParentId INT
Name VARCHAR(MAX) AS ParentName
ChildId INT
Name VARCHAR(MAX) as ChildName
Boundary GEOGRAPHY

Now, are the data for these 5 fields serialized/copied to ANOTHER location again ? or does the index view only create some index id's that is the data for the table?

+2  A: 

Yes. Indexed view is basically another invisible table that gets updated automatically as underlying tables change.

Mehrdad Afshari
but what's the content of that table? the same stuff as the original table? so i would have TWO copies of the GEOGRAPHY data? or is this 2nd _invisible_ table just numbers, which are index's to the various columns, etc?
Pure.Krome
The "result of querying view" (whatever column included in the view) will be stored in the index. Just like a table that stores all column data. Pointers to the original table rows are not stored (there is not necessarily a one to one relationship between data in the view and the backing tables, think of joins and computed stuff)
Mehrdad Afshari
holy molly! i might explain why my db size is... well, getting massive :P
Pure.Krome