From e52b57b7a9f0303c0c710e60870d0ec265d32541 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Mon, 1 Dec 2014 14:11:19 +0100 Subject: [PATCH 19/30] Optimize queries: Do not retrieve known key used in the condition. There is no point in doing a select like: SELECT foo, bar FROM table WHERE foo = needle; That can be rewritten to say SELECT bar FROM table WHERE foo = needle; This reduces the data traffic with the mysql server. Additionally, it work-arounds some issues in Qt SQL, which lead to bad performance: QSqlResult::value incurs multiple temporary allocations, and string conversions, even to read a simple integer ID for example. Finally, by reusing an externally provided QString name e.g., we can leverage Qt's implicit sharing, instead of duplicating the string in a separate QString instance, with the contents read from SQL server. REVIEW: 121310 --- server/src/storage/entities.xsl | 50 +++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/server/src/storage/entities.xsl b/server/src/storage/entities.xsl index 9471293..c8fb1fd 100644 --- a/server/src/storage/entities.xsl +++ b/server/src/storage/entities.xsl @@ -104,6 +104,12 @@ Q_DECLARE_TYPEINFO( Akonadi::Server::, Q_MOVABLE_T using namespace Akonadi::Server; +static QStringList removeEntry(QStringList list, const QString& entry) +{ + list.removeOne(entry); + return list; +} + @@ -179,7 +185,8 @@ set( ) return (); QueryBuilder qb( tableName(), QueryBuilder::Select ); - qb.addColumns( columnNames() ); + static const QStringList columns = removeEntry(columnNames(), Column()); + qb.addColumns( columns ); qb.addValueCondition( Column(), Query::Equals, ); if ( !qb.exec() ) { akDebug() << "Error during selection of record with " @@ -191,21 +198,36 @@ set( ) return (); } + + int valueIndex = 0; + + const value = + + + ; + + + (qb.query().isNull(valueIndex)) ? + () : + + + Utils::variantToString( qb.query().value( valueIndex ) ) + + + static_cast<Tristate>(qb.query().value( valueIndex ).value<int>()) + + + qb.query().value( valueIndex ).value<>() + + + ; ++valueIndex; + + + + rv( - (qb.query().isNull()) ? - () : - - - Utils::variantToString( qb.query().value( ) ) - - - static_cast<Tristate>(qb.query().value( ).value<int>()) - - - qb.query().value( ).value<>() - - + value , ); -- 2.1.0