Wednesday, March 21, 2012
Number of indexes can affect performance event in nearly read-only table?
day about 200 rows are inserted by an application, running as a
scheduled job.
So few writes per day are performed, but many reads are executed.
We have on this table 1 clustered index and 5 non-clustered indexes:
this is because the queryes applied to this table are very different,
and we have to use very different indexes.
Could the number of indexes affect performance, even if this is mainly
a read-only table?
Is there a 'maximum' number of indexes suggested for such large tables,
or i can build as many indexes as i want, nearly one for each 'where'
clause applied to the table?
Thnx i.a. for the answer
MarcoM. Simioni (m.simioni@.gmail.com) writes:
> Could the number of indexes affect performance, even if this is mainly
> a read-only table?
> Is there a 'maximum' number of indexes suggested for such large tables,
> or i can build as many indexes as i want, nearly one for each 'where'
> clause applied to the table?
The maximum number of tables is 250 if memory serves.
Can the number of index on a read-only table affect performance negatively?
Yes, from two different angles: 1) the optimizer gets more choices, and it
can take longer time to build the query plan. 2) the optimizer can pick an
index which it shouldn't. None of these issues should be given too much
weight. Most of the time the compilation time for a query is worth the
wait. And it's only occasionally the optimizer picks the wrong index. (But
I ran into that yesterday, when a customer got a problem with running a
stored procedure, and all that had happened was that I had added an index
to a table.)
So, if you feel that your table could benefit from more indexes, just do
adding them.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx
Monday, March 12, 2012
Nulls in indexes
If I have a column that allows NULLs and the majority of the queries that
run against the table look for rows when that column is NULL.
Would an index increase the performance of the query?
Thanks,
--AML--Possibly. NULL, seen from am index perspective, is just another value. But i
n the end, usefulness of
an index here is determined by selectivity (how many Null's do you have comp
ared to number of rows),
the query in whole (perhaps there are better indexes) and stuff like that.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Aaron M. Lowe" <alowe@.uic.edu> wrote in message news:e4TTDQ3PFHA.1236@.TK2MSFTNGP14.phx.gbl
..
> Hi,
> If I have a column that allows NULLs and the majority of the queries that
run against the table
> look for rows when that column is NULL.
> Would an index increase the performance of the query?
> Thanks,
> --AML--
>|||It might, if the majority of the rows are not NULL. In this case, the index
will be highly selective with regard to NULLs and a s
when you query for Col IS NULL. On the other hand, if most of the rows have
a NULL for that column, the index will not be selective and a scan will most
likely be used...
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"Aaron M. Lowe" <alowe@.uic.edu> wrote in message
news:e4TTDQ3PFHA.1236@.TK2MSFTNGP14.phx.gbl...
> Hi,
> If I have a column that allows NULLs and the majority of the queries that
> run against the table look for rows when that column is NULL.
> Would an index increase the performance of the query?
> Thanks,
> --AML--
>|||In addition to the other responses: this index may also be useful if it
is a covering index or clustered index.
Gert-Jan
"Aaron M. Lowe" wrote:
> Hi,
> If I have a column that allows NULLs and the majority of the queries that
> run against the table look for rows when that column is NULL.
> Would an index increase the performance of the query?
> Thanks,
> --AML--
Wednesday, March 7, 2012
NULL values and Indexes
1- NULL values is NOT good for a column that has an index
2- Therefore, all columns have default values of :
- 0 for numbers
- " " for strings
I honestly can't believe that it's a good idea to have all table columns
be filled with 1-2 space bar characters in order not to leave them
as NULL values.
Am i the only one who is confused about this approach? Is the
person doing this correct or wrong? And not just the columns that
have indexes on, all the columns are being set to ALLOW NULLS and
all of them are set with Default Values of (' ') for text fields and (0)
for
number fields.
Thank youOn Fri, 1 Apr 2005 22:57:23 -0500, "serge" <sergea@.nospam.ehmail.com>
wrote:
>Someone was explaining me the following:
>1- NULL values is NOT good for a column that has an index
>2- Therefore, all columns have default values of :
> - 0 for numbers
> - " " for strings
>I honestly can't believe that it's a good idea to have all table columns
>be filled with 1-2 space bar characters in order not to leave them
>as NULL values.
>Am i the only one who is confused about this approach? Is the
>person doing this correct or wrong? And not just the columns that
>have indexes on, all the columns are being set to ALLOW NULLS and
>all of them are set with Default Values of (' ') for text fields and (0)
>for
>number fields.
>
>Thank you
Time to be blunt here...
You are absolutely right.
You should not be confused at all.
NULL values can be very useful, especially on indexes, as an
indication of "index is not set" or "no index here", or "default
inherited index applies".
I use Null values extensively (in huge database systems) with not
only no problems whatsoever, but measurably signifcant advantages.
People who try to tell you that "Nulls are the work of the devil", or
:the sky will fall down if you allow nulls", or some such
unsubstantiated childish delusion are exclusively ignorant of the
correct ways to handle them.
(Or too lazy/ineducable to learn their correct implementation and/or
benefits.)
Fact, just plain indisputable fact.|||"serge" <sergea@.nospam.ehmail.com> wrote in message
news:EKo3e.24424$w63.1491786@.news20.bellglobal.com ...
> Someone was explaining me the following:
> 1- NULL values is NOT good for a column that has an index
> 2- Therefore, all columns have default values of :
> - 0 for numbers
> - " " for strings
> I honestly can't believe that it's a good idea to have all table columns
> be filled with 1-2 space bar characters in order not to leave them
> as NULL values.
Disk space is cheap, so this is not much of an objection.
> Am i the only one who is confused about this approach? Is the
> person doing this correct or wrong? And not just the columns that
> have indexes on, all the columns are being set to ALLOW NULLS and
> all of them are set with Default Values of (' ') for text fields and (0)
> for
> number fields.
Ultimately the concern is cardinality. If you have lots of NULLs the index
is less useful than an index with fewer NULLs.
Of course if you have lots of 0's or single spaces,the index is less useful.
>
> Thank you|||I don't think it's reasonable to imply that the ideas of people such as
Chris Date are based on ignorance or laziness. There are intelligent
arguments on both sides of the NULL debate.
Serge might want to refer to the works of Date, Darwen and Pascal for
contrary points-of-view on the problems with NULLs.
http://www.amazon.com/exec/obidos/t...0260307-5456631
http://www.dbdebunk.com/publications.html
As for saving a few bytes of storage, of all the reasons to use or not
to use NULLs that's probably the least important in my view.
--
David Portas
SQL Server MVP
--