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

  • Home
  • SEARCH
  • 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 101833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:50:50+00:00 2026-05-11T00:50:50+00:00

I’m doing an ActiveRecord find operation (via the will_paginate library) like this: contacts =

  • 0

I’m doing an ActiveRecord find operation (via the ‘will_paginate’ library) like this:

  contacts = Contact.paginate(:all,     :conditions => conditions_specified,     :select => 'DISTINCT contacts.*',     :joins => joins,     :include => [:addresses, :emails, :phone_numbers, {:addresses => :organization}],     :page => page,     :per_page => @@PAGE_SIZE,     :order => 'last_name, first_name, middle_name') 

In the console, I get the output shown below. By setting the include parameter, I expect this to result in only one query. But in the output I’m seeing many queries. For example, I’m surprised to see the line…

  Address Load (2.5ms)   SELECT `addresses`.* FROM `addresses` WHERE (`addresses`.contact_id IN (94,106,104,108,121,55,40,75,62,4,67,36,77,64,7,35,24,68,57,117,8,30,85)) 

in the output below. (I understand that the SHOW FIELDS FROM queries are cached in production so that’s not a problem. It’s all the extra SELECTS I’m trying to figure out.)

Processing ContactController#index (for 127.0.0.1 at 2009-01-03 21:21:18) [GET]   Session ID: d453897c2f67c29c9a68d3fbc7b94f7b   ContactSearch Columns (4.4ms)   SHOW FIELDS FROM `contact_searches`   Contact Load (1.1ms)   SELECT DISTINCT contacts.* FROM `contacts` WHERE (contacts.last_name LIKE '%n%') ORDER BY last_name, first_name, middle_name LIMIT 0, 35   Contact Columns (2.3ms)   SHOW FIELDS FROM `contacts`   Address Load (2.5ms)   SELECT `addresses`.* FROM `addresses` WHERE (`addresses`.contact_id IN (94,106,104,108,121,55,40,75,62,4,67,36,77,64,7,35,24,68,57,117,8,30,85))   Address Columns (2.7ms)   SHOW FIELDS FROM `addresses`   Email Load (1.7ms)   SELECT `emails`.* FROM `emails` WHERE (`emails`.contact_id IN (94,106,104,108,121,55,40,75,62,4,67,36,77,64,7,35,24,68,57,117,8,30,85))   Email Columns (1.8ms)   SHOW FIELDS FROM `emails`   PhoneNumber Load (3.3ms)   SELECT `phone_numbers`.* FROM `phone_numbers` WHERE (`phone_numbers`.contact_id IN (94,106,104,108,121,55,40,75,62,4,67,36,77,64,7,35,24,68,57,117,8,30,85))   PhoneNumber Columns (3.0ms)   SHOW FIELDS FROM `phone_numbers`   Organization Columns (2.9ms)   SHOW FIELDS FROM `organizations`   Organization Load (0.9ms)   SELECT * FROM `organizations` WHERE (`organizations`.`id` IN (99,116,44,6,23,78,107,91,79,119,14,120,71,26,59,94,27,100,62,1,51,29,30,2,65,76,5)) Rendering template within layouts/main Rendering contact/index Rendered contact/_field_function_specifier (0.9ms) Rendered contact/_field_function_specifier (0.6ms) Rendered contact/_field_function_specifier (0.6ms) Rendered contact/_field_function_specifier (0.6ms) Rendered contact/_field_function_specifier (0.6ms) Rendered contact/_field_function_specifier (0.6ms) Rendered contact/_field_function_specifier (0.6ms) Rendered contact/_field_function_specifier (0.6ms) Rendered contact/_field_function_specifier (0.6ms) Rendered contact/_field_function_specifier (0.6ms) Rendered contact/_search_form (14.1ms) Rendered contact/_quick_view_contact_info (3.2ms) Rendered contact/_quick_view_contact_info (2.1ms) Rendered contact/_quick_view_contact_info (1.9ms) Rendered contact/_quick_view_contact_info (1.9ms) Rendered contact/_quick_view_contact_info (0.8ms) Rendered contact/_quick_view_contact_info (2.0ms) Rendered contact/_quick_view_contact_info (2.4ms) Rendered contact/_quick_view_contact_info (1.7ms) Rendered contact/_quick_view_contact_info (1.4ms) Rendered contact/_quick_view_contact_info (1.7ms) Rendered contact/_quick_view_contact_info (2.2ms) Rendered contact/_quick_view_contact_info (1.5ms) Rendered contact/_quick_view_contact_info (2.0ms) Rendered contact/_quick_view_contact_info (1.7ms) Rendered contact/_quick_view_contact_info (1.8ms) Rendered contact/_quick_view_contact_info (3.6ms) Rendered contact/_quick_view_contact_info (2.2ms) Rendered contact/_quick_view_contact_info (2.2ms) Rendered contact/_quick_view_contact_info (1.9ms) Rendered contact/_quick_view_contact_info (1.7ms) Rendered contact/_quick_view_contact_info (2.0ms) Rendered contact/_quick_view_contact_info (2.1ms) Rendered contact/_quick_view_contact_info (1.9ms) Completed in 308ms (View: 104, DB: 27) | 200 OK [http://localhost/contact] 
  • 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. 2026-05-11T00:50:51+00:00Added an answer on May 11, 2026 at 12:50 am

    I did a little more research and found the answer. I’m updating this for those who search later. The long answer is in this blog post.

    It appears that when you do a find that has both joins and a limit, ActiveRecord has to first query the main table to get the IDs of the rows to return, then redo the query using just the IDs in order to apply the limit.

    Since I was using will_paginate, that’s what happened as will_paginate used limited queries to do the pagination.

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

Sidebar

Ask A Question

Stats

  • Questions 79k
  • Answers 79k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You simply use another HttpWebRequest object and provided that you… May 11, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer That would require spoofing a non-local IP address in requests… May 11, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer I believe it should work if you Change the declaration… May 11, 2026 at 4:00 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.