Hey, progress!
SELECT et_sort.text, items.* FROM omeka_items AS items
INNER JOIN omeka_element_texts AS et_sort
ON et_sort.record_id = items.id
AND et_sort.record_type = 'Item'
AND et_sort.element_id = 40
GROUP BY items.id
ORDER BY et_sort.text ASC, items.id ASC
LIMIT 50 OFFSET 100
1.734 seconds
Also I’m sure you’re aware that MySQL/MariaDB will attempt to guess the best join if you just state “JOIN”.
SELECT et_sort.text, items.* FROM omeka_items AS items
JOIN omeka_element_texts AS et_sort
ON et_sort.record_id = items.id
AND et_sort.record_type = 'Item'
AND et_sort.element_id = 40
GROUP BY items.id
ORDER BY et_sort.text ASC, items.id ASC
LIMIT 50 OFFSET 100
1.744 seconds
And then LEFT JOIN…
SELECT et_sort.text, items.* FROM omeka_items AS items
LEFT JOIN omeka_element_texts AS et_sort
ON et_sort.record_id = items.id
AND et_sort.record_type = 'Item'
AND et_sort.element_id = 40
GROUP BY items.id
ORDER BY et_sort.text ASC, items.id ASC
LIMIT 50 OFFSET 100
9.2 seconds
From a StackOverflow article:
There are different types of joins available in SQL:
INNER JOIN: returns rows when there is a match in both tables.
LEFT JOIN: returns all rows from the left table, even if there are no matches in the right table.
RIGHT JOIN: returns all rows from the right table, even if there are no matches in the left table.
FULL JOIN: It combines the results of both left and right outer joins.
I am assuming there is a reason for using a LEFT JOIN in the generic query constructor which has to handle all kinds of variations between installations, vocabularies, filters, searches, user selections, etc. But just to confirm, you do intend the join results to include “all rows from LEFT even if no matches”?