Skip to content

Commit 7804642

Browse files
committed
Suppress the dependencies on the now obsolete mail_status table.
1 parent ac4c90e commit 7804642

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

Diff for: src/msg_status_cache.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ msg_status_cache::db_new_mail_notif()
104104
DBG_PRINTF(5, "We have NEW MAIL!");
105105
db_cnx db;
106106
try {
107-
sql_stream s("SELECT ms.mail_id,ms.status,sender,sender_fullname,subject,recipients FROM mail m JOIN mail_status ms USING(mail_id) WHERE ms.mail_id>:p1", db);
107+
sql_stream s("SELECT mail_id,status,sender,sender_fullname,subject,recipients FROM mail WHERE status&status_mask('archived')=0 AND mail_id>:p1", db);
108108
s << m_max_mail_id;
109109
mail_id_t mail_id;
110110
int status;

Diff for: src/query_listview.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,12 @@ query_listview::fetch_tag_map()
467467
{
468468
db_cnx db;
469469
try {
470-
int mask = mail_msg::statusTrashed + mail_msg::statusArchived + mail_msg::statusSent;
471-
sql_stream s(QString("SELECT ms.mail_id,mt.tag,ms.status,m.priority FROM (mail m JOIN mail_status ms USING (mail_id)) LEFT OUTER JOIN mail_tags mt ON mt.mail_id=ms.mail_id WHERE ms.status&%1=0").arg(mask), db); // status is not (sent OR archived OR trashed)
470+
// status is current (=NOT(sent OR archived OR trashed))
471+
sql_stream s(QString("SELECT m.mail_id,mt.tag,m.status,m.priority "
472+
"FROM mail m LEFT OUTER JOIN mail_tags mt ON mt.mail_id=m.mail_id "
473+
"WHERE m.status&status_mask('archived')=0 AND m.status&%1=0")
474+
.arg(mail_msg::statusSent|mail_msg::statusTrashed),
475+
db);
472476
mail_id_t mail_id;
473477
unsigned int tag, status;
474478
int pri;

Diff for: src/selectmail.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -393,17 +393,20 @@ msgs_filter::build_query(sql_query& q)
393393
some particular values for the status */
394394
if (m_status == -1 && !m_in_trash && m_status_set==0 && m_status_unset == mail_msg::statusArchived) {
395395
// current and not tagged
396-
q.add_clause(QString("m.mail_id in (SELECT ms.mail_id FROM mail_status ms"
397-
" LEFT OUTER JOIN mail_tags mt ON mt.mail_id=ms.mail_id"
398-
" WHERE mt.mail_id is null AND ms.status&%1=0)")
399-
.arg(mail_msg::statusArchived|mail_msg::statusTrashed));
396+
q.add_clause(QString("(m.status & status_mask('archived'))=0 AND"
397+
" NOT EXISTS (SELECT 1 FROM mail_tags mt"
398+
" WHERE mt.mail_id=m.mail_id)"));
400399
done_with_status=true;
401400
}
402401
else if (m_status==0) {
403-
// new and not tagged
404-
q.add_clause(QString("m.mail_id in (SELECT ms.mail_id FROM mail_status ms"
405-
" LEFT OUTER JOIN mail_tags mt ON mt.mail_id=ms.mail_id"
406-
" WHERE mt.mail_id is null AND ms.status=0)"));
402+
/* New and not tagged.
403+
The (m.status & status_mask('archived')) clause is redundant
404+
with (m.status=0) but it's used to let the planner use the partial
405+
index on current mail. */
406+
q.add_clause("(m.status & status_mask('archived'))=0 AND"
407+
" m.status=0 AND"
408+
" NOT EXISTS (SELECT 1 FROM mail_tags mt"
409+
" WHERE mt.mail_id=m.mail_id)");
407410
done_with_status=true;
408411
}
409412
else {
@@ -606,11 +609,9 @@ msgs_filter::build_query(sql_query& q)
606609
s.sprintf("(status&%d=%d AND status&%d=0)", status_set, status_set, status_unset);
607610
}
608611
else {
609-
if (status_unset == mail_msg::statusArchived ||
610-
status_unset == mail_msg::statusArchived+mail_msg::statusTrashed) {
611-
// unprocessed messages: optimize by joining with mail_status
612-
q.add_table("mail_status ms");
613-
s.sprintf("ms.mail_id=m.mail_id AND ms.status&%d=0", status_unset);
612+
if (status_unset & mail_msg::statusArchived) {
613+
// unprocessed messages: optimize by using the dedicated partial index
614+
s.sprintf("status&status_mask('archived')=0 AND status&%d=0", status_unset);
614615
}
615616
else {
616617
s.sprintf("status&%d=0", status_unset);
@@ -620,9 +621,8 @@ msgs_filter::build_query(sql_query& q)
620621
}
621622
if (m_status!=-1 && !done_with_status) {
622623
if (m_status==0) {
623-
// new messages: optimize by joining with mail_status
624-
q.add_table("mail_status ms");
625-
q.add_clause("ms.mail_id=m.mail_id AND ms.status=0");
624+
// new messages: optimize by using the dedicated partial index
625+
q.add_clause("status&status_mask('archived')=0 AND status=0");
626626
}
627627
else {
628628
QString s;

0 commit comments

Comments
 (0)