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

Backup Optim : Primary Key instead of Limit Offset #887

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

GautierBoudeweel
Copy link

Questions Answers
Description? Please be specific when describing this change. What did you change? Why?
Type? bug fix / improvement / new feature / refactor
BC breaks? yes / no
Deprecations? yes / no
Fixed ticket? Fixes #{issue URL here}, Fixes #{another issue URL here}
Sponsor company Your company or customer's name goes here (if applicable).
How to test? Indicate how to verify that this change works as expected.

@@ -219,7 +221,11 @@ public function run(): int
if (!in_array($table, $ignore_stats_table)) {
do {
$backup_loop_limit = $this->container->getState()->getBackupLoopLimit();
$data = $this->container->getDb()->executeS('SELECT * FROM `' . $table . '` LIMIT ' . (int) $backup_loop_limit . ',200', false, false);
if ($primary_key) {
$data = $this->container->getDb()->executeS('SELECT * FROM `' . $table . '` WHERE `' . $primary_key . '` BETWEEN ' . (int) $backup_loop_limit . ' AND ' . (int) $backup_loop_limit + 200 , false, false);
Copy link
Member

Choose a reason for hiding this comment

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

Note that in this implementation, if there is a gap in the rows that is bigger than a batch size, nothing would be returned by this request and the sync of the backup would be considered as done.

Copy link
Author

Choose a reason for hiding this comment

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

We could check for the max id in order to prevent stopping the loop
$maxId = (int)$db->getValue("SELECT MAX($primaryKey) FROM $table");

Copy link
Member

Choose a reason for hiding this comment

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

That's a great idea, and this should be stored in a cache. We would avoid reloading the same request at each HTTP request.

@GautierBoudeweel GautierBoudeweel changed the title Patch 1 Backup Optim : Primary Key instead of Limit Offset Sep 11, 2024
@GautierBoudeweel
Copy link
Author

There is another issue with composite primary key, like in ps_cart_rule_combination
We could ignore the primary_key optimization for these tables with composite indexes, but it is precisely on these tables that we find the largest volumes and that the need for optimization is the greatest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants