Hello All,
I'm currently maintaining a decently high-traffic site (40,000-50,000+ visitors a day) with a gallery having about 22,000 images. Images are linked in various areas of the site and show up as users browser content etc.
At the moment, whenever items are added to the live portions of the gallery, the database tends to spike some really hefty traffic. The slow queries log is showing mostly SELECT's looknig like:
# Query_time: 51 Lock_time: 0 Rows_sent: 4 Rows_examined: 1334128
SELECT g2_ImageBlockCacheMap.g_itemId, g2_ItemAttributesMap.g_viewCount FROM g2_ImageBlockCacheMap LEFT JOIN g2_ImageBlockDisabledMap ON g2_ImageBlockCacheMap.g_itemId=g2_ImageBlockDisabledMap.g_itemId
LEFT JOIN g2_PhotoItem ON g2_ImageBlockCacheMap.g_itemId=g2_PhotoItem.g_id, g2_ItemAttributesMap WHERE g2_PhotoItem.g_width > g2_PhotoItem.g_height AND g2_ImageBlockCacheMap.g_userId = 5 AND g2_ImageBlockCacheMap.g_itemType = 1 AND g2_ImageBlockDisabledMap.g_itemId IS NULL AND g2_ImageBlockCacheMap.g_itemId = g2_ItemAttributesMap.g_itemId AND g2_ItemAttributesMap.g_parentSequence LIKE '7/10/2885/137058/%' ORDER BY RAND() LIMIT 4;
# Query_time: 75 Lock_time: 13 Rows_sent: 0 Rows_examined: 983136
SELECT g2_ImageBlockCacheMap.g_itemId, g2_ItemAttributesMap.g_viewCount FROM g2_ImageBlockCacheMap LEFT JOIN g2_ImageBlockDisabledMap ON g2_ImageBlockCacheMap.g_itemId=g2_ImageBlockDisabledMap.g_itemId, g2_ItemAttributesMap, g2_Item WHERE g2_ImageBlockCacheMap.g_userId = 5 AND g2_ImageBlockCacheMap.g_itemType = 1 AND g2_ImageBlockDisabledMap.g_itemId IS NULL AND g2_ImageBlockCacheMap.g_itemId = g2_ItemAttributesMap.g_itemId AND g2_Item.g_id = g2_ImageBlockCacheMap.g_itemId AND g2_Item.g_keywords LIKE '%american-ironhorse%' AND g2_Item.g_keywords LIKE '%somevalue%' AND g2_Item.g_keywords LIKE '%2006%' AND g2_Item.g_keywords LIKE '%someothervalue%' AND g2_Item.g_keywords LIKE '%base%' ORDER BY RAND() LIMIT 5;
etc
Any thoughts on how I can tweak the performance of this database so that it's not dragging in the mud with these? I've added an index to g_itemId on the ImageBlockCacheMap table, as well as a few other odd things to improve performance, but I'd value any advice from those running high-access galleries out there.