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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:48:47+00:00 2026-05-26T16:48:47+00:00

In my application, I have two queries that occur from time to time (from

  • 0

In my application, I have two queries that occur from time to time (from different processes), that cause a deadlock.

Query #1

UPDATE tblA, tblB SET tblA.varcharfield=tblB.varcharfield WHERE tblA.varcharfield IS NULL AND [a few other conditions];

Query #2

INSERT INTO tmp_tbl SELECT * FROM tblA WHERE [various conditions];

Both of these queries take a significant time, as these tables have millions of rows. When query #2 is running, it seems that tblA is locked in mode S. It seems that query #1 requires an X lock. Since this is incompatible with an S lock, query #1 waits for up to 30 seconds, at which point I get a deadlock:

Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction

Based on what I’ve read in the documentation, I think I have a couple options:

  1. Set an index on tblA.varcharfield. Unfortunately, I think that this would require a very large index to store the field of varchar(512). (See edit below… this didn’t work.)
  2. Disable locking with SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
    . I don’t understand the implications of this, and am worried about corrupt data. I don’t use explicit transactions in my application currently, but I might at some point in the future.
  3. Split my time-consuming queries into small pieces so that they can queue and run in MySQL without reaching the 30-second timeout. This wouldn’t really fix the heart of the issue, and I am concerned that when my database servers get busy that the problem will occur again.
  4. Simply retrying queries over and over again… not an option I am hoping for.

How should I proceed? Are there alternate methods I should consider?


EDIT: I have tried setting an index on varcharfield, but the table is still locking. I suspect that the locking happens when the UPDATE portion is actually executing. Are there other suggestions to get around this problem?

  • 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-26T16:48:48+00:00Added an answer on May 26, 2026 at 4:48 pm

    I was able to solve the issue by adding explicit LOCK TABLE statements around both queries. This turned out to be a better solution, since each query affects so many records, and that both of these are background processes. They now wait on each other.

    http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html

    While this is an okay solution for me, it obviously isn’t the answer for everyone. Locking with WRITE means that you cannot READ. Only a READ lock will allow others to READ.

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

Sidebar

Related Questions

I have an application that queries and updates two databases at the same time
I have application in VB.net that have two different form (Form1 and Form2). Now
I am writing my first little Access 2003 application. I have two queries that
I have two queries that are basically the same: OLD TRANSACTIONS QUERY SELECT t.payment_method,
I have two queries: <cfquery name=getChairReview datasource=#application.dsn#> SELECT* FROM eval_reviews WHERE faculty = <cfqueryparam
I have two XML files that are generated by another application I have no
I have two application that need to talk to each other. App1 needs to
We have two tables in our application that both have a ShowOrder column. We
In my application I have two queries which will be quite frequently used. The
I have a MySQL table from a third-party application that has millions of rows

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.