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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:31:13+00:00 2026-06-14T14:31:13+00:00

I found some strange(for me) behavour in MySQL. I have a simple query: SELECT

  • 0

I found some strange(for me) behavour in MySQL. I have a simple query:

SELECT CONVERT( `text`.`old_text` 
USING utf8 ) AS stext
FROM  `text` 
WHERE  `text`.`old_id` IN 
(    
 SELECT  `revision`.`rev_text_id`
 FROM  `revision` 
 WHERE  `revision`.`rev_id`
 IN 
  (    
  SELECT `page_latest`
  FROM  `page` 
  WHERE `page_id` = 108
  )
)

when i run it, phpmyadmin show execution time of 77.0446 seconds.
But then i replace

WHERE  `text`.`old_id` IN 

by

WHERE  `text`.`old_id` = 

it’s execution time falls to about 0.001 sec. Result of this query

 SELECT  `revision`.`rev_text_id`
 FROM  `revision` 
 WHERE  `revision`.`rev_id`
 IN 
  (    
  SELECT `page_latest`
  FROM  `page` 
  WHERE `page_id` = 108
  )    

is

+------------+
|rev_text_id |
+------------+
|6506        |
+------------+

Can somebody please explain this behavour?

  • 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-06-14T14:31:14+00:00Added an answer on June 14, 2026 at 2:31 pm

    There are two primary ways you can increase your query performance here

    • Add Indexes (such as Kuya mentioned)
    • Rid yourself of the subqueries where possible

    For Indexes, add an index on the columns you are searching for your matches:
    text.old_id, revision.rev_text_id & page.page_id

    ALTER TABLE `text` ADD INDEX idx_text (old_id);
    ALTER TABLE `revision` ADD INDEX idx_revision (rev_text_id);
    ALTER TABLE `page` ADD INDEX idx_page (page_id);
    

    Your next issue is that nested-sub-selects are hell on your query execution plan. Here is a good thread discussing JOIN vs Subquery. Here is an article on how to get execution plan info from mySQL.

    First looks at an execution plan can be confusing, but it will be your best friend when you have to concern yourself with query optimization.

    Here is an example of your same query with just joins ( you could use inner or left and get pretty much the same result). I don’t have your tables or data, so forgive synax issues (there is no way I can verify the code works verbatim in your environment, but it should give you a good starting point).

    SELECT 
      CONVERT( `text`.`old_text` USING utf8 ) AS stext
      FROM  `text` 
      -- inner join only returns rows when it can find a 
      --    matching `revision`.`rev_text_id` row to `text`.`old_id`
      INNER JOIN `revision`  
      ON `text`.`old_id` = `revision`.`rev_text_id` 
      -- Inner Join only returns rows  when it can find a 
      --  matching `page_latest` row to `page_latest`
      INNER JOIN `page`
      ON `revision`.`rev_id` = `page`.`page_latest`
    WHERE `page`.`page_id` = 108
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am performing a simple multiplication with BigDecimal and I have found some strange
I'm hacking my way through learning Flex and have found some strange behaviour. When
I have learn OpenGL programming for some time.And I found a very strange phenomenon
I have found some strange syntax in python: int(array[0], 32) array[0] is some string,
During testing i found some thing strange in Xcode. I have a png of
I found some strange behavior when using nested Spring transactions: when, in the same
While answering this question I found some strange behavior for which I have no
I just found some strange behavior of database's order by clause. In string comparison,
I was experimenting with toCharArray() and found some strange behavior. Suppose private static final
I'm working on a heavily data-bound Win.Forms application where I've found some strange behavior.

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.