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