Make sure that JOIN columns both carry indexes of the same type
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Running a JOIN on two columns of different data types may force a sequential scan.
Example:
SELECT *
FROM foo
INNER JOIN bar ON foo.a = bar.b
If foo.a and bar.b are not of the same data type, the query planner will need to cast the data of each foo.a and bar.b entry. For instance, if foo.a is integer and bar.b is string, it can't use one to lookup in the other unless and until it casts to the right type. This happens using any database, inducing MySQL and PostgreSQL.
Even if the cast happens on memory only, it will consume CPU time, at least one cycle per row and hence will be very slow. On very large tables, this should be avoided.
More examples soon.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion