oracle scalar subquery caching

这是oracle特有的特性,当对于子查询未展开(包括标量子查询)时,oracle会维护一个hash table的内存区域缓存,对于重复的关联列,并不需要重复的执行子查询。该特性在Cost Based Oracle Fundamental书中有介绍。

Oracle limits the size of the in-memory hash table (presumably to stop excessive memory consumption in unlucky cases).In 8i and 9i the limit on the size of the hash table seems to be 256 entries, in 10g it seems to be
1,024.This means the performance of a subquery filter can be affected by the number of different driving values that exist, the order in which they appear in the pass through the driving table,and the actual values. If the hash table is simply too small, or you have driving values that just happen to cause excessive collisions on the hash table, then you may execute the subquery far more frequently than is strictly necessary.

内存大小由参数”_query_execution_cache_max_size“控制

测试验证:

可以看到外表查询返回了73257条记录,但是标量子查询只执行了130次。这其实与t表关联列object_type的distinct值有关系

可以看到distinct值为47,那么应该只执行47次才对,为什么执行了130次呢?那是因为”_query_execution_cache_max_size“不够大。

增大缓存大小之后,可以看到标量子查询只执行了外表关联列的distinct值次数。该特性对于子查询未展开走filter的情况同样适用。并且这个特性是国产数据库普遍不支持的特性,确实还需要向oracle多多借鉴。

此条目发表在Oracle, Oralce performance分类目录,贴了标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注