diff --git a/src/Lunr/Gravity/Database/DatabaseAccessObject.php b/src/Lunr/Gravity/Database/DatabaseAccessObject.php
index 9d75d5e17c02728090fd2f94044f937072caa2a4..5ad32f0189a4a1bacd0b84208b1824d0094ccc99 100644
--- a/src/Lunr/Gravity/Database/DatabaseAccessObject.php
+++ b/src/Lunr/Gravity/Database/DatabaseAccessObject.php
@@ -197,6 +197,33 @@ abstract class DatabaseAccessObject implements DataAccessObjectInterface
         }
     }
 
+    /**
+     * Retry executing the query in case of deadlock error.
+     *
+     * @param DatabaseQueryResult $query          The result of the run query
+     * @param Integer             $effort_number  The title of the requested cell
+     *
+     * @return mixed $return FALSE on failure, mixed otherwise
+     */
+    protected function result_retry($query, $effort_number = 5)
+    {
+        $i = 1;
+
+        while($effort_number >= $i)
+        {
+            if($query->has_deadlock() === FALSE)
+            {
+                return $query;
+            }
+
+            $query = $this->db->query($query->query());
+
+            $i++;
+        }
+
+        return $query;
+    }
+
 }
 
 ?>
diff --git a/src/Lunr/Gravity/Database/DatabaseQueryResultInterface.php b/src/Lunr/Gravity/Database/DatabaseQueryResultInterface.php
index b76c0f596835e13f2c526866fa0228a86c1fb70b..a00e7128d0cf03b8e28e353bfc2694cff33d4847 100644
--- a/src/Lunr/Gravity/Database/DatabaseQueryResultInterface.php
+++ b/src/Lunr/Gravity/Database/DatabaseQueryResultInterface.php
@@ -34,6 +34,13 @@ interface DatabaseQueryResultInterface
     public function has_failed();
 
     /**
+     * Check whether the query has a deadlock or not.
+     *
+     * @return Boolean $return TRUE if it failed, FALSE otherwise
+     */
+    public function has_deadlock();
+
+    /**
      * Get string description of the error, if there was one.
      *
      * @return String $message Error Message
diff --git a/src/Lunr/Gravity/Database/MySQL/MySQLQueryResult.php b/src/Lunr/Gravity/Database/MySQL/MySQLQueryResult.php
index a008dc28d7a1d2b2a5ea9e9b9e467a7a4983eb20..c6f4117ecf2e1ffe4cfe57fe91c320fed90ade2f 100644
--- a/src/Lunr/Gravity/Database/MySQL/MySQLQueryResult.php
+++ b/src/Lunr/Gravity/Database/MySQL/MySQLQueryResult.php
@@ -28,6 +28,11 @@ use MySQLi_Result;
  */
 class MySQLQueryResult implements DatabaseQueryResultInterface
 {
+    /**
+     * The MySQL error code for transaction deadlock.
+     * @var Integer
+     */
+    const DEADLOCK_ERR_CODE = 1213;
 
     /**
      * The query string that was executed.
@@ -166,6 +171,21 @@ class MySQLQueryResult implements DatabaseQueryResultInterface
     }
 
     /**
+     * Check whether the query has a deadlock or not.
+     *
+     * @return Boolean $return TRUE if it failed, FALSE otherwise
+     */
+    public function has_deadlock()
+    {
+        if($this->error_number == self::DEADLOCK_ERR_CODE)
+        {
+            return TRUE;
+        }
+
+        return FALSE;
+    }
+
+    /**
      * Get string description of the error, if there was one.
      *
      * @return String $message Error Message
diff --git a/src/Lunr/Gravity/Database/MySQL/Tests/MySQLQueryResultFailedTest.php b/src/Lunr/Gravity/Database/MySQL/Tests/MySQLQueryResultFailedTest.php
index 5fbb1e97f64d3670bf43fadad0526ff19cfda6c8..4f540765a5df4d6a3d35063ec21a28fde49a0579 100644
--- a/src/Lunr/Gravity/Database/MySQL/Tests/MySQLQueryResultFailedTest.php
+++ b/src/Lunr/Gravity/Database/MySQL/Tests/MySQLQueryResultFailedTest.php
@@ -201,6 +201,36 @@ class MySQLQueryResultFailedTest extends MySQLQueryResultTest
         $this->assertNull($this->result->result_cell('cell'));
     }
 
+    /**
+     * Test that the has_deadlock() method returns TRUE.
+     *
+     * @covers Lunr\Gravity\Database\MySQL\MySQLQueryResult::has_deadlock
+     */
+    public function testHasDeadlockReturnsTrue()
+    {
+        $property = $this->result_reflection->getProperty('error_number');
+        $property->setAccessible(TRUE);
+
+        $property->setValue($this->result, 1213);
+
+        $this->assertTrue($this->result->has_deadlock());
+    }
+
+    /**
+     * Test that the has_deadlock() method returns FALSE.
+     *
+     * @covers Lunr\Gravity\Database\MySQL\MySQLQueryResult::has_deadlock
+     */
+    public function testHasDeadlockReturnsFalse()
+    {
+        $property = $this->result_reflection->getProperty('error_number');
+        $property->setAccessible(TRUE);
+
+        $property->setValue($this->result, 999);
+
+        $this->assertFalse($this->result->has_deadlock());
+    }
+
 }
 
 ?>
