Use subquery instead of JOIN + COUNT (#1483)
This commit is contained in:
parent
8c5edcf0e9
commit
df3e58bdb9
1 changed files with 6 additions and 4 deletions
|
@ -696,8 +696,9 @@ class database_driver extends calendar_driver
|
|||
}
|
||||
|
||||
$result = $this->rc->db->query(sprintf(
|
||||
"SELECT e.*, COUNT(a.attachment_id) AS _attachments FROM " . $this->db_events . " AS e
|
||||
LEFT JOIN " . $this->db_attachments . " AS a ON (a.event_id = e.event_id OR a.event_id = e.recurrence_id)
|
||||
"SELECT e.*, (SELECT COUNT(attachment_id) FROM " . $this->db_attachments . "
|
||||
WHERE event_id = e.event_id OR event_id = e.recurrence_id) AS _attachments
|
||||
FROM " . $this->db_events . " AS e
|
||||
WHERE e.calendar_id IN (%s)
|
||||
AND e.$col=?",
|
||||
$cals
|
||||
|
@ -738,8 +739,9 @@ class database_driver extends calendar_driver
|
|||
$events = array();
|
||||
if (!empty($calendar_ids)) {
|
||||
$result = $this->rc->db->query(sprintf(
|
||||
"SELECT e.*, COUNT(a.attachment_id) AS _attachments FROM " . $this->db_events . " AS e
|
||||
LEFT JOIN " . $this->db_attachments . " AS a ON (a.event_id = e.event_id OR a.event_id = e.recurrence_id)
|
||||
"SELECT e.*, (SELECT COUNT(attachment_id) FROM " . $this->db_attachments . "
|
||||
WHERE event_id = e.event_id OR event_id = e.recurrence_id) AS _attachments
|
||||
FROM " . $this->db_events . " AS e
|
||||
WHERE e.calendar_id IN (%s)
|
||||
AND e.start <= %s AND e.end >= %s
|
||||
%s
|
||||
|
|
Loading…
Add table
Reference in a new issue