Hello, 

could someone please help me with optimizing the following query?

USE commonswiki_p;

SELECT first_upload, uploads, username FROM
(
  SELECT MIN(log_timestamp) AS first_upload, MIN(log_id) AS first_upload_id, COUNT(log_timestamp) AS uploads, log_user_text AS username
  FROM logging_compat
  LEFT JOIN user ON user_id = log_user
  JOIN page ON log_page = page_id
  WHERE log_type = "upload" AND (log_action = "upload" OR log_action = "overwrite") AND user_registration > "20190101000000"
  GROUP BY log_user
) AS first_uploads
JOIN change_tag ON ct_log_id = first_upload_id
WHERE ct_tag_id=21;


It takes over 30 minutes :/. I want to have a list of users whose first contrib to Wikimedia Commons is tagged with tag number 21. 

Thanks!

Martin