Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7544321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:38:42+00:00 2026-05-30T08:38:42+00:00

I have a table orders on an MS SQL 2008R2 server orders has a

  • 0

I have a table orders on an MS SQL 2008R2 server
orders has a primary key of id
orders has a column called ordering_date that is type datetime
I created an index of column ordering_date called ordering_date_ndx on the server using a snippet of SQL. I did try to use a migration, but running the migration timed-out on this table of 23 million records.

2 Questions:

  1. What, if anything, should I put in app/models/order.rb to make use
    of the index.
  2. Will code like this make use of the presence of the index and optimize the SQL query?
list=Orders.find(ordering_date.year == 2006)

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:38:44+00:00Added an answer on May 30, 2026 at 8:38 am

    Afaik Rails doesn’t care about indexes on databases. There is no query optimization on the basis of indexes in Rails. If you do sorting or filtering on a column (especially on big tables) it’s helpful to add indexes. This helps your database server to do these operations more effective.

    However the better approach to add an index is to let Rails do it via migrations than doing it manually. It could be if a SQL snipped as well. This ensures that the index is in place on all environments and servers.

    Why this takes to long in Rails I have no idea. But you can run SQL in a migration:

    def up
      execute "ALTER TABLE orders ADD UNIQUE ordering_date_ndx (ordering_date)"
    end
    

    I don’t know about MS SQL syntax but I guess it can be adapted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table in my SQL Server database called OrderDetail which stores the order
In SQL Server 2008 I have a Table- Fruits Items Orders Bananas 6 Bananas
I'm using SQL Server 2008 R2 and have a simple table with a column
I have a table called ORDEREXECUTIONS that stores all orders that have been executed.
In MS Transact SQL, let's say I have a table (Orders) like this: Order
I have one table orders with a foreing key ProductID. I want to show
I also have a very large table in SQL Server (2008 R2 Developer Edition)
I have an Orders table that stores the Ordernumber as NVarChar. We manually increment
In a SQL Server 2008R2 sproc, I have the following code to calculate the
for SQL Server 2008 R2 I have a resultset that looks like this (note

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.