Here's a version that I'm testing now. It fixes the CurrentDbAttrCount and HasAttributes values that were not reporting correctly in jamo's post. I am no one as far as mysql goes but I've been bashing on this for a couple hours.
The missing index was not implemented on my db.
Thanks jamo, buckle, bulek, tschak, and others for working on this query! This has been a great collaboration!
SELECT
File.PK_File,
File.Path,
File.Filename,
File.Inode,
s.CurrentDbAttrDate,
s.CurrentDbAttrCount,
s.HasAttributes,
File.AttrDate AS OldDbAttrDate,
File.AttrCount AS OldDbAttrCount,
File.ModificationDate AS OldFileDate,
File.Source
FROM
(
SELECT
PK_File,
greatest(
(IF(Bookmark.psc_mod IS NULL, CAST('0000-00-00 00:00:00' AS DATE),Bookmark.psc_mod)),
(IF(Attribute.psc_mod IS NULL,CAST('0000-00-00 00:00:00' AS DATE), Attribute.psc_mod)),
(IF(LongAttribute.psc_mod IS NULL,CAST('0000-00-00 00:00:00' AS DATE), LongAttribute.psc_mod)),
(IF(Picture_File.psc_mod IS NULL,CAST('0000-00-00 00:00:00' AS DATE), Picture_File.psc_mod)) ) As CurrentDbAttrDate,
(select count(*) from Bookmark where FK_File=PK_File) as BOOKMARKCOUNT,
(select count(*) from File_Attribute where FK_File=PK_File) as ACOUNT,
(select count(*) from LongAttribute where FK_File=PK_File) as LONGATTRCOUNT,
(select count(*) from Picture_File where FK_File=PK_File) as IMGCOUNT,
((1000000 * (select BOOKMARKCOUNT)) +
(10000 * (select ACOUNT)) +
(100 * (select LONGATTRCOUNT)) +
(select IMGCOUNT)) as CurrentDbAttrCount,
((select ACOUNT) + (select LONGATTRCOUNT)) as HasAttributes
FROM File
LEFT JOIN Bookmark ON Bookmark.FK_File = PK_File
LEFT JOIN File_Attribute ON File_Attribute.FK_File = PK_File
LEFT JOIN Attribute ON File_Attribute.FK_Attribute = PK_Attribute
LEFT JOIN LongAttribute ON LongAttribute.FK_File = PK_File
LEFT JOIN Picture_File ON Picture_File.FK_File = PK_File
WHERE 1 = 1
AND ( Path LIKE '/home/public/data%' OR (Path ='/home/public' AND Filename = 'data' )
OR Path LIKE '/home/user_1/data%' OR (Path = '/home/user_1' AND Filename = 'data' )
OR Path LIKE '/home/user_2/data%' OR (Path = '/home/user_2' AND Filename = 'data' )
OR Path LIKE '/home/user_3/data%' OR (Path = '/home/user_3' AND Filename = 'data' )
OR Path LIKE '/home/user_4/data%' OR (Path = '/home/user_4' AND Filename = 'data' )
OR Path LIKE '/home/user_5/data%' OR (Path = '/home/user_5' AND Filename = 'data' )
OR Path LIKE '/home/user_6/data%' OR (Path = '/home/user_6' AND Filename = 'data' )
OR Path LIKE '/home/user_7/data%' OR (Path = '/home/user_7' AND Filename = 'data' )
OR Path LIKE '/home/user_8/data%' OR (Path = '/home/user_8' AND Filename = 'data' ) )
AND Missing = 0
GROUP BY PK_File
) s
INNER JOIN File ON s.PK_File=File.PK_File;
J.