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 997457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:02:15+00:00 2026-05-16T07:02:15+00:00

UPDATE: Just to mention it on a more visible place. When I changed IN

  • 0

UPDATE:

Just to mention it on a more visible place. When I changed IN for =, the query execution time went from 180 down to 0.00008 seconds. Ridiculous speed difference.


This SQL query takes 180 seconds to finish! How is that possible? is there a way to optimize it to be faster?

SELECT IdLawVersionValidFrom 
FROM question_law_version 
WHERE IdQuestionLawVersion IN 
  (
  SELECT MAX(IdQuestionLawVersion) 
  FROM question_law_version 
  WHERE IdQuestionLaw IN 
    (
    SELECT MIN(IdQuestionLaw) 
    FROM question_law 
    WHERE IdQuestion=236 AND IdQuestionLaw>63
    )
  )

There are only about 5000 rows in each table so it shouldn’t be so slow.

  • 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-16T07:02:15+00:00Added an answer on May 16, 2026 at 7:02 am

    (Posting my comment as an answer as apparently it did make a difference!)

    Any difference if you change the IN
    to =?

    If anyone wants to investigate this further I’ve just done a test and found it very easy to reproduce.

    Create Table

    CREATE TABLE `filler` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      PRIMARY KEY (`id`)
    ) 
    

    Create Procedure

    CREATE PROCEDURE `prc_filler`(cnt INT)
    BEGIN
            DECLARE _cnt INT;
            SET _cnt = 1;
            WHILE _cnt <= cnt DO
                    INSERT
                    INTO    filler
                    SELECT  _cnt;
                    SET _cnt = _cnt + 1;
            END WHILE;
    END
    

    Populate Table

      call prc_filler(5000)
    

    Query 1

    SELECT id 
    FROM filler 
    WHERE id =  (SELECT MAX(id) FROM filler  WHERE id =   
     ( SELECT MIN(id) 
        FROM filler
        WHERE id between 2000 and 3000
        )
      )
    

    Equals Explain Output http://img689.imageshack.us/img689/5592/equals.png

    Query 2 (same problem)

    SELECT id 
    FROM filler 
    WHERE id in  (SELECT MAX(id) FROM filler  WHERE id in   
     ( SELECT MIN(id) 
        FROM filler
        WHERE id between 2000 and 3000
        )
      )
    

    In Explain Output http://img291.imageshack.us/img291/8129/52037513.png

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

Sidebar

Related Questions

Update: I just tested my JSON format returned from the server using JSONlint and
I was just reading an update from a friend's project, mentioning the use of
I have developed a windows forms c# application, i just want update items in
I just did an update of my SDK and now eclipse is giving me
I just used Android SDK Manager to update Android SDK Tools to revision 17,
I was just asked to update my settings in xcode as I was getting
I just installed Eclipse Galileo for Java developers and noticed that the update site
Update: Last night, I decided that this is just too much work to change
I just pulled https://github.com/kolanos/kohana-universe and now I'm trying to update all the modules running:
UPDATE: I have somewhat resolved the issue. Just in case if anyone runs in

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.