Rex Dieter adf30a
From 7cbff48f5782d1f7f844678e6b785aeb419b0c47 Mon Sep 17 00:00:00 2001
Rex Dieter adf30a
From: Milian Wolff <mail@milianw.de>
Rex Dieter adf30a
Date: Mon, 1 Dec 2014 11:59:12 +0100
Rex Dieter adf30a
Subject: [PATCH 18/30] Optimize: Skip value condition on invalid flags.
Rex Dieter adf30a
Rex Dieter adf30a
HandlerHelper::itemWithFlagsCount gets called quite often apparently
Rex Dieter adf30a
and I noticed that it was relatively slow from the Query Debugger
Rex Dieter adf30a
in Akonadi Console. EXPLAIN'ing the query showed that it was using
Rex Dieter adf30a
a slow-path for the WHERE FOO AND (BAR OR ASDF) condition. Here,
Rex Dieter adf30a
ASDF was always id = -1, the id of the $IGNORED flag, which
Rex Dieter adf30a
I apparently don't have. Getting rid of that condition simplifies
Rex Dieter adf30a
the query to WHERE FOO AND BAR, which is apparently much better
Rex Dieter adf30a
optimizable. Before, the query often showed a runtime of ~15ms.
Rex Dieter adf30a
Now it is down to ~9ms.
Rex Dieter adf30a
Rex Dieter adf30a
REVIEW: 121306
Rex Dieter adf30a
---
Rex Dieter adf30a
 server/src/handlerhelper.cpp | 4 ++++
Rex Dieter adf30a
 1 file changed, 4 insertions(+)
Rex Dieter adf30a
Rex Dieter adf30a
diff --git a/server/src/handlerhelper.cpp b/server/src/handlerhelper.cpp
Rex Dieter adf30a
index 634a26c..82347b4 100644
Rex Dieter adf30a
--- a/server/src/handlerhelper.cpp
Rex Dieter adf30a
+++ b/server/src/handlerhelper.cpp
Rex Dieter adf30a
@@ -123,6 +123,10 @@ int HandlerHelper::itemWithFlagsCount( const Collection &col, const QStringList
Rex Dieter adf30a
   // it hits an in-memory cache.
Rex Dieter adf30a
   Q_FOREACH ( const QString &flag, flags ) {
Rex Dieter adf30a
     const Flag f = Flag::retrieveByName( flag );
Rex Dieter adf30a
+    if (!f.isValid()) {
Rex Dieter adf30a
+      // since we OR this condition, we can skip invalid flags to speed up the query
Rex Dieter adf30a
+      continue;
Rex Dieter adf30a
+    }
Rex Dieter adf30a
     cond.addValueCondition( PimItemFlagRelation::rightFullColumnName(), Query::Equals, f.id() );
Rex Dieter adf30a
   }
Rex Dieter adf30a
   qb.addCondition( cond );
Rex Dieter adf30a
-- 
Rex Dieter adf30a
2.1.0
Rex Dieter adf30a