QUERY_REWRITE_INTEGRITY Property Description Parameter type String Syntax QUERY_REWRITE_INTEGRITY = { enforced | trusted | stale_tolerated } Default value enforced Modifiable ALTER SESSION, ALTER SYSTEM Real Application Clusters Multiple i
QUERY_REWRITE_INTEGRITY
Property | Description |
---|---|
Parameter type | String |
Syntax | QUERY_REWRITE_INTEGRITY = { enforced | trusted | stale_tolerated } |
Default value | enforced |
Modifiable | ALTER SESSION, ALTER SYSTEM |
Real Application Clusters | Multiple instances can have different values. |
QUERY_REWRITE_INTEGRITY determines the degree to which Oracle must enforce query rewriting. At the safest level, Oracle does not use query rewrite transformations that rely on unenforced relationships.
Values:
enforced
Oracle enforces and guarantees consistency and integrity.
trusted
Oracle allows rewrites using relationships that have been declared, but that are not enforced by Oracle.
stale_tolerated
Oracle allows rewrites using unenforced relationships. Materialized views are eligible for rewrite even if they are known to be inconsistent with the underlying detail data.
实验:
TOM书上的例子,我自己做一些实验 大家一起理解
首先我设置 QUERY_REWRITE_INTEGRITY = ENFORCED
TYGER@ORCL>create table emp as select * from scott.emp;
Table created.
TYGER@ORCL>create table dept as select * from scott.dept;
Table created.
TYGER@ORCL>show parameter query
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
query_rewrite_enabled string TRUE
query_rewrite_integrity string enforced
TYGER@ORCL>
TYGER@ORCL>create materialized view emp_dept
2 build immediate
3 refresh on demand
4 enable query rewrite
5 as
6 select dept.deptno,dept.dname,count(*)
7 from emp,dept
8 where emp.deptno=dept.deptno
9 group by dept.deptno,dept.dname
10 /
Materialized view created.
TYGER@ORCL>show parameter optimizer
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
TYGER@ORCL>set autot traceonly explain
TYGER@ORCL>select count(*) from emp;
COUNT(*)
----------
14
Execution Plan
----------------------------------------------------------
Plan hash value: 2083865914
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| EMP | 14 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
TYGER@ORCL>desc emp
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
TYGER@ORCL>desc dept
Name Null? Type
----------------------------------------- -------- ----------------------------
DEPTNO NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
总结: 之所以发生这种情况是由于知道 DEPTNO 是 DEPT 表的主键,DEPTNO 在表 EMP 中应该是 NOT NULL 的,EMP 表的 DEPTNO 应该是基于 DEPT 表 DEPTNO 列的外键,但是由于我们的表没有这个外键约束存在,而 query_rewrite_integrity 又设置为 enforced ,优化器为了得到完整可靠的数据不得不查询基表而得出最终结果。
假如我们加上上面的规则,再看查询结果:
TYGER@ORCL>alter table dept add constraint dept_pk primary key(deptno);
Table altered.
TYGER@ORCL>desc dept
Name Null? Type
----------------------------------------- -------- ----------------------------
DEPTNO NOT NULL NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
TYGER@ORCL>alter table emp
2 add constraint emp_fk_dept
3 foreign key(deptno) references dept(deptno);
Table altered.
TYGER@ORCL>alter table emp modify deptno not null;
Table altered.
TYGER@ORCL>desc emp;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NOT NULL NUMBER(2)
TYGER@ORCL>set autot traceonly explain
TYGER@ORCL>select count(*) from emp;
COUNT(*)
----------
14
Execution Plan
----------------------------------------------------------
Plan hash value: 155013515
--------------------------------------------------------------------------------
----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------------------
----------
| 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)|
00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | |
|
| 2 | MAT_VIEW REWRITE ACCESS FULL| EMP_DEPT | 3 | 39 | 3 (0)|
00:00:01 |
--------------------------------------------------------------------------------
----------
Note
-----
- dynamic sampling used for this statement
可见 当我们将完整性约束全部添加后,优化器有了足够的信息知道这条语句通过物化视图可以查询重写,而不用查询基表,实际的执行情况也印证了这一点。
我们在通过一个例子说明 THUSTED 的情况。我们首先将这些约束去除掉,然后添加一行新的数据
TYGER@ORCL>alter table emp drop constraint emp_fk_dept;
Table altered.
TYGER@ORCL>alter table dept drop constraint dept_pk;
Table altered.
TYGER@ORCL>alter table emp modify deptno null;
Table altered.
TYGER@ORCL>desc dept
Name Null? Type
----------------------------------------- -------- ----------------------------
DEPTNO NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
TYGER@ORCL>desc emp;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
// 插入一条违反实际约束行
TYGER@ORCL>insert into emp(empno,deptno) values(1,1);
1 row created.
TYGER@ORCL>exec dbms_mview.refresh('EMP_DEPT');
PL/SQL procedure successfully completed.
TYGER@ORCL>alter materialized view emp_dept consider fresh;
alter materialized view emp_dept consider fresh
*
ERROR at line 1:
ORA-30374: materialized view is already fresh
// 创建一个 novalidate 的约束
TYGER@ORCL>alter table dept
2 add constraint dept_pk primary key(deptno)
3 rely enable novalidate
4 /
Table altered.
TYGER@ORCL>alter table emp
2 add constraint emp_fk_dept
3 foreign key(deptno) references dept(deptno)
4 rely enable novalidate
5 /
Table altered.
TYGER@ORCL>alter table emp modify deptno not null novalidate;
Table altered.
回到原来的查询,假如 query_rewrite_integrity = enforced 的话,那么我们知道由于上述约束实际上是违反真实数据约束的,因此优化器将不会利用物化视图查询重写。
TYGER@ORCL>show parameter query
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
query_rewrite_enabled string TRUE
query_rewrite_integrity string enforced
TYGER@ORCL>
TYGER@ORCL>set autot traceonly explain
TYGER@ORCL>select count(*) from emp;
COUNT(*)
----------
16
Execution Plan
----------------------------------------------------------
Plan hash value: 2083865914
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| EMP | 16 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
而如果设置 query_rewrite_integrity = trusted 的话,那么优化器因为有了我们上述那个 novalidate约束的误导,它并不真实检验数据的完整性,因此还将会利用物化视图查询重写,尽管这样得出的结果是错误的。只要我们让优化器知道有完整性约束的存在,不管约束严格与否,优化器只要为了这个信息就会尽可能地利用物化视图查询重写。
TYGER@ORCL>alter session set query_rewrite_integrity=trusted;
Session altered.
TYGER@ORCL>select count(*) from emp;
COUNT(*)
----------
14
Execution Plan
----------------------------------------------------------
Plan hash value: 155013515
--------------------------------------------------------------------------------
----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------------------
----------
| 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)|00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | ||
| 2 | MAT_VIEW REWRITE ACCESS FULL| EMP_DEPT | 3 | 39 | 3 (0)|00:00:01 |
--------------------------------------------------------------------------------
----------
Note
-----
- dynamic sampling used for this statement
而 stale_tolerated 就简单了:
/* 结果 我自己做实验却没有得到的想要的结果: */
TYGER@ORCL>show parameter query
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
query_rewrite_enabled string TRUE
query_rewrite_integrity string enforced
// session 级别修改参数
TYGER@ORCL>alter session set query_rewrite_integrity=stale_tolerated;
Session altered.
TYGER@ORCL>show parameter query
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
query_rewrite_enabled string TRUE
query_rewrite_integrity string STALE_TOLERATED
TYGER@ORCL>set autot traceonly explain;
TYGER@ORCL>select count(*) from emp;
Execution Plan
----------------------------------------------------------
Plan hash value: 2083865914
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| EMP | 14 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
// system 级别修改参数 仍然如此
TYGER@ORCL>alter system set query_rewrite_integrity=stale_tolerated;
System altered.
TYGER@ORCL>set autot traceonly explain;
TYGER@ORCL>select count(*) from emp;
Execution Plan
----------------------------------------------------------
Plan hash value: 2083865914
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| EMP | 14 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
// 重新启动数据库 结果依旧
TYGER@ORCL>conn / as sysdba
Connected.
SYS@ORCL>shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@ORCL>startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 71304784 bytes
Database Buffers 209715200 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SYS@ORCL>conn tyger/tyger
Connected.
TYGER@ORCL>show parameter query
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
query_rewrite_enabled string TRUE
query_rewrite_integrity string STALE_TOLERATED
TYGER@ORCL>set autot traceonly explain
TYGER@ORCL>select count(*) from emp;
Execution Plan
----------------------------------------------------------
Plan hash value: 2083865914
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| EMP | 14 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
虽然结果有点不是很满意,但是看完后基本可以了解 query_rewrite_integrity 这个参数了吧
遗留问题:356 行 stale_tolerated 参数设置, 如果看出错误的步骤 欢迎指正。

