The purpose of this task is to ensure that CREATE VIEW is atomic
When a view is created, the definition is first written to a view_name.frm~ and then renamed to
The logic should be
- Log CREATE view to DDL log, with a marker if old view existsted
- If old view exists (in case of CREATE or REPLACE view) make a copy of old view
- Create view
- Delete view copy if it was created.
- Delete view_name.frm~ file.
- If query was logged to binary log
- delete copy of view if it exists
rename the copy of the view over the .frm file (restoring old definition)
One benefit of the new code is that create or replace view is no totally atomic even if there existed an old view: Either the view will be replaced or the old one will be untouched.