Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SQL Index

SQL Index

SQL Index

I have the following query, but it runs a bit slow as the table consist of about 30 000 records, i want to know on which columns i must create what type of index to maximize the query?

select r_curcode, r_curdesc, to_char(r_sellrate,'999990.0000') as sellrate, to_char(r_buyrate,'999990.0000') as buyrate, to_char(r_buyairmail,'999990.0000') as buyairmail, to_char(r_buysurfmail,'999990.0000') as buysurfmail from someTable order by datesubmitted, timesubmitted desc limit 3

RE: SQL Index

Well I'd be inclined to put a Compound Index on DateSubmitted and TimeSubmitted.

CREATE INDEX Index_Name ON Table_Name (DateSubmitted, TimeSubmitted)

Then run your query through EXPLAIN and see the results (I think you may be surprised at them), if its not what you'd expect then create two indicies one for each column.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close