在这篇文章中,我们将向你展示如何通过拖放在PowerQuery中对多列进行重新排序。通常,从各种来源导入数据时,列可能不是所需的顺序。重新排序列不仅允许您按照符合您的分析或报告需求的逻辑顺序排列它们,还可以提高数据的可读性,并加快过滤、排序和执行计算等任务。如何在Excel中重新排列多个列?在Excel中,重新排列列的方法有多种。您可以简单地选择列标题,然后将其拖动到所需位置。但是,当处理包含许多列的大表时,这种方法可能会变得繁琐。为了更高效地重新排列列,您可以使用增强查询编辑器。通过增强查询编

ReactQuery数据库插件:实现数据导入和导出的方法,需要具体代码示例随着ReactQuery在前端开发中的广泛应用,越来越多的开发者开始使用它来管理数据。而在实际开发中,我们经常需要将数据导出到本地文件或从本地文件导入数据到数据库中。为了更方便地实现这些功能,可以使用ReactQuery数据库插件。ReactQuery数据库插件提供了一系列方

url跳转这里说的url跳转就是用户在访问一个url时将其跳转到另一个url上。常见的应用场景是让多个域名跳转到同一个url上,(例如让旧域名跳转到新域名上)将静态文件请求跳转到cdn上等根据用户设备跳转到不同站点(pc版,wap版)等。url跳转可以通过js在页面上设置的window.location实现也可以通过php设置header来实现当然也可以用nginx的rewrite功能实现nginxrewrite模块rewrite是nginx的静态重写模块基本用法是rewritepattenre

