truncate和delete的一些东西

在Mysql中 TRUNCATE 是 DDL(数据定义语言), DELETE 是 DML(数据操作语言)
所以 truncate 操作是无法在事务中回滚的
不过在PostgreSQL中, truncate 操作是可以在事务中回滚的!
不过truncate和delete还是有区别的:

Truncate会阻止其他事务,或者被其他事务阻止,这会降低整个系统的并发能力。
详见:http://blog.itpub.net/133735/viewspace-732292/

DELETE 语句每次删除一行,并在事务日志中为所删除的每行记录一项。TRUNCATE TABLE 通过释放存储表数据所用的数据页来删除数据,并且只在事务日志中记录页的释放。
详见: http://blog.chinaunix.net/uid-22891521-id-2109647.html

鉴于此,我们还是要避免在EDW层和AGG层使用truncate命令。

TRUNCATE is transaction-safe with respect to the data in the tables: the truncation will be safely rolled back if the surrounding transaction does not commit.

猜你喜欢

转载自blog.csdn.net/qq_22994783/article/details/81702204