Bug 311542

Summary: Same SQL queries performed multiple times when fetching one email
Product: [Frameworks and Libraries] Akonadi Reporter: Alex Richardson <arichardson.kde>
Component: generalAssignee: kdepim bugs <kdepim-bugs>
Status: RESOLVED UNMAINTAINED    
Severity: normal CC: Martin
Priority: NOR    
Version: 4.10   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: The MySQL log
The same log piped through sort and uniq -c

Description Alex Richardson 2012-12-11 20:06:44 UTC
I enabled logging SQL queries for MySQL and saw that whenever I click on an email in kontact lots of SQL queries are being performed. After looking at the log I saw that they were also very similar/identical.
There is only one unique SELECT, the others are being performed at least twice.
Also atime ist updated three times (Also why is this stored anyway? I don't see any reason for it, but I may be wrong)

The attached files contain the log for opening one email

Reproducible: Always

Steps to Reproduce:
1. Open an email in kontact
2. View MySQL log file
Actual Results:  
Duplicate queries

Expected Results:  
Every query should only be performed once
Comment 1 Alex Richardson 2012-12-11 20:07:49 UTC
Created attachment 75787 [details]
The MySQL log
Comment 2 Alex Richardson 2012-12-11 20:09:04 UTC
Created attachment 75788 [details]
The same log piped through sort and uniq -c

As you can see most operations are being performed three times, I think it should be possible to reduce that
Comment 3 Alex Richardson 2012-12-11 20:15:29 UTC
Also the queries in line 5 and 6 of the filtered log could be merged into one:

... WHERE ( ( PartTable.name IN ( 'PLD:RFC822', 'COLLECTIONID', 'ATR:ErrorAttribute' ) OR substr( PartTable.name, 1, 4 ) = ( 'PLD:' ) OR substr( PartTable.name, 1, 4 ) = ( 'ATR:' ) ) AND ( PimItemTable.id = 148263 ) ) ORDER BY PimItemTable.id DESC

... WHERE ( ( PartTable.name IN ( 'PLD:RFC822', 'COLLECTIONID', 'PLD:HEAD' ) OR substr( PartTable.name, 1, 4 ) = ( 'PLD:' ) OR substr( PartTable.name, 1, 4 ) = ( 'ATR:' ) ) AND ( PimItemTable.id = 148263 ) ) ORDER BY PimItemTable.id DESC

The only difference is the third item in the IN (...) clause.

It could be simplified to 

... WHERE ( ( PartTable.name = 'COLLECTIONID' OR substr( PartTable.name, 1, 4 ) = ( 'PLD:' ) OR substr( PartTable.name, 1, 4 ) = ( 'ATR:' ) ) AND ( PimItemTable.id = 148263 ) ) ORDER BY PimItemTable.id DESC

Or maybe even 
... WHERE ( ( PartTable.name = 'COLLECTIONID' OR substr( PartTable.name, 1, 4 ) IN ( 'PLD:',  'ATR:' ) ) AND ( PimItemTable.id = 148263 ) ) ORDER BY PimItemTable.id DESC

which is more readable and could also be faster.
Comment 4 Denis Kurz 2016-09-24 20:40:20 UTC
This bug has only been reported for versions older than KDEPIM 4.14 (at most akonadi-1.3). Can anyone tell if this bug still present?

If noone confirms this bug for a recent version of akonadi (part of KDE Applications 15.08 or later), it gets closed in about three months.
Comment 5 Denis Kurz 2017-01-07 21:35:05 UTC
Just as announced in my last comment, I close this bug. If you encounter it again in a recent version (at least 5.0 aka 15.08), please open a new one unless it already exists. Thank you for all your input.