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 synonym index to Names table #1857

Merged
merged 1 commit into from
Jan 26, 2024
Merged

Conversation

nimmolo
Copy link
Contributor

@nimmolo nimmolo commented Jan 26, 2024

Name.where(synonym_id: whatever) is called on every obs index and show.


without index:

irb(main):001> Name.where(synonym_id: 6869).explain
  Name Load (99.7ms)  SELECT `names`.* FROM `names` WHERE `names`.`synonym_id` = 6869
=> 
EXPLAIN SELECT `names`.* FROM `names` WHERE `names`.`synonym_id` = 6869
+----+-------------+-------+------------+------+---------------+------+---------+------+-------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows  | filtered | Extra       |
+----+-------------+-------+------------+------+---------------+------+---------+------+-------+----------+-------------+
|  1 | SIMPLE      | names | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 67680 |     10.0 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+-------+----------+-------------+
1 row in set (0.00 sec)

On production, it can be quite slow:

Name Load (494.8ms)  SELECT `names`.* FROM `names` WHERE `names`.`synonym_id` = 6869

with index:

irb(main):001> Name.where(synonym_id: 6869).explain
  TRANSACTION (0.1ms)  BEGIN
  Name Load (0.3ms)  SELECT `names`.* FROM `names` WHERE `names`.`synonym_id` = 6869
=> 
EXPLAIN SELECT `names`.* FROM `names` WHERE `names`.`synonym_id` = 6869
+----+-------------+-------+------------+------+---------------+---------------+---------+-------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key           | key_len | ref   | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+---------------+---------+-------+------+----------+-------+
|  1 | SIMPLE      | names | NULL       | ref  | synonym_index | synonym_index | 5       | const |    2 |    100.0 | NULL  |
+----+-------------+-------+------------+------+---------------+---------------+---------+-------+------+----------+-------+
1 row in set (0.00 sec)

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 94.517%. remained the same
when pulling 82eceff on nimmo-add-synonym-index-to-names
into f54d931 on main.

@nimmolo nimmolo merged commit e63abcb into main Jan 26, 2024
5 checks passed
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.

None yet

2 participants