ORACLE SAMPLE block

最近发现一个有意思的语法,采样扫描,这种语法适用的场合是那种非常大的表,半天查不出来就可以用,或是一些非重要的统计功能,只想知道一个大概。按采样扫描的维度不一样,有两种语法:

sample  按记录采样

sample block  按数据块采样

如果不知道什么是数据块那你很可能听不懂。

SQL> drop table test purge;

SQL> create table test as select * from dba_objects;

sample([0.000001,100])

SQL> select count(*) from test;

COUNT(*)

----------

74105

SQL> select count(*) from test sample(10);

COUNT(*)

----------

7434

SQL> select count(*) from test sample(20);

COUNT(*)

----------

14869

SQL> select count(*) from test sample(50);

COUNT(*)

----------

37210

SQL> select count(*) from test sample(80);

COUNT(*)

----------

59505

SQL> select count(*) from test sample(99);

COUNT(*)

----------

73303

sample block([0.000001,100])

SQL> select count(*) from test sample block(10);

COUNT(*)

----------

8830

SQL> select count(*) from test sample block(20);

COUNT(*)

----------

10456

SQL> select count(*) from test sample block(50);

COUNT(*)

----------

47723

SQL> select count(*) from test sample block(80);

COUNT(*)

----------

62941

SQL> select count(*) from test sample block(99);

COUNT(*)

----------

73232

官方文档:

sample_clause

The sample_clause lets you instruct Oracle to select from a random sample of rows from the table, rather than from the entire table.

BLOCK

BLOCK instructs Oracle to perform random block sampling instead of random row sampling.

sample_percent

sample_percent is a number specifying the percentage of the total row or block count to be included in the sample. The value must be in the range .000001 to (but not including) 100.

Restrictions on Sampling During Queries

You can specify SAMPLE only in a query that selects from a single table. Joins are not supported. However, you can achieve the same results by using a CREATE TABLE ... AS SELECT query to materialize a sample
of an underlying table and then rewrite the original query to refer to the newly created table sample. If you wish, you can write additional queries to materialize samples for other tables.

When you specify SAMPLE, Oracle automatically uses cost-based optimization. Rule-based optimization is not supported with this clause.

--------------------------------------------------------------------------------

Caution:

The use of statistically incorrect assumptions when using this feature can lead to incorrect or undesirable results.

--------------------------------------------------------------------------------

ORACLE SAMPLE block,布布扣,bubuko.com

时间: 2024-10-07 14:22:11

ORACLE SAMPLE block的相关文章

Oracle corrupt block(坏块) 详解

转自:http://blog.csdn.net/tianlesoftware/article/details/5024966 一. 坏块说明 1.1 相关链接 在看坏块之前,先看几个相关的链接,在后面的说明中,会用到链接中的一些内容. ORA-600 各个参数含义说明 http://blog.csdn.net/tianlesoftware/article/details/6645809 Oracle 不同故障的恢复方案 http://blog.csdn.net/tianlesoftware/ar

Oracle 10g Block Change Tracking特性

Using Block Change Tracking to Improve Incremental Backup Performance 使用块改变跟踪改善增量备份的性能 The block change tracking feature for incremental backups improves backup performance by recording changed blocks for each data file.    块改变跟踪特性通过记录每个数据文件的块改变来改善增量

Oracle Log Block Size

Although the size of redo entries is measured in bytes, LGWR writes the redo to the log files on disk in blocks. The size of redo log blocks is fixed in the Oracle source code and is operating system specific. Oracle's documentation uses the term "op

oracle block corrupt 坏块

整体上来讲,oracle的坏块能够分为两种情景:物理损坏和逻辑损坏.物理损坏是因为存储等原因造成的,致使oracle在处理数据块时发现块的checksum不一致.逻辑损坏多是因为oracle的bug或者内存错误引起,通过检測数据块的checksum并不会发现什么问题,可是在逻辑上这些块已经发生了损坏. oracle通过两个參数来控制对物理损坏和逻辑损坏的检測: SQL> show parameter db_block_check NAME TYPE VALUE -----------------

Oracle Study之案例--Oracle 数据块地址(Block Address)

Oracle Study之案例--Oracle 数据块地址(Block Address) Oracle访问数据是以block为单位,本文简单介绍了如何通过Block Address在内存中获取所需要的block. DBA(data block address): A DBA is the address of an oracle data block for access purposes. RDBA (Tablespace relative database block address): R

Oracle中随机抽取N条记录

一.Oracle取随机数据  1.Oracle访问数据的基本方法:  1).全表扫描(Full table Scan):执行全表扫描,Oracle读表中的所有记录,考查每一行是否满足WHERE条件.Oracle顺序的读分配给该表的每一个数据块,且每个数据块Oracle只读一次.这样全表扫描能够受益于多块读. 2).采样表扫描(sample table scan):扫描返回表中随机采样数据,这种访问方式需要在FROM语句中包含SAMPLE选项或者SAMPLE BLOCK选项.     注:从Ora

oracle随机抽取表中的n条记录

采样表扫描(sample table scan):扫描返回表中随机采样数据,这种访问方式需要在FROM语句中包含SAMPLE选项或者SAMPLE BLOCK选项. 注:从Oracle8i开始Oracle提供采样表扫描特性 2.使用sample获得随机结果集 2.1.语法: SAMPLE [ BLOCK ](sample_percent)[ SEED (seed_value) ] SAMPLE选项:表示按行采样来执行一个全表扫描,Oracle从表中读取特定百分比的记录,并判断是否满足WHERE子句

Oracle的优化器介绍

Oracle优化器介绍 本文讲述了Oracle优化器的概念.工作原理和使用方法,兼顾了Oracle8i.9i以及最新的10g三个版本.理解本文将有助于您更好的更有效的进行SQL优化工作. RBO优化器 RBO是一种基于规则的优化器,随着CBO优化器的逐步发展和完善,在最新的10g版本中Oracle已经彻底废除了RBO.正在使用Oracle8i或9i的人们或多或少的都会碰到RBO,因此在详细介绍CBO之前,我们有必要简单回顾一下古老的RBO优化器. 在RBO中Oracle根据可用的访问路径和访问路

Oracle ->> 随机函数

SQL SERVER下生成随机数据干得多,可是到了Oracle下我就傻了.没用过Oracle,不知道该怎么办?SQL SERVER下依靠TABLESAMPLE或者CHECKSUM(NEWID())来做随机抽样,Oracle则有它自己的随机抽样方法. 这里找到一篇文章讲得挺好的:http://www.cnblogs.com/Athrun/archive/2009/04/25/1443619.html Oracle下随机取样相关的办法有: 1)SAMPLE(percent) 2)SAMPLE BLO