Re: Using multiple indices on a single table in a query

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Andrew J. Kelly (sqlmvpnooospam_at_shadhawk.com)
Date: 09/17/04


Date: Fri, 17 Sep 2004 15:36:35 -0400

1. Actually the caching is not done on a row by row basis. Everything in
memory and disk pretty much happens at he page or extent level. You will
never read a single row into memory unless there is only 1 row on a page. I
am not 100% sure where you are going with this but it is not necessary to
index every column or keep every row in cache. If you do something once a
day like a table scan for a distinct it is usually not worth keeping all
that data in cache at the expense of more frequently used data.

2. SQL Server is quite capable of using two indexes to find a common row.
This is called index intersection. But the conditions must be correct for
this to be more useful than the example you listed. Just because it didn't
use index intersection in your simple test does not mean it is not capable
of doing so. If the first index is selective enough (and especially if you
use * for the column list) the chances are it is less effort to do the
bookmark lookup and filter out the unwanted rows.

-- 
Andrew J. Kelly  SQL MVP
"Jami Bradley" <jbradley@isa-og.com> wrote in message
news:madmk0tvupsp07qcu14ioq0clj2l612pfg@4ax.com...
> Hi,
>
> Over the past several months I have been working on our schema (extending
and studying
> performance).  Two interesting thoughts on performance have come up:
>
> 1. AFAIK, caching of tables is done on a row by row basis.  It would be
interesting to cache by
> column.  Where this comes in handy is when certain commands are executed
infrequently (and they are
> not indexed).  For example, SELECT DISTINCT X FROM Y.  Of course, indexing
would dramatically help
> this query, but sometimes the columns just are worth indexing.  Now, if
the entire column were
> cached (the table is too large to cache in entirety), this would still be
pretty quick.
>
> Actually, a single column index is much like a column cache.  I just don't
feel like indexing every
> column individually :-)
>
>
> 2. Why don't queries make use of multiple indices on a single table in a
query?
> For example,  SELECT * FROM T WHERE a = aVal and b = bVal
> I could make an index on (a,b) which would work great for this query.
But, what if I had an index
> on (a) and a second index on (b).  You could use the intersection of the
two subsets and grab the
> rows from that list.  Instead what I see is an index seek on the more
selective index followed by a
> bookmark lookup to get the other column in the where clause.
>
> I can see why #1 might not be implemented - it is complex and a single
column index addresses most
> of it anyway.  But for #2, it seems like it would be really helpful in a
lot of cases.  Any other
> reasons why #2 isn't done?
>
> Thanks,
>
> Jami
>


Relevant Pages

  • Re: ARM926 caching question
    ... VIPT means that you can do the index lookup in parallel with the TLB ... PIPT-caching x86s do memory access instructions ... in 1 cycle (cache hit assumed) since 486, ... caching. ...
    (comp.arch.embedded)
  • Re: How does disk caching work?
    ... FreeBSD has a unified buffer cache. ... > MEMORY IS A BUFFER CACHE for all device IO. ... >> I think I know how caching memory mapped IO works for the most part, ...
    (freebsd-performance)
  • Re: Cache Memory in top command
    ... amount of memory used for caching: FreeBSD has a unified buffer cache ... so any memory is available for use as cache. ... The amount of cached file data pages is included in the Wired value ...
    (freebsd-questions)
  • Re: More optimisation
    ... If I want to perform actions on several large arrays, ... The best way is to look at the memory hiearchy of the processor you are using. ... Neither method uses caching particularly well. ... The organization of the cache system can still ...
    (comp.lang.c)
  • Re: Cached memory never gets released
    ... Stock linux 2.4.26 kernel. ... Due to flash bug 3M of memory gets lost due to font memory getting lost ... The output of "free" cache number steadily grows. ... longer to exhaust all of system memory with the cache. ...
    (Linux-Kernel)