Bug 273852

Summary: MYSQL : showing only one tag results in photos where this tag is not set
Product: [Applications] digikam Reporter: Frank Hommes <freanki>
Component: Database-MysqlAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: caulier.gilles, swatilodha27, vivo75+kde
Priority: NOR    
Version: 1.9.0   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In: 5.0.0
Sentry Crash Report:

Description Frank Hommes 2011-05-22 17:12:15 UTC
Version:           1.9.0 (using KDE 4.6.2) 
OS:                Linux

I click on tags on the left side and choose a specific tag. This tag (database id 292)  is set on ~13000 pictures.
But the search displays several images with another tag (database id 41).

I looked up the pictures in the mysql database and I can confirm that there is no tag id 292 on those pictures the search result for id 41 gives back.

After some investigation there is something wrong with all tag searches.

Reproducible: Always

Steps to Reproduce:
Choose a tag from the tag search.

Actual Results:  
Wrong images.

Expected Results:  
Right images.

Couldn't find that it's already fixed.
Comment 1 Marcel Wiesweg 2011-05-23 20:16:56 UTC
You double checked that 41 is not a child of 292 and "include tag subtree" is checked?
Comment 2 Frank Hommes 2011-05-23 20:27:08 UTC
Yes, I haven't checked "include tag subtree" and it's not a child of 292.
They are both in different groups.

This actually happens quite often not just with one tag-id.
Comment 3 Marcel Wiesweg 2011-05-23 20:50:59 UTC
I am testing with 2.0 and SQlite, so chances are I cannot reproduce this.

The relevant SQL is
SELECT DISTINCT Images.id, Images.name, Images.album,
                                    Albums.albumRoot,
                                    ImageInformation.rating, Images.category,
                                    ImageInformation.format, ImageInformation.creationDate,
                                    Images.modificationDate, Images.fileSize,
                                    ImageInformation.width, ImageInformation.height
                            FROM Images
                                    INNER JOIN ImageInformation ON Images.id=ImageInformation.imageid
                                    INNER JOIN Albums ON Albums.id=Images.album
                            WHERE Images.status=1 AND Images.id IN
                                    (SELECT imageid FROM ImageTags
                                    WHERE tagid=:tagID );

so the relevant subquery is 
SELECT imageid FROM ImageTags WHERE tagid=:tagID
which is simple enough.
Comment 4 Frank Hommes 2011-05-23 21:07:50 UTC
SELECT imageid FROM ImageTags WHERE tagid='292'
gives the right images back.

Digikam remains buggy.
Comment 5 Francesco Riosa 2011-05-24 23:40:22 UTC
confirmed; in mysql it is:

SELECT DISTINCT Images.id, Images.name, Images.album,
        Albums.albumRoot,
        ImageInformation.rating, Images.category,
        ImageInformation.format, ImageInformation.creationDate,
        Images.modificationDate, Images.fileSize,
        ImageInformation.width, ImageInformation.height
FROM Images
        INNER JOIN ImageInformation ON Images.id=ImageInformation.imageid
        INNER JOIN Albums ON Albums.id=Images.album
WHERE Images.status=1 AND Images.id IN
        (
        SELECT imageid 
        FROM ImageTags
        WHERE tagid=? 
           OR tagid IN (SELECT id FROM Tags WHERE lft BETWEEN (SELECT lft FROM Tags WHERE id=?) AND (SELECT rgt FROM Tags WHERE id=?))
        )
need to review the thing (tomorrow?)
Comment 6 Marcel Wiesweg 2011-05-28 15:34:30 UTC
Francesco: According to the description, the bug also appears with the non-recursive tag listing (not "Include tags subtree") which should employ the much simpler version above.
So we should double check that it indeed occurs with the non-recursive mode, and that also the simpler SQL is called by the ioslave (debug output from ioslave is easy to get, into ~/.xsession-errors), and see why this call breaks.
Comment 7 Frank Hommes 2011-05-29 12:08:08 UTC
Because of localisation I got confused with "include tag-subtree" and "include album tag-subtree".

I had "include tag-subtree" checked and when I discheck it, I get the right results.

Anyway, there are no subtree's to the tags but it still messes up all the search results...

It should give the same results since there are no subtags involved...
Comment 8 Marcel Wiesweg 2011-05-29 17:07:40 UTC
Ok, then it is most probably a problem with the TagsTree handling under MySQL, and under SQLite I will never see any problem.
Comment 9 swatilodha27 2016-05-25 09:33:25 UTC
(In reply to Frank Hommes from comment #0)
> Version:           1.9.0 (using KDE 4.6.2) 
> OS:                Linux
> 
> I click on tags on the left side and choose a specific tag. This tag
> (database id 292)  is set on ~13000 pictures.
> But the search displays several images with another tag (database id 41).
> 
> I looked up the pictures in the mysql database and I can confirm that there
> is no tag id 292 on those pictures the search result for id 41 gives back.
> 
> After some investigation there is something wrong with all tag searches.
> 
> Reproducible: Always
> 
> Steps to Reproduce:
> Choose a tag from the tag search.

Do your mean searching by tags from left sidebar->advanced search from search tab ?
> 
> Actual Results:  
> Wrong images.
> 
> Expected Results:  
> Right images.
> 
> Couldn't find that it's already fixed.

I think it gives the correct results according to the tags. You need to make sure that the parent tag is not selected while searching for a specific image using tags.
Comment 10 swatilodha27 2016-05-25 20:21:34 UTC
(I use digikam 5.0.0-beta6)
Steps to reproduce:

Added several images and assigned tags to all of them. I used several tags which are common for multiple images. From the left sidebar, use Advanced Search from the Search tab. Use search by "tags". 

Actual results:

On searching by 1 or 2 or multiple tags, all the required images are retrieved. If parent tag is not selected, only the images containing that specific tag are retrieved. Else, images with both child and parent tags are retrieved. 

Expected results:

Same as actual results.