暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 虚拟列的优点

askTom 2016-08-30
853

问题描述

大家好,

今天我有个简短的问题要问你。

我正在创建一个大的(按行)表,该表将按月进行查询,主要用于报告目的(每行表示一天,并有一个日期列).

通常,当我必须设计一个类似于这个表的表时,我会创建一个额外的列-月-并对该列建立索引,以便加快报表查询的速度。

感谢问汤姆团队,我现在知道虚拟列。使用此Oracle功能,我可以创建一个虚拟列“月”,从“日期”列计算出来,并对其进行索引。这将节省一些有关存储数据的空间。

然而,我意识到,太空的好处是我所知道的唯一好处。而且使用这种方法可能也有一些缺点。

你能说明一下在这两种方法中选择的优点和缺点是什么吗(额外物理列+索引VS虚拟列+索引)?你能推荐另一种方法吗?

谢谢你的时间和帮助

专家解答

好吧,在优势阵营:

-该值始终与源数据同步。即您的虚拟月份不能与日期列中的月份不同。这可以通过物理列来实现(除非添加约束)。
-它们占用的空间最小
- CBO可以像普通的专栏一样收集他们的数据

不利的一面是:

-它们在运行时计算。这可能会减慢您的查询速度。特别是如果它基于PL/SQL函数
-有一些限制:

- You can create virtual columns only in relational heap tables. Virtual columns are not supported for index-organized, external, object, cluster, or temporary tables.

- The column_expression in the AS clause has the following restrictions:
- It cannot refer to another virtual column by name.
- Any columns referenced in column_expression must be defined on the same table.
- It can refer to a deterministic user-defined function, but if it does, then you cannot use the virtual column as a partitioning key column.
- The output of column_expression must be a scalar value.

- The virtual column cannot be an Oracle supplied data type, a user-defined type, or LOB or LONG RAW.

- You cannot specify a call to a PL/SQL function in the defining expression for a virtual column that you want to use as a partitioning column.


http://docs.oracle.com/database/121/SQLRF/statements_7002.htm#BABIIGBD

但是,除非您受到上述限制的影响,或者性能非常关键,否则我建议将它们用于计算值!

如果您想了解更多详情,阿德里安·比林顿将在以下网站详细讨论这些问题:

http://www.oracle-developer.net/display.php?id=510
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论