Allow tweaking of the index that MySQL use when searching products (#29934)
* Allow tweaking of the index that MySQL use when searching products Sometimes when working with large dataset with many entities the MySQL engine does not pick-up the right index. This is especially true when doing a search over the reference because the LIKE '%%' prevent the uk_product_label from being chosen. This PR aims to improve this situation by doing the following : - Adding a simple index on entity column. - Adding an hidden constant to force the index being used when searching products. Performances over a 8M products dataset shows a reduction of 2/3 execution time. * Add missing global $conf * Fix wrong usage of getDolGlobalString() * Finalise fix * Add more indexes * Rework indexes
This commit is contained in:
parent
f0ccd63ed4
commit
0cfd16d8db
3 changed files with 8 additions and 0 deletions
|
|
@ -2961,6 +2961,11 @@ class Form
|
|||
}
|
||||
|
||||
$sql .= " FROM ".$this->db->prefix()."product as p";
|
||||
|
||||
if (getDolGlobalString('MAIN_SEARCH_PRODUCT_FORCE_INDEX')) {
|
||||
$sql .= " USE INDEX (" . $this->db->sanitize(getDolGlobalString('MAIN_PRODUCT_FORCE_INDEX')) . ")";
|
||||
}
|
||||
|
||||
// Add from (left join) from hooks
|
||||
$parameters = array();
|
||||
$reshook = $hookmanager->executeHooks('selectProductsListFrom', $parameters); // Note that $action and $object may have been modified by hook
|
||||
|
|
|
|||
|
|
@ -388,3 +388,5 @@ ALTER TABLE llx_chargesociales ADD INDEX idx_chargesociales_fk_user (fk_user);
|
|||
|
||||
-- table paiementcharge indexes
|
||||
ALTER TABLE llx_paiementcharge ADD INDEX idx_paiementcharge_fk_charge (fk_charge);
|
||||
|
||||
ALTER TABLE llx_product ADD INDEX idx_product_entity_fk_product_type (entity, fk_product_type);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ ALTER TABLE llx_product ADD INDEX idx_product_fk_country (fk_country);
|
|||
ALTER TABLE llx_product ADD INDEX idx_product_fk_user_author (fk_user_author);
|
||||
ALTER TABLE llx_product ADD INDEX idx_product_fk_barcode_type (fk_barcode_type);
|
||||
ALTER TABLE llx_product ADD INDEX idx_product_fk_project (fk_project);
|
||||
ALTER TABLE llx_product ADD INDEX idx_product_entity_fk_product_type (entity, fk_product_type);
|
||||
ALTER TABLE llx_product ADD UNIQUE INDEX uk_product_barcode (barcode, fk_barcode_type, entity);
|
||||
ALTER TABLE llx_product ADD CONSTRAINT fk_product_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
|
||||
ALTER TABLE llx_product ADD CONSTRAINT fk_product_finished FOREIGN KEY (finished) REFERENCES llx_c_product_nature (code);
|
||||
|
|
|
|||
Loading…
Reference in a new issue