Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    62

    Unanswered: What to index on this query?

    Dear all,
    this is my query
    select to_char(updated,'DD-MON-YYYY'),count(id) total from mylog table
    g r o u p by to_char(updated,'DD-MON-YYYY')

    Sample data
    1234 22-MAY-2005 13:01

    I have 922276 data in mylog table. The result will return 33331. I have indexed the updated field with normal index. The results , i suffered 22 seconds to query it with
    1. table scans rows = 922276
    2. physical reads =33331


    Can anyone help me on how to improve my query.
    Thank you in advance

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >Can anyone help me on how to improve my query.
    Since you have no WHERE clause, no index will speed up this query.
    You are getting more than 1000 reads (I/O persecond) or less than 1 millisecond per read; which is typical or better for PC hardware.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jul 2004
    Posts
    62
    Dear anacedent,
    I have indexed the updated field with normal index, and let say i have the where clause for the updated fields, should it improves a lot

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    What does your benchmark show?
    Either it does or it does now.
    Why are you asking me?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by anacedent
    Since you have no WHERE clause, no index will speed up this query.
    I don't think so. As he is using a GROUP BY (which implicitely needs to do sorting) I would expect that an index:

    CREATE INDEX ON mylog (to_char(updated,'DD-MON-YYYY'))

    could speed up the query. But you will need to verify that with an EXPLAIN PLAN to be sure

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •