Correct bugs in temporary tables management