Showing posts with label index. Show all posts
Showing posts with label index. Show all posts

Friday, March 30, 2012

is it possible to re-build index without logging?

nt5, sql2k
i have a vendor application on one of my sql servers.
this application has many tables, and each tables have many indexes. it's
very write intensive (because when a record is inserted, it's insereted to
many many other tables, and that behavior can't be changed). the problem is
page split happened often, but when i tried to reindex tables once a week,
the log file run out of space.
can anyone offers some good solutions to my problem?
thank you!!
Steve
You can try changing the recovery mode to Bulk Logged or Simple and see if
that helps. Do only a few tables at a time and backup the log in between.
Andrew J. Kelly SQL MVP
"Steve Lin" <lins@.nospam.portptld.com> wrote in message
news:#otAPXEGEHA.3288@.TK2MSFTNGP12.phx.gbl...
> nt5, sql2k
>
> i have a vendor application on one of my sql servers.
> this application has many tables, and each tables have many indexes. it's
> very write intensive (because when a record is inserted, it's insereted to
> many many other tables, and that behavior can't be changed). the problem
is
> page split happened often, but when i tried to reindex tables once a week,
> the log file run out of space.
>
> can anyone offers some good solutions to my problem?
> thank you!!
>
> Steve
>
|||as i said, the database is write intensive. so simple recovery mode might be
too risky. is there a way to run a scheduled re-index job as a non-logged
operation?
thank you so much for the help.
steve
"Andrew J. Kelly" <sqlmvpnoooospam@.shadhawk.com> wrote in message
news:ujUS9aFGEHA.2876@.TK2MSFTNGP09.phx.gbl...
> You can try changing the recovery mode to Bulk Logged or Simple and see if
> that helps. Do only a few tables at a time and backup the log in between.
>
> --
> Andrew J. Kelly SQL MVP
>
> "Steve Lin" <lins@.nospam.portptld.com> wrote in message
> news:#otAPXEGEHA.3288@.TK2MSFTNGP12.phx.gbl...
it's
to
> is
week,
>
|||Checkout DBCC INDEXDEFRAG, which does online defragmentation. You can look
in BOL for details. There's also an excellent whitepaper at
http://www.microsoft.com/technet/pro.../ss2kidbp.mspx
which will give you a bunch of details, hints, and explanations - including
working out whether you even need to bother getting rid of fragmentation,
based on your workload.
Regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Steve Lin" <lins@.nospam.portptld.com> wrote in message
news:eDkxfqPGEHA.3324@.TK2MSFTNGP09.phx.gbl...
> as i said, the database is write intensive. so simple recovery mode might
be
> too risky. is there a way to run a scheduled re-index job as a non-logged
> operation?
> thank you so much for the help.
> steve
> "Andrew J. Kelly" <sqlmvpnoooospam@.shadhawk.com> wrote in message
> news:ujUS9aFGEHA.2876@.TK2MSFTNGP09.phx.gbl...
if
between.
> it's
insereted
> to
problem
> week,
>

is it possible to re-build index without logging?

nt5, sql2k
i have a vendor application on one of my sql servers.
this application has many tables, and each tables have many indexes. it's
very write intensive (because when a record is inserted, it's insereted to
many many other tables, and that behavior can't be changed). the problem is
page split happened often, but when i tried to reindex tables once a week,
the log file run out of space.
can anyone offers some good solutions to my problem?
thank you!!
SteveYou can try changing the recovery mode to Bulk Logged or Simple and see if
that helps. Do only a few tables at a time and backup the log in between.
Andrew J. Kelly SQL MVP
"Steve Lin" <lins@.nospam.portptld.com> wrote in message
news:#otAPXEGEHA.3288@.TK2MSFTNGP12.phx.gbl...
> nt5, sql2k
>
> i have a vendor application on one of my sql servers.
> this application has many tables, and each tables have many indexes. it's
> very write intensive (because when a record is inserted, it's insereted to
> many many other tables, and that behavior can't be changed). the problem
is
> page split happened often, but when i tried to reindex tables once a week,
> the log file run out of space.
>
> can anyone offers some good solutions to my problem?
> thank you!!
>
> Steve
>|||as i said, the database is write intensive. so simple recovery mode might be
too risky. is there a way to run a scheduled re-index job as a non-logged
operation?
thank you so much for the help.
steve
"Andrew J. Kelly" <sqlmvpnoooospam@.shadhawk.com> wrote in message
news:ujUS9aFGEHA.2876@.TK2MSFTNGP09.phx.gbl...
> You can try changing the recovery mode to Bulk Logged or Simple and see if
> that helps. Do only a few tables at a time and backup the log in between.
>
> --
> Andrew J. Kelly SQL MVP
>
> "Steve Lin" <lins@.nospam.portptld.com> wrote in message
> news:#otAPXEGEHA.3288@.TK2MSFTNGP12.phx.gbl...
it's
to
> is
week,
>|||Checkout DBCC INDEXDEFRAG, which does online defragmentation. You can look
in BOL for details. There's also an excellent whitepaper at
http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
which will give you a bunch of details, hints, and explanations - including
working out whether you even need to bother getting rid of fragmentation,
based on your workload.
Regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Steve Lin" <lins@.nospam.portptld.com> wrote in message
news:eDkxfqPGEHA.3324@.TK2MSFTNGP09.phx.gbl...
> as i said, the database is write intensive. so simple recovery mode might
be
> too risky. is there a way to run a scheduled re-index job as a non-logged
> operation?
> thank you so much for the help.
> steve
> "Andrew J. Kelly" <sqlmvpnoooospam@.shadhawk.com> wrote in message
> news:ujUS9aFGEHA.2876@.TK2MSFTNGP09.phx.gbl...
if
between.
> it's
insereted
> to
problem
> week,
>sql

Wednesday, March 21, 2012

Is it possible to create clustered index for multi tables within a SQL Server 2005 database with

Hi, all,

I am having up to serveral hundred tables within a SQL Server 2005 database, up to 200 of them are without any clustered index. Is it possible to create clustered indexes for all of them together in a same query? :)

Thanks a lot for any guidance and advices for that.

With best regards,

Yours sincerely,

Yes, it is possible with WHILE loop and dynamic SQL (with eithersp_executesql or EXEC statement) that calls CREATE INDEX. However, the tricky part is you have to specify the column(s) for each table to be included in the index in the CREATE INDEX statement. So if you have a way to programmatically get the table names and the index column(s) for each table, it is easy to do the rest.|||

Hi, Hugh Qu,

Thank you very much for your kind guidance and advices. Got the ideas, very appreciated.

With best regards,

Yours sincerely,

Is it possible to create clustered index for multi tables within a SQL Server 2005 database with

Hi, all,

I am having up to serveral hundred tables within a SQL Server 2005 database, up to 200 of them are without any clustered index. Is it possible to create clustered indexes for all of them together in a same query? :)

Thanks a lot for any guidance and advices for that.

With best regards,

Yours sincerely,

Yes, it is possible with WHILE loop and dynamic SQL (with eithersp_executesql or EXEC statement) that calls CREATE INDEX. However, the tricky part is you have to specify the column(s) for each table to be included in the index in the CREATE INDEX statement. So if you have a way to programmatically get the table names and the index column(s) for each table, it is easy to do the rest.|||

Hi, Hugh Qu,

Thank you very much for your kind guidance and advices. Got the ideas, very appreciated.

With best regards,

Yours sincerely,

Is it possible to create clustered index for multi tables within a SQL Server 2005 database

Hi, all,

I am having up to serveral hundred tables within a SQL Server 2005 database, up to 200 of them are without any clustered index. Is it possible to create clustered indexes for all of them together in a same query? :)

Thanks a lot for any guidance and advices for that.

With best regards,

Yours sincerely,

Yes, it is possible with WHILE loop and dynamic SQL (with either sp_executesql or EXEC statement) that calls CREATE INDEX. However, the tricky part is you have to specify the column(s) for each table to be included in the index in the CREATE INDEX statement. So if you have a way to programmatically get the table names and the index column(s) for each table, it is easy to do the rest.|||

Hi, Hugh Qu,

Thank you very much for your kind guidance and advices. Got the ideas, very appreciated.

With best regards,

Yours sincerely,

Wednesday, March 7, 2012

Is is possible to make index over datepart in datetime column?

For example, i want to make index over dd-mm-yyyy not including hh:mm:ss, or sometimes only mm-yyyy. Is this possible?Yes, that's possible, create a view and then index your view.

Friday, February 24, 2012

Is Index useful?

Hi
In a table A (currently holding approx. 4700 rows but will
expand during use) the primary key is a combination of
three columns col1, col2, col3.
The primary key is indexed with a clustered index
(FillFactor 90).
On the columns col1, col2 an nonclustred index have been
added (FillFactor 90) too, this because I guess these two
columns together form a foreign key to another table B
(currently holding approx 1000 rows - number will raise).
The two indexes are both sorted ascending for all values.
My assumption is that the nonclustered index are of no use
and only adds overhead to inserts etc., since both col1
and col2 allready are indexed (in same sequence and sort
order) in the clustered index, so a query on col1 and/or
col2, and a join between table A and B can already use the
clustered index values for the col1, col2 to speed up the
query and the join using a merge join.
Infact the DBCC SHOWSTATISTIC returns the exact same
result (density etc.) for both the clusterd and
nonclustered index (propably because the nonclustered
index after having scanned its only structure will point
to the clustered index anyway and use this afterwards - to
my recollection).
But does the extra col3 of the clustered index make it
useless for queries/order by/joins on only col1, col2?
or
Can I - with a good nights sleep in mind - just delete the
nonclustered index as it is superflous?
Kind regards
Jakob PerssonJacob
On which column(s) do you have clustered index?
What is mostly WHERE caluse in your queries?
If all three columns are participated in your query you probably want to
consider using COVERING index.
A clustered index is more useful where you try to retrive a set of data ( a
lot of rows) on other hand a non clustered index will be more useful where
you retrieve a single row.
Again it is depends upon you requriments, you will have to monitor your
query to find out an appropritate indexes
SET STATISTICS IO may be useful ,also look at excution plan of the query.
"Jakob Persson" <jakobpersson@.yahoo.dk> wrote in message
news:084601c3b8bc$173b71c0$a501280a@.phx.gbl...
> Hi
> In a table A (currently holding approx. 4700 rows but will
> expand during use) the primary key is a combination of
> three columns col1, col2, col3.
> The primary key is indexed with a clustered index
> (FillFactor 90).
> On the columns col1, col2 an nonclustred index have been
> added (FillFactor 90) too, this because I guess these two
> columns together form a foreign key to another table B
> (currently holding approx 1000 rows - number will raise).
> The two indexes are both sorted ascending for all values.
> My assumption is that the nonclustered index are of no use
> and only adds overhead to inserts etc., since both col1
> and col2 allready are indexed (in same sequence and sort
> order) in the clustered index, so a query on col1 and/or
> col2, and a join between table A and B can already use the
> clustered index values for the col1, col2 to speed up the
> query and the join using a merge join.
> Infact the DBCC SHOWSTATISTIC returns the exact same
> result (density etc.) for both the clusterd and
> nonclustered index (propably because the nonclustered
> index after having scanned its only structure will point
> to the clustered index anyway and use this afterwards - to
> my recollection).
> But does the extra col3 of the clustered index make it
> useless for queries/order by/joins on only col1, col2?
> or
> Can I - with a good nights sleep in mind - just delete the
> nonclustered index as it is superflous?
> Kind regards
> Jakob Persson
>|||Jakob,
>But does the extra col3 of the clustered index make it
>useless for queries/order by/joins on only col1, col2?
No. The index with col1, col2, col3 is just as useful as the one with col1, col2. So your thinking
is spot on. One thing is of course if col1 and col2 are very narrow and col3 is very wide, but that
is obvious.
Another, more important issue, is that the index on col1, col2 is an NC index which has other
characteristics than a clustered index. The optimizer might use this index to cover queries (or
partially cover), which can have significant performance gains compared to a clustered index.
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Jakob Persson" <jakobpersson@.yahoo.dk> wrote in message
news:084601c3b8bc$173b71c0$a501280a@.phx.gbl...
> Hi
> In a table A (currently holding approx. 4700 rows but will
> expand during use) the primary key is a combination of
> three columns col1, col2, col3.
> The primary key is indexed with a clustered index
> (FillFactor 90).
> On the columns col1, col2 an nonclustred index have been
> added (FillFactor 90) too, this because I guess these two
> columns together form a foreign key to another table B
> (currently holding approx 1000 rows - number will raise).
> The two indexes are both sorted ascending for all values.
> My assumption is that the nonclustered index are of no use
> and only adds overhead to inserts etc., since both col1
> and col2 allready are indexed (in same sequence and sort
> order) in the clustered index, so a query on col1 and/or
> col2, and a join between table A and B can already use the
> clustered index values for the col1, col2 to speed up the
> query and the join using a merge join.
> Infact the DBCC SHOWSTATISTIC returns the exact same
> result (density etc.) for both the clusterd and
> nonclustered index (propably because the nonclustered
> index after having scanned its only structure will point
> to the clustered index anyway and use this afterwards - to
> my recollection).
> But does the extra col3 of the clustered index make it
> useless for queries/order by/joins on only col1, col2?
> or
> Can I - with a good nights sleep in mind - just delete the
> nonclustered index as it is superflous?
> Kind regards
> Jakob Persson
>

Monday, February 20, 2012

Is B-Tree the only Index structure within SQL Server 2005 database?

Hi, All,

Is B-Tree the only Index structure used within SQL Server 2005 database?

Thanks a lot in advance for any guidance and advices for that.

With best regards,

Yours sincerely,

Yes, B-trees are the only index structure available. These are used for nonclustered indexes, and for clustered indexes. An unordered "heap" structure is used to store the data in tables with no clustered index.

Thanks,
--R

|||

Hi, Ryan, thanks a lot for your guidance.

With best regards,

Yours sincerely,

Is B-Tree the only Index structure within SQL Server 2005 database?

Hi, All,

Is B-Tree the only Index structure used within SQL Server 2005 database?

Thanks a lot in advance for any guidance and advices for that.

With best regards,

Yours sincerely,

Yes, B-trees are the only index structure available. These are used for nonclustered indexes, and for clustered indexes. An unordered "heap" structure is used to store the data in tables with no clustered index.

Thanks,
--R

|||

Hi, Ryan, thanks a lot for your guidance.

With best regards,

Yours sincerely,

Is bookmark in a nonclustered index ordered?

When a nonunique nonclustered index is built on top of a clustered
index, is it guaranteed that the bookmark in the nonclustered index
will be kept in the same order as the clustered index?

Here's an example to demonstrate my question:

CREATE TABLE indextest (col1 int NOT NULL,col2 int NOT NULL,col3
int,col4 int)
ALTER TABLE indextest ADD PRIMARY KEY CLUSTERED (col1,col2)
CREATE INDEX ix_indextest ON indextest (col1,col3)
GO
INSERT indextest VALUES (1,2,1,1)
INSERT indextest VALUES (1,3,2,1)
INSERT indextest VALUES (1,4,2,1)
INSERT indextest VALUES (2,1,1,1)
INSERT indextest VALUES (1,1,1,1)
SELECT col1,col2 FROM indextest WHERE col1=1 AND col3=1
DROP TABLE indextest

The select statement above is covered by the nonclustered index, so
that index is used. However, the nonclustered index is defined only to
ensure the ordering of col1 and col3 within the index; col1 and col2
follow within the index as the bookmark to the clustered index. When I
run this query, my desired result is to have the records appear in the
order supported by the clustered index:
1,1
1,2
As it happens, the result I got was indeed in that order, but I don't
know if it was mere coincidence, or if the bookmark in the nonclustered
index is maintained in the same order as the clustered index. If I
want to ensure the above order, is it sufficient to have the
nonclustered index defined as above, or do I need to define it as:
create index ix_indextest on indextest (col1,col3,col2)
just to be sure that the results are returned in ascending order for
col1,col2? If the two-column index is sufficient, is it guaranteed to
still be sufficient in SQL2005 and future versions of SQL Server, or am
I better off adding the third column just to be safe?

Thank you,
--Dennis CulleyAn index (clustered or non-clustered) shouldn't be relied upon to fix the
order in which rows are returned. There are no guarantees unless you use
ORDER BY in your query. Use ORDER BY and let the server decide which index
is most appropriate.

--
David Portas
SQL Server MVP
--|||Here's an example of why you cannot rely on the order of rows returned
unless you specifically use an ORDER BY. We have a concept of merry-go-round
scans. If two queries need to perform a range scan over an index, they can
share the same scan. Now, if query one starts before query two, we still
recognize that the scan we need for query two is already under way and we
piggy-back on it until it completes. However, because we hopped on it after
it had started, we need to go back to the start of the scan to read the rows
we missed. (e.g. query one scans and returns rows 1 to 100. Query two starts
when query one's scan is at row 46. Query two thus returns rows 46 to 100
plus 1 to 45)

Regards.

--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine

This posting is provided "AS IS" with no warranties, and confers no rights.

"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:WvidncyWk-E2CZnfRVn-hg@.giganews.com...
> An index (clustered or non-clustered) shouldn't be relied upon to fix the
> order in which rows are returned. There are no guarantees unless you use
> ORDER BY in your query. Use ORDER BY and let the server decide which index
> is most appropriate.
> --
> David Portas
> SQL Server MVP
> --|||Okay, good point. So if I include ORDER BY col1,col2 in the query, the
query plan I get back does not show an additional sorting operation.
Does that imply that SQL Server has ensured that the bookmarks will be
maintained in this order, because they're ordered that way in the
clustered index?

--Dennis Culley|||DC (cactuswren1@.hotmail.com) writes:
> Okay, good point. So if I include ORDER BY col1,col2 in the query, the
> query plan I get back does not show an additional sorting operation.
> Does that imply that SQL Server has ensured that the bookmarks will be
> maintained in this order, because they're ordered that way in the
> clustered index?

Yup. If you run the query with and without ORDER BY and compare the
popups, you will see that the one with ORDER BY includes a ORDERED FORWARD,
while the one without ORDER BY does not.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

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