Improve query speed when migrating to 1.10.x see BT#12609

pull/2487/head
jmontoyaa 8 years ago
parent d878dce952
commit 3a7ff40a76
  1. 34
      app/Migrations/Schema/V110/Version20150603181728.php

@ -62,26 +62,48 @@ class Version20150603181728 extends AbstractMigrationChamilo
$this->addSql("DELETE FROM c_item_property WHERE c_id NOT IN (SELECT id FROM course)");
// Remove inconsistencies about non-existing users
$this->addSql("DELETE FROM course_rel_user WHERE user_id NOT IN (SELECT id FROM user)");
// Remove inconsistencies about non-existing courses
$this->addSql("DELETE FROM c_item_property WHERE c_id NOT IN (SELECT id FROM course)");
// Fix to_group_id
$this->addSql("UPDATE c_item_property SET to_group_id = NULL WHERE to_group_id = 0");
$this->addSql('UPDATE c_item_property cip SET cip.to_group_id = (SELECT cgi.iid FROM c_group_info cgi WHERE cgi.c_id = cip.c_id AND cgi.id = cip.to_group_id)');
$this->addSql("DELETE FROM c_item_property WHERE to_group_id IS NOT NULL AND to_group_id <> 0 AND to_group_id NOT IN (SELECT iid FROM c_group_info)");
$this->addSql('UPDATE c_item_property SET to_user_id = NULL WHERE to_user_id = 0');
$this->addSql('UPDATE c_item_property SET insert_user_id = NULL WHERE insert_user_id = 0');
$this->addSql('UPDATE c_item_property SET session_id = NULL WHERE session_id = 0');
$table = $schema->getTable('c_group_info');
if ($table->hasIndex('idx_cginfo_id') == false) {
$this->addSql('ALTER TABLE c_group_info ADD INDEX idx_cginfo_id (id);');
}
if ($table->hasIndex('idx_cginfo_cid') == false) {
$this->addSql('ALTER TABLE c_group_info ADD INDEX idx_cginfo_cid (c_id);');
}
$table = $schema->getTable('c_item_property');
if ($table->hasIndex('idx_cip_tgid') == false) {
$this->addSql('ALTER TABLE c_item_property ADD INDEX idx_cip_tgid (to_group_id);');
}
if ($table->hasIndex('idx_cip_cid') == false) {
$this->addSql('ALTER TABLE c_item_property ADD INDEX idx_cip_cid (c_id);');
}
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C18191D79BD3 FOREIGN KEY (c_id) REFERENCES course(id)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C181330D47E9 FOREIGN KEY (to_group_id) REFERENCES c_group_info (iid)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C18129F6EE60 FOREIGN KEY (to_user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C1819C859CC3 FOREIGN KEY (insert_user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C181613FECDF FOREIGN KEY (session_id) REFERENCES session (id)');
$this->addSql('CREATE INDEX IDX_1D84C18191D79BD3 ON c_item_property (c_id)');
$this->addSql('CREATE INDEX IDX_1D84C181330D47E9 ON c_item_property (to_group_id)');
$this->addSql('CREATE INDEX IDX_1D84C18129F6EE60 ON c_item_property (to_user_id)');
$this->addSql('CREATE INDEX IDX_1D84C1819C859CC3 ON c_item_property (insert_user_id)');
$this->addSql('CREATE INDEX IDX_1D84C181613FECDF ON c_item_property (session_id)');
// Update c_item_property.to_group_id
$this->addSql('UPDATE c_item_property cip SET cip.to_group_id = (SELECT cgi.iid FROM c_group_info cgi WHERE cgi.c_id = cip.c_id AND cgi.id = cip.to_group_id)');
$this->addSql("DELETE FROM c_item_property WHERE to_group_id IS NOT NULL AND to_group_id <> 0 AND to_group_id NOT IN (SELECT iid FROM c_group_info)");
$this->addSql('ALTER TABLE c_item_property ADD CONSTRAINT FK_1D84C181330D47E9 FOREIGN KEY (to_group_id) REFERENCES c_group_info (iid)');
$this->addSql('CREATE INDEX IDX_1D84C181330D47E9 ON c_item_property (to_group_id)');
}
/**

Loading…
Cancel
Save