(SELECT \`uri-id\` FROM \`post-thread\` WHERE \`received\` < (CURDATE() - INTERVAL $interval DAY)\
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-thread-user\`\
WHERE (\`mention\` OR \`starred\` OR \`wall\`) AND \`uri-id\`=\`post-thread\`.\`uri-id\`)\
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-category\`\
WHERE \`uri-id\`=\`post-thread\`.\`uri-id\`)\
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-collection\`\
WHERE \`uri-id\`=\`post-thread\`.\`uri-id\`)\
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-media\`\
WHERE \`uri-id\`=\`post-thread\`.\`uri-id\`)\
AND NOT \`uri-id\` IN (SELECT \`parent-uri-id\` FROM \`post-user\` INNER JOIN \`contact\` ON \`contact\`.\`id\`=\`contact-id\` AND \`notify_new_posts\`\
WHERE \`parent-uri-id\`=\`post-thread\`.\`uri-id\`)\
AND NOT \`uri-id\` IN (SELECT \`parent-uri-id\` FROM \`post-user\`\
WHERE (\`origin\` OR \`event-id\` !=0 OR \`post-type\`= 128) AND \`parent-uri-id\`=\`post-thread\`.\`uri-id\`)\
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-content\`\
WHERE \`resource-id\` !=0 AND \`uri-id\`=\`post-thread\`.\`uri-id\`))\
"CREATE TEMPORARY TABLE \`tmp-item-uri-not-in-valid-post-user\` (SELECT \`id\` FROM \`item-uri\` WHERE \`id\` IN (SELECT \`uri-id\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`uid\` = 0 \
AND \`received\` < (CURDATE() - INTERVAL $interval DAY)\
AND NOT \`uri-id\` IN (\
SELECT \`parent-uri-id\` FROM \`post-user\` AS \`i\` WHERE \`i\`.\`uid\` !=0 AND \`i\`.\`parent-uri-id\`=\`post-user\`.\`uri-id\`\
) AND NOT \`uri-id\` IN (\
SELECT \`parent-uri-id\` FROM \`post-user\` AS \`i\` WHERE \`i\`.\`uid\`=0 AND \`i\`.\`parent-uri-id\`=\`post-user\`.\`uri-id\` AND \`i\`.\`received\` > (CURDATE() - INTERVAL $interval DAY)\
"CREATE TEMPORARY TABLE \`tmp-attach-not-in-post-media\` (SELECT \`id\` FROM \`attach\` WHERE \`id\` NOT IN (SELECT \`attach-id\` FROM \`post-media\`)); \
DELETE FROM \`attach\` WHERE \`id\` IN (SELECT * FROM \`tmp-attach-not-in-post-media\`);"
"CREATE TEMPORARY TABLE \`tmp-post-media-duplicate\` (SELECT \`id\` FROM \`post-media\` u1 INNER JOIN \`post-media\` u2 WHERE u1.\`id\` < u2.\`id\` AND u1.\`uri-id\` = u2.\`uri-id\` AND u1.\`url\`= u2.\`url\`); \
DELETE FROM \`post-media\` WHERE \`id\` IN (SELECT * FROM \`tmp-post-media-duplicate\`);"