关于表压缩
表压缩的目的,主要是节省磁盘空间,减少数据库buffer cache内存使用,并且可以显著加速查询效率。压缩本身肯定会增加CPU的压力,但相对于减少的I/O消耗来说,还是很值得的。
参考Oracle官方的说明:
As your database grows in size, consider using table compression. Compression saves disk space, reduces memory use in the database buffer cache, and can significantly speed query execution during reads. Compression has a cost in CPU overhead for data loading and DML. However, this cost might be offset by reduced I/O requirements
压缩表
压缩表,属于基本压缩(Compress for BASIC),只有当数据是直接路径插入或更新记录(direct-path insert and updated )时才会发生压缩。 并且支持有限的数据类型和SQL操作。
如何启用基本压缩?
1)通过create table语句中指定compress条件。
2)通过alter table .. compress; 来给现有表启用压缩;
3)通过alter table .. nocompress; 来禁用表压缩
对于压缩表,通过直接路径插入的数据,会占用更少的数据块。
压缩表的技术限制
- 不允许在压缩表上增加一个带默认值的列
- 不允许删除压缩表上的列
- 不支持在线段收缩(Online segment shrink)
- 不支持SecureFiles large objects
- 压缩表创建时默认设置PCT_FREE 为 0,除非手工指定
常见问题
压缩表的字段变更
在使用常规方式删除压缩表的字段时,可能会报:ORA-39726错误。
ORA-39726 unsupported add/drop column operation on compressed tables
为此,需要通过如下语句实现删除操作:
ALTER TABLE TABLE_NAME SET UNUSED COLUMN COLUMN_NAME;