Hi All,
The 2 queries below are the same except the "ON" clause is on 2 different sets of fields.
The first ON clause is based on the "email" field in both tables. In both tables the email field is a "unique" index.
The second ON clause is based on the "user_id" field which is a primary key in the users table (id) and only indexed in the subscribers table.
Why would the "email" query take such a long time vs. the "id" query when both sets of fields are indexed? Is it the text comparison vs. the integer comparison?
This query takes a really long time.
SELECT M.* FROM users AS M
LEFT JOIN subscribers AS N
ON M.email = N.email
WHERE
N.id IS NULL AND
M.block=0 AND
M.registerDate<>'0000-00-00 00:00:00'
This query takes a very short time.
SELECT M.* FROM users AS M
LEFT JOIN subscribers AS N
ON M.id = N.user_id
WHERE
N.id IS NULL AND
M.block=0 AND
M.registerDate<>'0000-00-00 00:00:00'
The 2 queries below are the same except the "ON" clause is on 2 different sets of fields.
The first ON clause is based on the "email" field in both tables. In both tables the email field is a "unique" index.
The second ON clause is based on the "user_id" field which is a primary key in the users table (id) and only indexed in the subscribers table.
Why would the "email" query take such a long time vs. the "id" query when both sets of fields are indexed? Is it the text comparison vs. the integer comparison?
This query takes a really long time.
SELECT M.* FROM users AS M
LEFT JOIN subscribers AS N
ON M.email = N.email
WHERE
N.id IS NULL AND
M.block=0 AND
M.registerDate<>'0000-00-00 00:00:00'
This query takes a very short time.
SELECT M.* FROM users AS M
LEFT JOIN subscribers AS N
ON M.id = N.user_id
WHERE
N.id IS NULL AND
M.block=0 AND
M.registerDate<>'0000-00-00 00:00:00'
Comment