Oracle 如何通过 VIEW 实现 SQL 查询
How does Oracle implement an SQL query over a VIEW
我们使用 SQL 查询(SQL query1)
在基础 table 上定义了一个视图
我正在尝试了解如何通过视图查询(SQL query2)
当我运行一个SQL一个VIEW时,Oracle是否首先执行query1来创建一个temp table然后运行 query2温度 table ?
或者它是否通过组合 query1 和 query2 来创建单个复合查询以给出结果
(如果 运行 直接在基础 table 上,我的查询 2 具有高选择性,并且复合查询应该 运行 比先执行查询 1 快得多)
- Or does it create a single composite query by combining query1 and query2 in order to give the result
是的,CBO(Oracle 基于成本的优化器)扩展最终查询并对其进行转换并构建执行计划,您可以在跟踪 10053(优化器跟踪)中检查 final query after transformation
或使用 DBMS_UTILITY.EXPAND_SQL_TEXT
注意。 DBMS_UTILITY.EXPAND_SQL_TEXT在12.1已经出现,但是你打了Oracle 11g,所以需要用dbms_sql2.expand_sql_text
,例子:https://github.com/xtender/xt_scripts/blob/master/expand_11.sql
我们使用 SQL 查询(SQL query1)
在基础 table 上定义了一个视图我正在尝试了解如何通过视图查询(SQL query2)
当我运行一个SQL一个VIEW时,Oracle是否首先执行query1来创建一个temp table然后运行 query2温度 table ?
或者它是否通过组合 query1 和 query2 来创建单个复合查询以给出结果
(如果 运行 直接在基础 table 上,我的查询 2 具有高选择性,并且复合查询应该 运行 比先执行查询 1 快得多)
- Or does it create a single composite query by combining query1 and query2 in order to give the result
是的,CBO(Oracle 基于成本的优化器)扩展最终查询并对其进行转换并构建执行计划,您可以在跟踪 10053(优化器跟踪)中检查 final query after transformation
或使用 DBMS_UTILITY.EXPAND_SQL_TEXT
注意。 DBMS_UTILITY.EXPAND_SQL_TEXT在12.1已经出现,但是你打了Oracle 11g,所以需要用dbms_sql2.expand_sql_text
,例子:https://github.com/xtender/xt_scripts/blob/master/expand_11.sql