本文将介绍如何使用PowerQuery将数据进行行拆分。在从其他系统或源导出数据时,常常会遇到数据存储在单元格中组合多个值的情况。通过PowerQuery,我们可以轻松将这样的数据拆分成行,使得数据更易于处理和分析。若用户不了解Excel的规则并意外将多个数据输入到一个单元格,或者在从其他来源复制/粘贴数据时未正确格式化,就会出现这种情况。要处理这些数据,需要额外的步骤来提取和整理信息,以便进行分析或报告。如何在PowerQuery中拆分数据?PowerQuery转换可以根据各种不同因素(例如字

location教程示例:location=/{#精确匹配/,主机名后面不能带任何字符串[configurationA]}location/{#因为所有的地址都以/开头,所有这条规则将匹配到所有请求#但是正则和最长字符串会优先匹配[configurationB]}location/documents/{#匹配任何以/documents/开头的地址,匹配符合以后,还要继续往下搜索#只有后面的正则表达式没有匹配到时,这一条才会采用[configurationC]}location~/document

ReactQuery数据库插件:实现数据备份和还原的策略,需要具体代码示例引言:在现代的Web开发中,数据的备份和还原是非常重要的一项任务。特别是在使用ReactQuery这样的状态管理工具时,我们需要确保数据的安全性和可靠性。本文将介绍一种基于ReactQuery的数据库插件,用于实现数据备份和还原的策略,并提供具体的代码示例。ReactQu

一、背景介绍企业数字化是近年来很热的一个话题,它是指运用人工智能、大数据、云计算等新一代数字技术,改变企业的业务模式,从而推动企业业务产生新的增长。企业数字化一般来说包括业务经营的数字化和企业管理的数字化。本次分享主要介绍企业管理层面的数字化。信息数字化,简单来说,就是把信息用数字化的方式进行读写、存储和传递。从以前的纸质文档到现在的电子文档以及在线协同文档,信息数字化已经变成了现在办公的新常态。目前阿里使用钉钉文档和语雀文档进行业务协同,在线文档数量已经达到了2000万以上。另外很多企业内部会

应用场景1——基于域名的跳转公司旧域名,因业务需求有变更,需要使用新域名www.kgc.com代替1.不能废除旧域名2.从旧域名跳转到新域名,且保持其参数不变部署环境一台linux服务器(192.168.142.130)一台测试主机windows71,安装nginx服务[root@localhost~]#rpm-uvhhttp://nginx.org/packages/centos/7/noarch/rpms/nginx-release-centos-7-0.el7.ngx.noarch.rpm


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
