Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a table hash that take account of the AUTO_INCREMENT changes #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/TestSuite/Fixture/ChecksumTestFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,28 @@ protected function _hash(ConnectionInterface $db)
$sth = $db->execute("CHECKSUM TABLE " . $this->table . ';');
$result = $sth->fetch('assoc');
$checksum = $result['Checksum'];
return $checksum;

// get auto increment count
$autoIncrement = $this->_getAutoIncrement($db);

return $checksum . $autoIncrement;
}

/**
* Get the table auto increment count
*
* @param ConnectionInterface $db
* @return string
*/
protected function _getAutoIncrement(ConnectionInterface $db)
{
$autoIncrementSth = $db->execute('SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=:schema AND TABLE_NAME=:table;', [
'schema' => $db->config()['database'],
'table' => $this->table,
]);
$autoIncrementResult = $autoIncrementSth->fetch('assoc');

return (string) $autoIncrementResult['AUTO_INCREMENT'];
Comment on lines +133 to +139
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent performance degredation, we could try to execute both queries in one go.

  1. Getting the table checksum
  2. Fetching the AUTO_INCREMENT info

Because apart from the additional queries to execute, the biggest part of the performance degredation of this change comes most likely from the PHP side.

And since it sems it not possible to query the table checksum as a sub query, we can only try the idea above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean with "both queries in one go"? We cannot combine it like this:

SELECT 
  (SELECT `AUTO_INCREMENT` ...) as auto_increment,
  (CHECKSUM TABLE ...) as checksum;

Because the second query is not a select.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried that already.

But can we execute two queries with one execute() call by splitting them like SELECT ...;CHECKSUM TABLE;?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I didn't find any way to get the result from the second query. Only the first query is returned:

// Debugging
$sth = $db->execute(
  "CHECKSUM TABLE " . $this->table . ';' .
  'SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=:schema AND TABLE_NAME=:table;',
  [
    'schema' => $db->config()['database'],
    'table' => $this->table,
  ]
);

// How to get the result of the second query?
// $sth->fetch('assoc'); returns the result of the first one.

}

/**
Expand Down