Indexing Date/Time fields.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Bartkus

    #1

    Indexing Date/Time fields.

    If we have a date/time field and are doing frequent queries
    WHERE {date/time field} BETWEEN TimeA AND TimeB

    Does it make sense, query speed wise, to create an index on the date/time
    field?

    The reason I ask is that TimeA and TimeB are significant down to seconds.
    My *assumption* is that with a large amount of data scatter very few records
    will contain duplicate date/time points. And that under these circumstances,
    indexing will be of little value since every date/time point will need to be
    examined in detail. Date/time fields are actually floating point numbers
    after all.

    In other words, the assumption I am making is that if most of the data in a
    field is unique, then indexing will yield little or no query performance
    benefit.

    Is my "assumption " valid?
    Would an index on the date/time field speed up this type of query?

    Thomas Bartkus


  • Thomas Bartkus

    #2
    Re: Indexing Date/Time fields.

    "Thomas Bartkus" <tom@dtsam.co m> wrote in message
    news:5aidnTw4SL Kj0njcRVn-hw@telcove.net. ..[color=blue]
    > If we have a date/time field and are doing frequent queries
    > WHERE {date/time field} BETWEEN TimeA AND TimeB
    >
    > Does it make sense, query speed wise, to create an index on the date/time
    > field?
    >
    > The reason I ask is that TimeA and TimeB are significant down to seconds.
    > My *assumption* is that with a large amount of data scatter very few[/color]
    records[color=blue]
    > will contain duplicate date/time points. And that under these[/color]
    circumstances,[color=blue]
    > indexing will be of little value since every date/time point will need to[/color]
    be[color=blue]
    > examined in detail. Date/time fields are actually floating point numbers
    > after all.
    >
    > In other words, the assumption I am making is that if most of the data in[/color]
    a[color=blue]
    > field is unique, then indexing will yield little or no query performance
    > benefit.
    >
    > Is my "assumption " valid?
    > Would an index on the date/time field speed up this type of query?[/color]

    Okay. I'll answer my own question just in case anyone is interested.

    I ran a few tests and my assumption was *wrong*.

    Indexing on a field that contains mostly or entirely discrete values helps
    the query speed substantially. Indexing on date/time fields or floating
    point fields with lots of data scatter does speed up queries involving those
    fields in a WHERE clause restriction.

    This was a surprise to me!
    Thomas Bartkus




    Comment

    Working...