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

Add DB indexes to LinkMapping #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JamesDPC
Copy link

This change add indexes to commonly used LinkMapping fields appearing in queries.
This improves query performance and avoids full table scans, especially when a lot of LinkMapping records are present.

The indexes added represent fields used to find a LinkMapping record in MisdirectionService::getMapping();

Example with index on RedirectType with 1000 records and the query as below:

EXPLAIN SELECT DISTINCT `LinkMapping`.`ClassName`, `LinkMapping`.`LastEdited`, `LinkMapping`.`Created`, `LinkMapping`.`LinkType`, `LinkMappingLinkMapping`.`RedirectLink`, `LinkMapping`.`RedirectPageID`, `LinkMapping`.`ResponseCode`, `LinkMapping`.`HostnameRestriction`, `LinkMapping`.`ID`,                      ELSE 'nglasl\\misdirection\\LinkMapping' END AS `RecordClassName` 
FROM `LinkMapping`  
WHERE (`LinkMapping`.`MappedLink` LIKE '%11%') 
ORDER BY `LinkMapping`.`RedirectType` ASC
LIMIT 10;

Result with index on RedirectType and MappedLink (type=index)

+----+-------------+-------------+------------+-------+---------------+--------------+---------+------+------+----------+-------------+
| id | select_type | table       | partitions | type  | possible_keys | key          | key_len | ref  | rows | filtered | Extra       |
+----+-------------+-------------+------------+-------+---------------+--------------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | LinkMapping | NULL       | index | NULL          | RedirectType | 2       | NULL |   10 |    11.11 | Using where |
+----+-------------+-------------+------------+-------+---------------+--------------+---------+------+------+----------+-------------+

Without the indexes, same query (type=ALL)

+----+-------------+-------------+------------+------+---------------+------+---------+------+------+----------+-----------------------------+
| id | select_type | table       | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra                       |
+----+-------------+-------------+------------+------+---------------+------+---------+------+------+----------+-----------------------------+
|  1 | SIMPLE      | LinkMapping | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 1000 |    11.11 | Using where; Using filesort |
+----+-------------+-------------+------------+------+---------------+------+---------+------+------+----------+-----------------------------+

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.

1 participant