2.1.1.1_15 Oracle 静态数据字典之15 TAB_COLUMNS 表字段【T1】
Oracle 静态数据字典之15 TAB_COLUMNS 表字段【T1】
·
相关链接
1 静态数据字典
原文
这类数据字典主要是由表和视图组成。应该注意的是,数据字典中的表是不能直接来访问的,但是可以访问数据字典中的视图。静态数据字典中的视图分为三类,它们分别为:DBA_、ALL_、USER_。
DBA_TAB_COLUMNS
describes the columns of all tables, views, and clusters in the database. Its columns are the same as those in “ALL_TAB_COLUMNS”. To gather statistics for this view, use the SQL ANALYZE statement.
描述数据库中所有表、视图和集群的列。
表结构与"ALL_TABLE_COLUMNS"一致。
要为这个视图收集统计信息,请使用SQL ANALYZE语句。ALL_TAB_COLUMNS
describes the columns of the tables, views, and clusters accessible to the current user. To gather statistics for this view, use the ANALYZE SQL statement or the DBMS_STATS package.
描述当前用户可访问的表、视图和集群的列。
要为这个视图收集统计信息,可以使用ANALYZE SQL语句或DBMS_STATS包。USER_TAB_COLUMNS
describes the columns of the tables, views, and clusters owned by the current user. Its columns (except for OWNER) are the same as those in “ALL_TAB_COLUMNS”. To gather statistics for this view, use the ANALYZE SQL statement.
当前用户所拥有的表、视图和集群的列。此视图没有OWNER字段。
2 ALL_TAB_COLUMNS 数据字典
DBA_TAB_COLUMNS
,ALL_TAB_COLUMNS
表结构完全一致 ,USER_TAB_COLUMNS
没有OWNER字段。
Ser = Serial :表示字段序号
An= Analyze :表示该字段是否需要通过分析表获取最新信息
Ser | An | Column | DataType | Null | Description |
---|---|---|---|---|---|
1 | OWNER 库 |
VARCHAR2(30) | NOT NULL | Owner of the table, view, or cluster 表、视图或集群的拥有者 |
|
2 | TABLE_NAME 表名 |
VARCHAR2(30) | NOT NULL | Name of the table, view, or cluster 表、视图或集群的名称 |
|
3 | COLUMN_NAME 字段名 |
VARCHAR2(30) | NOT NULL | Column name 列名 |
|
4 | DATA_TYPE 字段类型 |
VARCHAR2(106) | Datatype of the column 列的数据类型 |
||
5 | DATA_TYPE_MOD ??? |
VARCHAR2(3) | Datatype modifier of the column 列的数据类型修饰符? |
||
6 | DATA_TYPE_OWNER ???(库名) |
VARCHAR2(30) | Owner of the datatype of the column 列的数据类型的所有者 |
||
7 | DATA_LENGTH 长度 |
NUMBER | NOT NULL | Length of the column (in bytes) 列长度(以字节为单位) |
|
8 | DATA_PRECISION 精度 |
NUMBER | Decimal precision for NUMBER datatype; binary precision for FLOAT datatype; NULL for all other datatypes 数字数据类型的十进制精度;浮点数据类型的二进制精度;其他数据类型为空 |
||
9 | DATA_SCALE 标度 |
NUMBER | Digits to the right of the decimal point in a number 一个数中小数点右边的数字 |
||
10 | NULLABLE 允许为空 |
VARCHAR2(1) | Indicates whether a column allows NULLs. The value is N if there is a NOT NULL constraint on the column or if the column is part of a PRIMARY KEY. The constraint should be in an ENABLE VALIDATE state. 指示列是否允许空值。如果列上存在NOT NULL约束,或者列是主键的一部分,则值为N。约束应该处于启用验证状态。 |
||
11 | COLUMN_ID 字段序号 |
NUMBER | Sequence number of the column as created 创建的列的序列号 |
||
12 | DEFAULT_LENGTH 默认值字节数 |
NUMBER | Length of the default value for the column 列的默认值的长度(字节数) ![]() |
||
14 | √ | NUM_DISTINCT 列去重后数量 |
NUMBER | Number of distinct values in the columnFoot 1 列中不同值的数目 |
|
15 | √ | LOW_VALUE 列上最小值(低位) |
RAW(32) | Low value in the column Footref 1 列中的最小值 |
|
16 | √ | HIGH_VALUE 列上最大值(高位) |
RAW(32) | High value in the columnFootref 1 列中的最大值 |
|
17 | √ | DENSITY 密度 |
NUMBER | Density of the columnFootref 1 列(柱)密度∈[0,1] 满足公式 【17-DENSITY】*【14-NUM_DISTINCT】= 1 即列(柱)密度越大,列中去重后的值越少 |
|
18 | √ | NUM_NULLS NULL值个数 |
NUMBER | Number of NULLs in the column 列中的NULL值数量 |
|
19 | √ | NUM_BUCKETS 桶数 |
NUMBER | Number of buckets in the histogram for the column Note: The number of buckets in a histogram is specified in the SIZE parameter of the ANALYZE SQL statement. However, Oracle Database does not create a histogram with more buckets than the number of rows in the sample. Also, if the sample contains any values that are very repetitious, Oracle Database creates the specified number of buckets, but the value indicated by this column may be smaller because of an internal compression algorithm.列的(统计)直方图中的桶数 注解:直方图中的桶数是在ANALYZE SQL语句的SIZE参数中指定的。但是,Oracle数据库不会创建一个桶数多于样例中行数的柱状图。另外,如果示例中包含重复非常多的值,Oracle数据库将创建指定数量的桶,但是由于使用了内部压缩算法,此列所指示的值可能会更小。 buckets ∈[1,254] , buckets = 1 时没有直方图 |
|
20 | LAST_ANALYZED 最近ANALYZE日期 |
DATE | Date on which this column was most recently analyzed 列最近被分析的日期 |
||
21 | SAMPLE_SIZE 样本大小 |
NUMBER | Sample size used in analyzing this column 用于分析这一列的样本大小 |
||
22 | CHARACTER_SET_NAME 字符集名称 |
VARCHAR2(44) | Name of the character set: 字符集名称 ● CHAR_CS ● NCHAR_CS |
||
23 | CHAR_COL_DECL_LENGTH 字符类型列的声明长度 |
NUMBER | Declaration length of the character type column 字符类型列的声明长度 |
||
24 | GLOBAL_STATS 全球状态 |
VARCHAR2(3) | For partitioned tables, indicates whether column statistics were collected for the table as a whole (YES ) or were estimated from statistics on underlying partitions and subpartitions (NO )对于分区表,指示是从整体上收集表的列统计信息(YES),还是从基础分区和子分区的统计信息中估计的(NO) |
||
25 | USER_STATS 用户状态 |
VARCHAR2(3) | Indicates whether statistics were entered directly by the user (YES ) or not (NO )指示统计信息是否由用户直接输入(YES)或否(NO) |
||
26 | √ | AVG_COL_LEN 列的平均字节长度 |
NUMBER | Average length of the column (in bytes) 列的平均长度(以字节为单位) |
|
27 | CHAR_LENGTH 字符类型长度 |
NUMBER | Displays the length of the column in characters. This value only applies to the following datatypes: 以字符显示列的长度。此值仅适用于以下数据类型: ● CHAR ● VARCHAR2 ● NCHAR ● NVARCHAR |
||
28 | CHAR_USED 字符类型使用(的定义语言) |
NUMBER | Indicates that the column uses BYTE length semantics (B) or CHAR length semantics ©, or whether the datatype is not any of the following (NULL): 指示列使用字节长度语义(B)或字符长度语义©,或者数据类型是否不属于下列任何一种(NULL): ● CHAR ● VARCHAR2 ● NCHAR ● NVARCHAR2 |
||
29 | V80_FMT_IMAGE V80 图像格式 |
NUMBER | Indicates whether the column data is in release 8.0 image format (YES ) or not (NO )指示列数据是否采用release 8.0图像格式(YES)或not (NO) |
||
30 | DATA_UPGRADED 数据升级 |
NUMBER | Indicates whether the column data has been upgraded to the latest type version format (YES ) or not (NO )指示列数据是否已升级为最新类型版本格式(YES)或未(NO) |
||
31 | HISTOGRAM (统计)直方图类型 |
NUMBER | Indicates existence/type of histogram: 表示直方图的存在/类型: ● NONE ● FREQUENCY 宽度平衡直方图 或 频率直方图 ● HEIGHT BALANCED 高度平衡直方图(平均分布类型) |
3 直方图(histograms)
- 概述
在oracle中直方图是用来描述数据在列中的分布情况。
每一个sql在被执行前都要经过优化这一步骤,那么在优化器给出一个最优执行计划之优化器应该要知道sql语句中所引用的底层对象的详细信息
判断统计信息是否准确,只需要比较一下表记录的count 和 num_rows 值就知道了。 如果是一致的,就说明是最新的,如果不一致,可能就需要分析了。
Ser | An | Column | DataType | Null | Description |
---|---|---|---|---|---|
14 | √ | NUM_DISTINCT 列去重后数量 |
NUMBER | Number of distinct values in the columnFoot 1 列中不同值的数目 |
|
15 | √ | LOW_VALUE 列上最小值(低位) |
RAW(32) | Low value in the column Footref 1 列中的最小值 |
|
16 | √ | HIGH_VALUE 列上最大值(高位) |
RAW(32) | High value in the columnFootref 1 列中的最大值 |
|
17 | √ | DENSITY 密度 |
NUMBER | Density of the columnFootref 1 列(柱)密度∈[0,1] |
|
18 | √ | NUM_NULLS NULL值个数 |
NUMBER | Number of NULLs in the column 列中的NULL值数量 |
|
26 | √ | AVG_COL_LEN 列的平均字节长度 |
NUMBER | Average length of the column (in bytes) 列的平均长度(以字节为单位) |
|
19 | √ | NUM_BUCKETS 桶数 |
NUMBER | Number of buckets in the histogram for the column Note: The number of buckets in a histogram is specified in the SIZE parameter of the ANALYZE SQL statement. However, Oracle Database does not create a histogram with more buckets than the number of rows in the sample. Also, if the sample contains any values that are very repetitious, Oracle Database creates the specified number of buckets, but the value indicated by this column may be smaller because of an internal compression algorithm.列的(统计)直方图中的桶数 注解:直方图中的桶数是在ANALYZE SQL语句的SIZE参数中指定的。但是,Oracle数据库不会创建一个桶数多于样例中行数的柱状图。另外,如果示例中包含重复非常多的值,Oracle数据库将创建指定数量的桶,但是由于使用了内部压缩算法,此列所指示的值可能会更小。 buckets ∈[1,254] , buckets = 1 时没有直方图 |
|
31 | HISTOGRAM (统计)直方图类型 |
NUMBER | Indicates existence/type of histogram: 表示直方图的存在/类型: ● NONE ● FREQUENCY 宽度平衡直方图 或 频率直方图 ● HEIGHT BALANCED 高度平衡直方图(平均分布类型) 在12c后引入了 TOP-Frequency ● Hybrid |
3.1 密度 density (Ser 17)
- 概述: 为连接查询( 如A.CLO1=B.CLO1) 和条件查询(如 WHERE A.CLO1 = 1)提供选择性
列的选择性是用来决定执行计划的一个重要部分。 - 取值范围: [0,1]
- 数值越高,选择性越差(unselective)
- 数值越低,选择性越高(highly selective)
当列的选择性越高,WHERE查询时返回的rows 越少,这样查询的效率就高。
- 作用:
当查询使用这个列作为 WHERE条件时 ,CBO(Cost Based Optimizer)会使用这个列的density统计信息来评估要返回的行数
3.1.1 计算方式
- 1·没有直方图或 7.3版本之前
满足公式 【17-DENSITY】*【14-NUM_DISTINCT】= 1
即列(柱)密度越大,列中 COUNT(DISTINCT) 值越少
列(柱)密度越小,列中 COUNT(DISTINCT) 值越多
例:
20/09/04
M
更多推荐
所有评论(0)