DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `cache`.`available_clean`()
BEGIN
	DROP TEMPORARY TABLE IF EXISTS tCalc;
	CREATE TEMPORARY TABLE tCalc
		(INDEX (id))
		ENGINE = MEMORY
		SELECT id FROM cache_calc;

	DELETE a
		FROM available a
			LEFT JOIN tCalc c ON c.id = a.calc_id
		WHERE c.id IS NULL;
	
	DELETE a
		FROM availableNoRaids a
			LEFT JOIN tCalc c ON c.id = a.calc_id
		WHERE c.id IS NULL;
		
	DROP TEMPORARY TABLE tCalc;
END$$
DELIMITER ;
