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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:00:26+00:00 2026-06-17T07:00:26+00:00

I have 2 mysql tables where one has a foreign key in another table.

  • 0

I have 2 mysql tables where one has a foreign key in another table. When mysqldump using where statement to selectively dump certain subsets, the second mysqldump goes into a preparing state and hangs forever. how do I fix this?

mysqldump -u$username -p$password --quick --lock-all-tables --where="table1_id<1000" $db table1 > $dump_dir/table1.sql                                                                                                 

mysqldump -u$username -p$password --quick --lock-all-tables --where="table2_id in (select table2_id from table1 where table1_id<1000)" $db table2 >$dump_dir/table2.sql
  • 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-17T07:00:27+00:00Added an answer on June 17, 2026 at 7:00 am

    Here’s a couple of things you could try.

    Try adding indexes:

    ... ON table1 (table1_id, table2_id)
    

    Also, try adding the DISTINCT keyword in subquery:

     table2_id in (select DISTINCT table2_id from table1 where table1_id<1000)
    

    Other than performance of the query that MySQL is using, I don’t see anything there that should cause a “hang”, other than that lock-all-tables option. I’m assuming you’ve tested without that, and observed the same behavior.


    Q: What do you suspect is causing the hang?

    I suspect it’s just the SELECT statement that is cranking. I think it’s likely that for EVERY row in table2, the execution plan is doing a nested loops lookup from table1. I suspect that the IN (subquery) predicate is being optimized into an equivalent EXISTS (correlated subquery).

    Q: Why would adding indexes help?

    Indexes may not help at all. But an appropriate index on table1 may cut down on the amount of time required to retrieve the results from the subquery. (It’s likely the results from the subquery will be “cached”, so that there will only be a savings when that subquery is first run, adn not a savings for each row from table2 that is evaluated.)

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

Sidebar

Related Questions

I have an existing database in mysql. One of my tables has discontinuous ids.
I have two large tables in MySQL, one containing about 6,00,000 records and another
In a MySQL database I have two tables linked in a join. One table
What I have is two tables inside of a mysql database. One table contains
I have two tables on mysql: users, and management. The users table has a
I have a database that has two tables, one of which contains a foreign
I have two tables, round and event. One round has many events. create table
I have three tables, table A has a unique primary key that is auto-incremented,
My database is MySQL with foreign key management. It has 2 tables : Table1
If I have a table that has a primary key and a foreign key,

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.