diff --git a/src/Lunr/Gravity/Database/Tests/DatabaseAccessObjectResultsTest.php b/src/Lunr/Gravity/Database/Tests/DatabaseAccessObjectResultsTest.php
index 8df854f60bdc8ea8358cca0e366d857857a01f8a..6033837f86c23ca36f36f86b4158c62bd0270eb9 100644
--- a/src/Lunr/Gravity/Database/Tests/DatabaseAccessObjectResultsTest.php
+++ b/src/Lunr/Gravity/Database/Tests/DatabaseAccessObjectResultsTest.php
@@ -417,6 +417,61 @@ class DatabaseAccessObjectResultsTest extends DatabaseAccessObjectTest
         $this->assertEquals($query_result, $result);
     }
 
+    /**
+     * Test that result_retry() returns the same result query if there is no deadlock.
+     *
+     * @covers Lunr\Gravity\Database\DatabaseAccessObject::result_retry
+     */
+    public function testResultRetryReturnsQueryInNoDeadlock()
+    {
+        $query = $this->getMockBuilder('Lunr\Gravity\Database\MySQL\MySQLQueryResult')
+                      ->disableOriginalConstructor()
+                      ->getMock();
+
+        $query->expects($this->once())
+              ->method('has_deadlock')
+              ->will($this->returnValue(FALSE));
+
+        $method = $this->reflection_dao->getMethod('result_retry');
+        $method->setAccessible(TRUE);
+
+        $result = $method->invokeArgs($this->dao, [$query]);
+
+        $this->assertSame($result, $query);
+    }
+
+    /**
+     * Test that result_retry() re-executes the query if there is a deadlock.
+     *
+     * @covers Lunr\Gravity\Database\DatabaseAccessObject::result_retry
+     */
+    public function testResultRetryReExecutesQueryInDeadlock()
+    {
+        $query = $this->getMockBuilder('Lunr\Gravity\Database\MySQL\MySQLQueryResult')
+                      ->disableOriginalConstructor()
+                      ->getMock();
+
+        $query->expects($this->at(0))
+              ->method('has_deadlock')
+              ->will($this->returnValue(TRUE));
+
+        $query->expects($this->at(1))
+              ->method('query')
+              ->will($this->returnValue('sql_query'));
+
+        $this->db->expects($this->once())
+                 ->method('query')
+                 ->with('sql_query')
+                 ->will($this->returnValue($query));
+
+        $method = $this->reflection_dao->getMethod('result_retry');
+        $method->setAccessible(TRUE);
+
+        $result = $method->invokeArgs($this->dao, [$query, 1]);
+
+        $this->assertSame($result, $query);
+    }
+
 }
 
 ?>
