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

insert into temp category table is kind of slow. #424

Open
zhhank opened this issue Apr 12, 2018 · 0 comments
Open

insert into temp category table is kind of slow. #424

zhhank opened this issue Apr 12, 2018 · 0 comments

Comments

@zhhank
Copy link

zhhank commented Apr 12, 2018

insert into temp category is kind of slow if you have thousands categories existed. And in my case, I need run import data from time to time every day, and the updated data is not very big(<300 products). So I need the import is as fast as possible.
For a quick fix, I create a index on temp table's path column. in my test case, the sql execute time is changed from 5seconds to <1 seconds. Hope this can help someone in the similar case..

Maybe someone have better idea to calculate the children_count.

public function updateChildrenCount() {

.....
$categoryTableTmp = $categoryTable . '_tmp';
$connection->query('DROP TEMPORARY TABLE IF EXISTS ' . $categoryTableTmp);
$connection->query("CREATE TEMPORARY TABLE {$categoryTableTmp} LIKE {$categoryTable};
CREATE FULLTEXT INDEX idx ON {$categoryTableTmp}(PATH);
INSERT INTO {$categoryTableTmp} SELECT * FROM {$categoryTable};
UPDATE {$categoryTable} cce
SET children_count =
(
SELECT count(cce2.entity_id) - 1 as children_county
FROM {$categoryTableTmp} cce2
WHERE PATH LIKE CONCAT(cce.path,'%')
);
");
}

@zhhank zhhank changed the title insert insert into temp category table is kind of slow. Apr 12, 2018
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

No branches or pull requests

1 participant