SELECT cm.course_id, xu.full_path, xu.file_name, xu.file_id, xu.virtual_server
FROM cms_doc.xyf_urls xu
LEFT JOIN bb_bb60.course_main cm ON xu.full_path LIKE '/courses/' ||
cm.course_id OR xu.full_path LIKE '/courses/' || cm.course_id || '%'
WHERE xu.full_path NOT LIKE '/orgs%'
AND xu.full_path NOT LIKE '/institution%'
AND xu.full_path NOT LIKE '/library%'
AND xu.full_path NOT LIKE '/internal%'
AND xu.full_path NOT LIKE '/user%'
ORDER BY cm.course_id
答案 0 :(得分:2)
它很慢,因为所有LIKE
都是JOIN
,特别是{{1}}的一部分。
答案 1 :(得分:0)
首先,确保xu.full_path
上有索引。
其次,两个OR
条件中的一个似乎是多余的。试试这个:
SELECT cm.course_id, xu.full_path, xu.file_name, xu.file_id, xu.virtual_server
FROM cms_doc.xyf_urls xu
LEFT JOIN bb_bb60.course_main cm
ON xu.full_path LIKE '/courses/' || cm.course_id || '%'
WHERE xu.full_path NOT LIKE '/orgs%'
AND xu.full_path NOT LIKE '/institution%'
AND xu.full_path NOT LIKE '/library%'
AND xu.full_path NOT LIKE '/internal%'
AND xu.full_path NOT LIKE '/user%'
ORDER BY cm.course_id