droptableifexists touch_vacuum_table_record;createtable touch_vacuum_table_record (
touchid intprimarykey,touchuser varchar(64),schemaname varchar(64),tablename varchar(64),statusvarchar(7)default'wait',touchsql varchar(32767),errmsg text,createtime timestampdefaultcurrent_timestamp,begintime timestamp,endtime timestamp)distributedby(touchid);commentontable touch_vacuum_table_record is'触发执行 vacuum analyze 表的记录';commentoncolumn touch_vacuum_table_record.touchid is $$select nextval('req_touchid_vacuum');$$;commentoncolumn touch_vacuum_table_record.touchuser is $$触发用户$$;commentoncolumn touch_vacuum_table_record.schemaname is $$模式名$$;commentoncolumn touch_vacuum_table_record.tablename is $$表名$$;commentoncolumn touch_vacuum_table_record.statusis $$状态,wait(等待)、running(运行中)、run(运行完毕)$$;commentoncolumn touch_vacuum_table_record.touchsql is $$等待运行的sql$$;commentoncolumn touch_vacuum_table_record.errmsg is $$报错信息$$;commentoncolumn touch_vacuum_table_record.createtime is $$触发时间$$;commentoncolumn touch_vacuum_table_record.begintime is $$运行开始时间$$;commentoncolumn touch_vacuum_table_record.endtime is $$运行结束时间$$;
wait_touch_vacuum_table_record
createorreplaceview wait_touch_vacuum_table_record asselect touchid,touchsql,
$$update gpload.touch_vacuum_table_record setstatus='running',begintime =current_timestampwherestatus='wait'and touchid = $$||touchid||$$;$$ as beforesql
,'update gpload.touch_vacuum_table_record set status = ''run'',errmsg = ''$'||'{ERRMSG}'||''',endtime = current_timestamp where status = ''running'' and touchid = '||touchid||';'as aftersql
from touch_vacuum_table_record
wherestatus='wait';