eygle.com   eygle.com
eygle.com eygle
eygle.com  
 
Digest Net: March 2008 Archives

March 2008 Archives

Optimizer Operations

How the Optimizer Performs Operations
    How the CBO Evaluates IN-List Iterators
        当 IN clause 指定了特定的值,并且在该列上有索引,优化器选择 IN-list iterator。如果有多个 OR clauses 使用相同的索引,那么优化器选择更高效的 IN-list iterator,而不使用 CONCATENATION or UNION ALL。
   
    How the CBO Evaluates Concatenation
        当不同的条件使用 OR clause 连接起来,并且不同的条件都可以通过不同的索引生成较好的执行计划,那么 Concatenation 是很有用的。
        HINT:
          USE_CONCAT
          NO_EXPAND 会禁止使用 Concatenation,他其实是阻止 QUERY 扩展为多个 QUERY
        当一下情况时不要使用 Concatenation:
          1.OR conditions 在同一个列上,可以使用 IN-list,后者更高效。
          2.每一个 concatenation 都重复昂贵的步骤。
     
      How the CBO Evaluates Remote Operations
          影响执行计划的因素:
            1.Network round trips 比物理和逻辑 I/Os 昂贵几个数量级
            2.如果远程数据库不是 Oracle 数据库,优化器无法获得远程数据库的任何 statistics
          一般来说,优化器在访问本地表之前先访问远程表
   


      How the CBO Executes Distributed Statements
          1.如果 SQL 语句中的所有表来自同一个远程数据库,Oracle 把语句发送给远程数据库,远程数据库执行完之后把结果发还给本地数据库。
          2.如果表来自不同的数据库,Oracle 把语句拆分,每一个部分访问单个数据库上的表,把他们分别发送给各数据库,各数据库执行自己部分的语句,并把结果发还给本地数据库,本地数据库再执行语句的其余处理部分。
   
          如果是 CBO,优化器会考虑远程数据库上的索引,就像本地数据库一样,还会考虑远程的 statistics,此外,在估计访问的 cost 时,还会考虑数据的位置,比如远程的一个全表扫描比本地相同表的全表扫描估计的 cost 要高。
          对于 RBO,优化器不会考虑远程数据库上的索引。
   
      How the CBO Executes Sort Operations
          SORT UNIQUE
              如果使用了 DISTINCT clause 或者 unique values 在下一步中需要,就会发生 SORT UNIQUE
     
          SORT AGGREGATE
              SORT AGGREGATE 实际上不发生 sort,他使用于对整个 set of rows 进行聚合计算。
     
          SORT GROUP BY
              SORT GROUP BY 用于对不同组上的数据进行聚合计算,这种情况下 sort 是需要的,sort 用于将行拆分成不同的组。
     
          SORT JOIN
              在 SORT MERGE JOIN 中,如果数据需要根据 join key 排序,就会发生 SORT JOIN。
     
          SORT ORDER BY
              当语句中使用 ORDER BY,并且没有任何索引适合这种排序方式,那么 SORT ORDER BY 就需要。
     
      How the CBO Executes Views
          以下情况 CBO 产生 VIEW:
              1.语句中有没有被 decomposed 的 View
              2.语句中有 temporary or inline view 被使用
     
      How the CBO Evaluates Constants
          常量的计算只在语句被优化时执行一次,而不是每次语句被执行的时候。
          比如:salary > 24000/12 会被优化器简化为 salary > 2000
          优化器不会跨过比较符简化表达式,salary*12 > 24000 不能被简化为 salary > 2000,因此写语句时应尽量用常量和列作比较,而不要将列作计算之后再去比较。
   
      How the CBO Evaluates the UNION and UNION ALL Operators
          对于将 OR clauses 组合为一个复合语句,或者将一个复杂语句分解为包含简单 select 语句的复合语句很有用,他们更易于优化和理解。
          就和 concatenation 一样,如果 UNION ALL 重复了昂贵的操作,就不应该使用。
   
      How the CBO Evaluates the LIKE Operator
          对于没有通配符的 like 条件,优化器会将他简化为等于操作
              last_name LIKE 'SMITH' -->> last_name = 'SMITH'
          但这种简化只能用于变长的类型,对于固定长度的,比如 CHAR(10) 就不能简化,因为等于操作遵循 blank-padded semantics,而 like 不是(此规则只适合 9i 以上)。
              CREATE TABLE ducks (f CHAR(6), v VARCHAR2(6));
              INSERT INTO ducks VALUES ('DUCK', 'DUCK');
              commit;
              select * from ducks where f='DUCK';         <<---'DUCK' 自动填充空格至 6 位长度
              F            V
              ------------ ------
              DUCK         DUCK
              select * from ducks where f like 'DUCK';    <<---不填充空格
              no rows selected
              以上结果在 9i 上有效,8i 下两者都返回行
     
      How the CBO Evaluates the IN Operator
          优化器将 IN comparison operator 条件扩展为等价的 equality comparison operators and OR logical operators 条件
   
      How the CBO Evaluates the ANY or SOME Operator
          1.列表
                优化器将其扩展为等价的 comparison operators and OR logical operators 条件
                   salary > ANY (:first_sal, :second_sal) -> salary > :first_sal OR salary > :second_sal
          2.子查询
                优化器将其转化为等价的 EXISTS operator and a correlated subquery 条件
                   x > ANY (SELECT salary
                        FROM employees
                        WHERE job_id = 'IT_PROG')
                变为
                   EXISTS (SELECT salary
                     FROM employees
                     WHERE job_id = 'IT_PROG'
                     AND x > salary)
             
      How the CBO Evaluates the ALL Operator
          1.列表
                优化器将其扩展为等价的 comparison operators and AND logical operators 条件
          2.子查询
                优化器将其转化为等价的 ANY comparison operator and a complementary comparison operator 条件
                  x > ALL (SELECT salary
                      FROM employees
                      WHERE department_id = 50)
                变为
                  NOT (x <= ANY (SELECT salary
                        FROM employees
                        WHERE department_id = 50) )
              然后再进一步根据 ANY Operator 的转换规则再将其转换:
                  NOT EXISTS (SELECT salary
                        FROM employees
                        WHERE department_id = 50
                        AND x <= salary)
               
      How the CBO Evaluates the BETWEEN Operator
          优化器总是将 BETWEEN 条件用 >= and <= 条件来代替
   
      How the CBO Evaluates the NOT Operator
          优化器使用除去 NOT logical operator 并使用相反的 comparison operator 代替原来 comparison operator 的方法来简化条件,使 NOT logical operator 消除。
          优化器会将 NOT 传递到子条件中,以便尽可能的简化条件,即使子条件中会产生更多的 NOTs:
              NOT (salary < 1000 OR commission_pct IS NULL)
          =>
              NOT salary < 1000 AND commission_pct IS NOT NULL
          =>
              salary >= 1000 AND commission_pct IS NOT NULL
     
      How the CBO Evaluates Transitivity
          如果两个条件涉及到同一个 column,且这个 column 的其中一个条件是和 constant expressions 进行比较,那么有时候优化器会推断出一个条件,这个推断的条件可以使用 index access path,而原始的条件却不能使用:
              WHERE column1 comp_oper constant
                AND column1 = column2
          其中:
              comp_oper 为任何比较操作:=, !=, ^=, <, <>, >, <=, or >=
              constant 为任何常量表达式(不能为其他 column):SQL functions, literals, bind variables, and correlation variables
          这时,优化器会推断一个条件:
              column2 comp_oper constant
          如果 column2 上有索引,就能使用该索引
          注:Transitivity 只用于 CBO
   
      How the CBO Optimizes Common Subexpressions
          公共的子表达式优化是一种启发式的优化,可以鉴别、移出、收集在各 disjunctive (OR) branches 中的公共子表达式,绝大数情况下,可以减少 join 的数量。
          在满足一下情况时,可使用公共子表达式优化(从最顶层至最内层的顺序):
              1.顶层条件是一个 disjunction(几个以 or 连接的条件)
              2.每个 or 分支中是 simple predicate 或者 a conjunction(几个以 and 连接的条件)
              3.每个 and 分支中是 simple predicate 或者 a disjunction of simple predicates
              4.表达式在每个 or 分支中都出现,即公共子表达式
                simple predicate 只不含有 AND or OR 连接的条件
           满足以上条件的公共子表达式,优化器会将其移到最顶层,去除重复,再和被移去公共子表达式的原 disjunction 做 conjunction,这样可以减少 join 操作。
   
      How the CBO Evaluates DETERMINISTIC Functions
          某些情况,优化器不需要计算 user-written function 的值,而用以前计算的值来代替他。
          这种 function 必须有一定的限制:
              1.Function 的返回值不能随着 package variables、database、session parameters 的不同而改变
              2.如果 function 被重定义了,那么他的返回值和以前的要保持一致
              3.使用预计算结果代替执行 function 必须没有重大副作用
          使用 DETERMINISTIC 关键字创建的 function 告诉 Oracle 该 function 满足以上限制,Oracle 不会去检查该 function,即使 function 很明显不满足以上限制,因此,程序员应负责检查以上限制,只有满足了才能加 DETERMINISTIC 关键字。
   
   
How the Optimizer Transforms SQL Statements
      How the CBO Transforms ORs into Compound Queries
          如果一个查询包含多个用 OR 连接的条件,优化器会将其转换为用 UNION ALL 连接的混合查询,如果转换后的语句执行更加高效
              1.如果每个条件都可以单独使用 index access path,那么可以转换。优化器将转换后的语句生成执行计划,他们用不同的索引多次访问表,并把结果放到一起
              2.如果任何一个条件使用 full table scan,那么不会转换,因为一个 full table scan 和几个 index scan 结合的效率不如直接使用一个 full table scan 效率高
              3.对于 CBO,优化器会估计并比较转换前后的语句所需的 COST,并决定是否转换
              4.CBO 不会转换 IN-lists 或者条在在同一列上的 OR 操作,而使用 INLIST iterator operator
     
      How the CBO Unnests Subqueries
          优化复杂语句,优化器选择下面两种方法的其中一种:
              1.如果复杂语句可以转换为等同的 join 语句,那么先转换,再优化 join 语句,这样可以利用 join 语句的优势
              2.如果无法转换,那么优化复杂语句本身
                 子查询包含 aggregate functions,比如 AVG 的复杂语句,无法转换为 join 语句
       
      How the CBO Merges Views
          merge view 的方法:
                在语句中将 view 的名字用 view 基表的名字代替,将 view 中的条件加到语句的条件中去
      
          Mergeable and Nonmergeable Views
              merge 只适合 select-project-join views,即 view 中只包含 selections, projections, and joins
              如果 view 中包含以下元素,不能 merge:
                1.Set operators (UNION, UNION ALL, INTERSECT, MINUS) 
                2.A CONNECT BY clause 
                3.A ROWNUM pseudocolumn 
                4.Aggregate functions (AVG, COUNT, MAX, MIN, SUM) in the select list 
              当 view 中包含以下元素时,只有 Complex View Merging is enabled 的时候才能 merge:
                1.A GROUP BY clause 
                2.A DISTINCT operator in the select list 
              如果 view 中包含多个基表,那么当该 view 在 outer join 语句的右边时,无法 merge,如果只有一个基表,那么可以使用 complex view merging,即使 an expression in the view can return a nonnull value for a NULL.
              如果一个查询语句包含 CURSOR expression,那么即使 view 可以被正常 merge 优化器也不会将它 merge
      
      Complex View Merging
          如果 complex view merging is enabled 的,那么包含 GROUP BY clause or DISTINCT 的 view 可以被 merge
          Complex merging 还可以用于 merge an IN subquery,只要 subquery 是不相关的
          Complex merging 不是 cost-based 的,必须用 OPTIMIZER_FEATURES_ENABLE or the MERGE hint 开启才能使用,如果没有 hint or parameter setting,优化器会使用另外一种方法:pushing predicates
      
      How the CBO Pushes Predicates
          优化器可以将访问 nonmergeable view 的 query block 通过 pushing the query block's predicates inside the view's query 来转换
    
      How the CBO Applies an Aggregate Function to the View
          优化器可以转换包含 aggregate function 的 query,通过将 aggregate function 应用到 view's query
      
      How the CBO Executes Views in Outer Joins
          如果 view 在一个 outer join 的右边: 
              1.如果 view 只有一个基表,优化器使用 view merging
              2.如果 view 有多个基表,优化器可以 push the join predicate into the view
        
      How the CBO Accesses the View's Rows with the Original Statement
          如果优化器无法将访问 view 的语句转换为等价的访问基表的语句,比如 view 中包含 ROWNUM pseudocolumn,view 不能被 merge,也不能 push predicate,那么 Oracle 执行 view 中的语句,获得结果集,original statement 将其当作一个表来处理。
      
      How the CBO Executes Compound Queries
          为了为混合查询选择执行计划,优化器首先为混合查询的每个部分选择执行计划,然后用 set operator 联合各 resulting row sources 

转引自: http://www.heysky.net/archives/2006/08/optimizer_operations_notes.html

 

Introduction to the Optimizer


Overview of SQL Processing
  1. parser 进行语意和语法分析
  2. Optimizer 利用RBO,CBO等方法决定产生查询结果的最有效路径
  3. Row Source Generator 从2中接受优化后的方案,并产生SQL的Execution Plan
  4. SQL Execution Engine运行该执行计划,并产生查询结果


Features that Require the CBO
  1. Partitioned tables and indexes
  2. Index-organized tables
  3. Reverse key indexes
  4. Function-based indexes
  5. SAMPLE clauses in a SELECT statement
  6. Parallel query and parallel DML
  7. Star transformations and star joins
  8. Extensible optimizer
  9. Query rewrite with materialized views
  10. Enterprise Manager progress meter
  11. Hash joins
  12. Bitmap indexes and bitmap join indexes
  13. Index skip scans
  即使OPTIMIZER_MODE=rule,这些features仍然会使用CBO


Components of the CBO
  Query Transformer
    数据来自于parse后的SQL,是一系列的query block。其目标是测定SQL的形式是否有利于产生好的query plan。有以下4种:
      1. View Merging
          SQL 中的view 被扩展到单独的query block中。Optimizer会单独分析view query block,这样通常会导致在整体优化上得不到最优的结果。因此query transformer会将大部分view和其他的query block 合并,这样可以在整体上统一优化。
      2. Predicate Pushing
          针对没有被merge的view, push the relevant predicates from the containing query block into the view query block, which can be used either to access indexes or to act as filters
      3. Subquery Unnesting
          子查询是nested在主查询中的,这样很难得到好的优化结果。所以将他们unnested,变成join
      4. Query Rewrite with Materialized Views
          如果查询与某个物化视图符合的化,则会按照物化视图重写这个查询,因为物化视图的结果都是事先计算好的。


  Estimator
  产生 3 种度量标准:
    1. Selectivity
        表示有多少 rows 可以通过谓词被选择出来,大小介于 0.0~1.0,0 表示没有 row 被选择出来。
        如果没有 statistics,estimator 会使用一个默认的 selectivity 值,这个值根据谓词的不同而异。比如 '=' 的 selectivity 小于 '<'。
        如果有 statistics,比如对于 last_name = 'Smith',estimator 使用 last_name 列的 distinct 值的倒数(注:是指表中所有 last_name 的 distinct 值),作为 selectivity。
如果 last_name 列上有 histogram,则使用 histogram 根据 last_name 值的分布情况产生的 selectivity 作为 selectivity。Histogram 在当列有数据倾斜时可以大大帮助 CBO 产生好的 selectivity。


    2. Cardinality
        表示一个 row set 的行数。
        Base cardinality:base table 的行数。如果表分析过了,则直接使用分析的统计信息。如果没有,则使用表 extents 的数量来估计。
        Effective cardinality:有效行集,指从基表中选择出来的行数。是 Base cardinality 和表上所有谓词的组合 Selectivity 的乘积。如果表上没有谓词,那么 Effective cardinality = Base cardinality。
        Join cardinality:两表 join 后产生的行数。是两表 cardinality 的乘积(Cartesian)乘以 Join 谓词的 selectivity。
        Distinct cardinality:列上 distinct 值的行数。
        Group cardinality:GROUP BY 操作之后 row set 的行数。由 grouping columns 的 distinct cardinality 和整个 row set 的行数决定。
          group cardinality lies between max ( dist. card. colx , dist. card. coly )
                                               and min ( (dist. card. colx * dist. card. coly) ,
                                                              num rows in row set )
                              
    3. Cost
        Cost 表现了 Disk I/O, CPU usage, Memory usage 资源单位的使用数量(units of work or resource used)。
        Access path 决定从 base table 获得数据所需的 units of work 的数量。也就是说Access path 决定 Cost 的值。Access path 可以是 table scan, fast full index scan, index scan。


        Clustering Factor:
          Index 的一种属性,表示被索引的行在数据块中的分布情况,表征表中数据的存储顺序和某索引字段顺序的符合程度。直接影响使用 rowid 找到 row 的cost。大小介于 block 数和 rownum 之间。
         (以下来自biti_rainy http://blog.itpub.net/post/330/2970
          Oracle 按照索引块中存储的 rowid 来识别相临的索引中记录在表 block 中是否为相同块,如果索引中存在记录 rowid a,b,c,d......,若b 和 a 是同一个block,则比较 c 和 b,若这时不是同一个block,则 clustering_factor + 1 ,然后比较 d 和 c,若还不是同一个 block,则clustering_factor + 1......
若 clustering_factor 接近表 block 数量,则说明表中数据具有比较好的跟索引字段一样排序顺序的存储,通过索引进行 range scan 的代价比较小(需要读取的表块可能比较少),若 clustering_factor 接近 row 数量,则说明表中数据和索引字段排序顺序差异很大,杂乱无张。则通过索引进行 range scan 的代价比较大(需要读取的表块可能更多)。
当然,在 oracle 920 开始,对于cluster_factor 比较接近表块数量的根据索引的大范围查询做了特别的处理,不再是读一个索引记录去搜索一个表记录了,而是成批处理(通过索引块一批 rowid 一次去表块中获得一批记录),这样就大大节约了读的成本(consistent gets)。


        Join Cost:
        表征了做 join 的两个 row sets 分别 cost 的组合。
          Nested loop join:
            outer row set 的每行遍历 inner row set 的所有行,寻找匹配的行。
            cost = outer access cost + (inner access cost * outer cardinality)
          Sort merge join:
            做 join 的两个 row sets 根据 join keys 进行排序,如果他们不是按照 join keys 的顺序的话。
            cost = outer access cost + inner access cost + sort costs (outer and inner, if sort is used)
          Hash join:
            cost = (outer access cost * # of hash partitions) + inner access cost
            首先理解 hash table 的数据结构:
              可以把 hash table 看做一个 2 维数组 a[200][100],现有 1000 个无序数字用来被查询。我们考虑把这 1000 个数字除以 200,根据其余数放在 a[200][100] 中,余数就是数组的第一维下标。这样平均一个 a[i] 只放5个数字。当查询的时候,对数字除以 200(这就是一个简单的 hash 算法),根据余数 i 去 a[i] 中查找,大约遍历 5 次就能找到。
              Inner row(小表)被 hash 在内存中,并且通过 join key 建立 hash table(作为第一个下标),然后 scan outer table,到 hash table 中查找 joined rows(通过 hash 算法)。
              hash table 会按照 multiblock_IO 决定分成几个 partitions。如果 hash table 太大超出了 hash_area_size,则将超出部分的 partitions 放到 temporary segments 中。
可以通过 10104 events 查看 hash join 的 statistics:
          ALTER SESSION SET EVENTS '10104 trace name context forever, level 10'; 比如:
          Total number of partitions: 
          Number of partitions which could fit in memory: 
          如果后者大于前者,则说明一些 partitions 因为超出了 hash_area_size,要被放置到临时表空间中。


  Plan Generator
    作用是尝试各种可能的执行计划,选择 cost 最低的一种。
    Plan Generator 会先为 nested subqueries and nonmerged views 产生 subplans,并且从 innermost query block 开始往外优化。
    Plan Generator 会使用 internal cutoff 来减少 plan 的尝试数量。internal cutoff 基于现有的最优计划的 cost。如果很大,那么会尝试较多的计划;如果很小,那么会很快结束尝试。
    如果 plan generator 从一个接近最优的 initial join order 开始,那么 internal cutoff 可以很好的工作。Plan Generator 根据 join items 的 effective cardinality 来确定 initial join order,小的在前面,大的在后面。


Understanding Execution Plans
  Execution Plan:
  为了执行 SQL 语句,Oracle 会执行很多步骤,这些步骤的综合叫做 execution plan,包括 access path 和 join order。



Understanding Access Paths for the CBO
  Access paths:
    从数据库获得数据的方式。
 
  Full Table Scans
    表中所有在 HWM 以下的 blocks 都被扫描一遍,确定符合 where 条件的行。
    块的读取范围从 1 到 DB_FILE_MULTIBLOCK_READ_COUNT。Multiblock reads 可以提高执行效率,当访问表中大量块时 full table scans 比 index range scans 效率高。
    优化器选择 Full Table Scans 的情况:
      Lack of Index
      Large Amount of Data
      Small Table               --大小表的区分由 _small_table_threshold 隐含参数决定,默认为 db_cache_size 的 2%。 http://www.eygle.com/archives/2006/05/oracle_long_short_table.html
      High Degree of Parallelism
    Full Table Scan Hints:/*+ FULL(table alias) */
   
  Rowid Scans
    获得一行数据的最快方法。
    一般要先通过 index scan 获得 Rowid,如果需要的列不在 index 中,再进行 Rowid Scans 获得相应的行,如果在 index 中,则不需要 Rowid Scans。
 
  Index Scans
    Index Unique Scans
      最多返回一个 rowid,用于 Unique Index 且 index cols 在条件中使用"等于"。
    Index Range Scans
      返回的数据按照 index columns 升序排列,index column 为同一个值的多行按照行 rowid 的升序排列。如果 order by/group by 的顺序和 Index Range Scans 返回的 row set 的顺序相同就不需要再 sort 了,否则还需要再对 row set 进行 sort。
      Unique index 中的 < > 条件,以及 nonunique indexe 的 < = > 条件,都会引起 Index Range Scans。如果进行 wild-card searches,% 不能放最前面,否则不会进行 Index Range Scans。
      如果某列上有索引,该列有 skewed distribution,且具有 histograms,但当时用 bind variable 时,Oracle 不知道该变量具体是什么值,而无法使用 histograms,导致选择 full table scan,这种情况下可以通过使用 hints 进行调整。
    Index Range Scans Descending
      和 Index Range Scans 相同,只是用于降序返回结果,或者返回小于某特定值的结果。
      HINT:INDEX_DESC(table_alias index_name)
    Index Skip Scans
      用于前导列没有出现在查询中(skiped)时使用索引。它将 composite index 拆分成若干个小的逻辑子索引。子索引的个数由前导列的 distinct 值决定。适用于前导列 distinct 值很少(子索引就少了),非前导列 distinct 值很多的情况。
    Full Scans
      适用于:
        1.A predicate references one of the columns in the index. The predicate does not need to be an index driver.
        2.No predicate,并且:
            A.查询中引用的列都在 index 中
            B.只少有一个索引列不为空。
      它是先定位到索引的 root block,然后到 branch block(如果有的话),再定位到第一个 leaf block,然后根据 leaf block 的双向链表顺序读取。它所读取的块都是有顺序的,也是经过排序的。
    Fast Full Index Scans
      和 Full Scans 适用于:查询的所有列都在索引中出现,且至少有一个索引列具有 NOT NULL 约束。区别在于 它是从段头开始,读取包含位图块,root block,所有的branch block,leaf block,读取的顺序完全有物理存储位置决定,并采取多块读,没次读取db_file_multiblock_read_count个块。(更详细的说明参见汪海的《Index Full Scan vs Index Fast Full Scan 》 http://www.dbanotes.net/Oracle/Index_full_scan_vs_index_fast_full_scan.htm
      Fast Full Index Scans 可以利用多块读和并行读,只能用于 CBO,不能在 bitmap indexes 上使用。
      当需要排序时,Oracle 会使用 Full Index Scans,因为他的结果已经排好序;当不排序时,会使用 Fast Full Index Scans,因为能使用多块读,速度更快。
      在 rebuild index 时使用的就是 Fast Full Index Scans,所以 rebuild index 需要排序。(参见汪海的 《Rebuild Index与 Sort》http://www.dbanotes.net/Oracle/Rebuild_Index_vs_Sort.htm
      HINT:INDEX_FFS(table_alias index_name)
      Fast Full Index Scan 限制:
        索引列中至少有一列有 NOT NULL 约束
        如果要用并行 fast full index scan 必须在创建索引时单独指定 parallel clause,不能从索引所在的表上继承
        必须分析索引,否则优化器可能不会使用它
    Index Joins
      他是一个有若干个 indexes 组成的 hash join,包含查询中需要的所有列。
      他无法 eliminate a sort operation,必须在 CBO 中使用。
      HINT:INDEX_JOIN
    Bitmap Joins
      A bitmap join uses a bitmap for key values and a mapping function that converts each bit position to a rowid. Bitmaps can efficiently merge indexes that correspond to several conditions in a WHERE clause, using Boolean operations to resolve AND and OR conditions.
      只能使用于 CBO,且需要企业版。
     
  Cluster Scans
    用于从存放于 indexed cluster 中的表中获得相同 cluster key 值的数据。具有相同 cluster key 值的所有数据存放于同一个 BLOCK。通过扫描 cluster index 获得相应的 rowid,再通过 rowid 定位到所需的行。


  Hash Scans
    用于从存放于 hash cluster 中的表中获得相同 hash value 值的数据。具有相同 hash value 值的所有数据存放于同一个 BLOCK。通过将 hash function 应用于 cluster key 值上,获得 hash value,再通过 hash value 定位到所需的行上。
   
  Sample Table Scans
    从表中获得 a random sample of data。
    SAMPLE clause:从表中随机获得指定百分比的行数据。
    SAMPLE BLOCK clause:从表中随机获得指定百分比的块数据。
    限制:
      查询不能包含 a join or a remote table
      需要使用 CBO
     
  How the CBO Chooses an Access Path
    1.语句所有可用的 access paths
    2.使用每种 access paths 或者 combination of paths 时,估计的 cost 值
    影响 CBO 的因素:
      1.Optimizer Hints
        hints 会覆盖可用的 access paths,除非包含 SAMPLE or SAMPLE BLOCK
      2.Old Statistics
        影响 cost 的估计
       
       
Understanding Joins
  How the CBO Executes Join Statements
    决定一下几个参数:
      Access Paths
      Join Method(nested loop, sort merge, cartesian, and hash joins)
      Join Order
     
  How the CBO Chooses the Join Method
    估计每个 join method 的 cost,选择 cost 最少的那种 join method。
    如果 join 返回大量行(一般来说,大于 10000 行),考虑以下因素:
      1.nested loop join  是低效的,优化器不会使用它
        nested loop join cost= access cost of A + (access cost of B * number of rows from A)
      2.CBO 中,hash join 是最高效的
        hash join cost= (access cost of A * number of hash partitions of B) + access cost of B
      3.RBO 中,merge join 是最高效的
        merge join cost= access cost of A + access cost of B +(sort cost of A + sort cost of B)
        (如果数据是预先排序好的,sort cost 为 0)
       
  How the CBO Chooses Execution Plans for Join Types
    CBO,RBO 都适用的:
      1.优化器通过 UNIQUE and PRIMARY KEY 约束找到最多返回一行的表,如果这样的表存在,就把它放在连接顺序的第一位,再处理连接中的其他表。
      2.For join statements with outer join conditions, the table with the outer join operator must come after the other table in the condition in the join order. The optimizer does not consider join orders that violate this rule.
    CBO:
      估计各种 join orders, join methods, and available access paths 的 cost,选择 cost 最低的
    其他因素:
      1.较小的 sort area size 会增加 sort merge join 的 cost,因为需要更多的 CPU time and I/O
      2.较大的多块读相对于 nested loop join 来说,会减少 sort merge join 的 cost。
    CBO 中 join orders 的选择会被 ORDERED hint 覆盖,但如果 HINT 和 outer join 的规则冲突,那么 HINT 会被忽略。


  Nested Loop Joins
    当 small subsets of data 被连接,并且 join condition 对于 inner table 来说是一种高效的访问方式时,nested loop joins 是非常有用的。
    必须保证 inner table is driven from (dependent on) the outer table,否则性能很差,这种情况适用 hash joins 更好。
    HINT:USE_NL(table1_alias table2_alias)
   
  Hash Joins
    Hash joins 适用于连接 large data sets。优化器选择较小的 data source 通过 join key 建立一个 hash table 存放在内存中。通过扫描大表,查询 hash table 找到所需的数据。
    当 hash table 太大无法放到内存中,他会被拆分,一部分放到 temporary segments 中,这时 temporary extent sizes 影响 I/O 性能。这种情况下,性能很差。
    当连接使用 equijoin,并且以下任何一种情况下,会使用 hash join:
      1. A large amount of data needs to be joined.
      2. A large fraction of the table needs to be joined.
    Execution Expain 中在上面的是先被扫描的小表,用作建立 hash table,在下的是大表。
    HINT:USE_HASH(table1_alias table2_alias)
    当使用 Hash Joins 时碰到问题时,应该注意 HASH_AREA_SIZE and HASH_JOIN_ENABLED 参数。
   
  Sort Merge Joins
    Sort Merge Join 没有驱动表的概念,他的执行步骤:
      1.Sort join operation: 两个表分别按照 join key 排序 (如果已经按照 join key 排序,这步省略)
      2.Merge join operation: 将排好序的结果 merge together.
    性能比较:
      Sort Merge Join 适用于两个 independent sources。一般来说 Hash join 比 Sort Merge Join 性能好,除非以下两个条件同时满足
        1.row sources 已经被排序
        2.排序操作不需要再进行
      如果 Sort Merge Join 选择了 slower access method,比如全表扫描,他的优势就失去了。
      当两个表通过 <, <=, >, or >= 连接时,Sort merge join 是很有用的,在进行两个大 data sets 连接时,他比 nested loop join 性能好,hash join 适合用 = 连接。
    当两个大数据量的 data sets 连接时,优化器何时选择 sort merge join 而不选择 hash join:
      1.连接条件不是 equi-join,而是 <, <=, >, or >= (but not a nonequality)
      2.OPTIMIZER_MODE is set to RULE,hash join 需要 CBO
      3.HASH_JOIN_ENABLED is false.
      4.连接的表已经排好序
      5.评估 HASH_AREA_SIZE and SORT_AREA_SIZE 大小之后,优化器认为 hash join 的 cost 较高
    HINT:USE_MERGE(table1_alias table2_alias) 可能还需要指定相应的 access path
   
  Cartesian Joins
    当两个表连接时,没有指定连接条件,就会导致 Cartesian Join,一般是由于 poor SQL 造成的。
    HINT:ORDERED,By specifying a table before its join table is specified, the optimizer does a Cartesian join.
   
  Outer Joins
    返回一个表满足连接条件的所有行以及另一个表的全部或者部分行,不管这些行符不符合连接条件。
   
    Nested Loop Outer Joins
      返回 outer (preserved) table 的所有行,即使 inner (optional) table 没有符合条件的行。
      Nested Loop Outer Join 时,外部表永远是驱动表,不根据 cost 来决定哪个是驱动表。
      在以下条件下,优化器选择 Nested Loop Outer Join
        1.外部表驱动内部表是可能的
        2.数据量小到使得 nested loop 效率较高
       
    Hash Join Outer Joins
      当连接的表的数据量大到使用 hash join 效率更高,或者外部表无法驱动内部表时,优化器选择 Hash Join Outer Joins。
      表的连接顺序也不按照 cost 来决定,外部表先进行处理,用它构建 hash table。
     
    Sort Merge Outer Joins
      当外表不能驱动内表,无法使用 hash join or nested loop joins 时,那么使用 Sort Merge Outer Joins。
      由于数据量或者表已经经过排序操作,使得 Sort Merge Outer Joins 效率更高时,优化器选择 Sort Merge Outer Joins。
     
    Full Outer Joins
      Left and right outer joins 的联合。
     
     
Setting Cost-Based Optimizer Parameters
  Enabling CBO Features
    OPTIMIZER_FEATURES_ENABLE
      后面跟版本号,设置 Oracle 允许哪些 CBO 相关的特征被使用,只允许被设置了的版本的 CBO 特征,其他的不允许,在升级版本之后,为了执行计划的稳定性和向后兼容可以使用,否则不需要设置。
    Peeking of User-Defined Bind Variables
      在第一次 invocation of a cursor 的时候,Oracle peeks at 用户定义绑定变量的值,来决定所有 where 条件的 selectivity,即使没有使用绑定变量。在这之后的 invocations of the cursor 就不用再 peek 了,cursor 被共享,即使绑定变量的值不同。
      使用绑定变量假设 cursor sharing 是故意的,并且假设不同的 invocations 使用相同的执行计划,如果没有使用相同的执行计划,那么绑定变量的使用可能不正确。
     
  Controlling the Behavior of the CBO
    CURSOR_SHARING
      将语句中的 literal values 转为绑定变量,提高 cursor sharing 并且影响语句的执行计划,生成的执行计划将基于绑定变量而不是 actual literal values。
    DB_FILE_MULTIBLOCK_READ_COUNT
      Full table scan or index fast full scan 时,一次 I/O 读取的块数。用于估计 full table scans and index fast full scans 的 cost。大的 DB_FILE_MULTIBLOCK_READ_COUNT 值使得 full table scans 的 cost 较低,从而选择 full table scans 而不是 index scan。
    HASH_AREA_SIZE
      用于 hash joins 的内存大小(bytes),越大 hash join 的 cost 越低。
    HASH_JOIN_ENABLED
      是否使用 hash joins
    OPTIMIZER_INDEX_CACHING
      控制 an index probe in conjunction with a nested loop 的 cost。范围 0~100,表明索引块在 buffer cache 中的百分比。他影响优化器对 index caching for nested loops and IN-list iterators 的假设。100 表示 100% 的索引块在 buffer cache 中能找到,这将影响优化器对 an index probe or nested loop cost 的调整。
    OPTIMIZER_INDEX_COST_ADJ
      用于调整 index probe 的 cost。范围 0~10000,默认值 100,表示 indexe 是基于 normal costing model 的 access path;如果设为 10,表示 index 的 cost 是一般 index access path 的 cost 的 1/10。
    OPTIMIZER_MAX_PERMUTATIONS
      用于控制 CBO 对带有连接的 SQL 语句产生的执行计划数。范围 4 to 80000,80000 相当于无限。当将他设置成小于 1000 可以保证 parse times 降到几秒甚者更少。这个参数可以用来减少多表连接语句的 parse times,但是可能会丢失最优的执行计划。
    OPTIMIZER_MODE
      设置优化器的模式:RULE, CHOOSE, ALL_ROWS, FIRST_ROWS_n, and FIRST_ROWS
    PARTITION_VIEW_ENABLED
      是否使用 partition view pruning。如果设置成 true,CBO 只扫描需要的 partitions,根据 view predicates or filters。
    QUERY_REWRITE_ENABLED
      是否使用 query rewrite 的特性。Query rewrite 是和 materialized views 一起工作的。如果设置为 true,Oracle 会考虑使用 query rewrite 来查询 materialized views 而不是原始的大表(参见 D.C.B.A 对 query rewrite 的解释 http://www.anysql.net/2005/12/queryrewrite01.html)。另外该参数还用来控制是否使用 function-based indexes。
    SORT_AREA_SIZE
      执行 sort 所使用的内存大小(bytes)。如果 sort 的数据超过该值,那么超过的部分会放到 temporary tablespace 中。CBO 用该值估量 sort 的 cost,包括 sort merge joins。
    STAR_TRANSFORMATION_ENABLED
      This parameter, if set to true, enables the CBO to cost a star transformation for star queries. The star transformation combines the bitmap indexes on the various fact table columns rather than using a Cartesian approach.(D.C.B.A 对该功能的测试:http://www.anysql.net/2006/03/dw_star_transform.html


     
Overview of the Extensible Optimizer
  The extensible optimizer is part of the CBO. It allows the authors of user-defined functions and domain indexes to control the three main components that the CBO uses to select an execution plan: statistics, selectivity, and cost evaluation.

转引自:http://www.heysky.net/archives/2006/08/9iperformancetuningguide.html

 

Oracle Glossary

| 3 Comments
asynchronous I/O

Independent I/O, in which there is no timing requirement for transmission, and other processes can be started before the transmission has finished.

Autotrace

Generates a report on the execution path used by the SQL optimizer and the statement execution statistics. The report is useful to monitor and tune the performance of DML statements.

bind variable

A variable in a SQL statement that must be replaced with a valid value, or the address of a value, in order for the statement to successfully execute.

block

A unit of data transfer between main memory and disk. Many blocks from one section of memory address space form a segment.

bottleneck

The delay in transmission of data, typically when a system's bandwidth cannot support the amount of information being relayed at the speed it is being processed. There are, however, many factors that can create a bottleneck in a system.

buffer

A main memory address in which the buffer manager caches currently and recently used data read from disk. Over time, a buffer can hold different blocks. When a new block is needed, the buffer manager can discard an old block and replace it with a new one.

buffer pool

A collection of buffers.

cache

Also known as buffer cache. All buffers and buffer pools.

cache recovery

The part of instance recovery where Oracle applies all committed and uncommitted changes in the redo log files to the affected data blocks. Also known as the rolling forward phase of instance recovery.

Cartesian product

A join with no join condition results in a Cartesian product, or a cross product. A Cartesian product is the set of all possible combinations of rows drawn one from each table. In other words, for a join of two tables, each row in one table is matched in turn with every row in the other. A Cartesian product for more than two tables is the result of pairing each row of one table with every row of the Cartesian product of the remaining tables. All other kinds of joins are subsets of Cartesian products effectively created by deriving the Cartesian product and then excluding rows that fail the join condition.

CBO

Cost-based optimizer. Generates a set of potential execution plans for SQL statements, estimates the cost of each plan, calls the plan generator to generate the plan, compares the costs, and chooses the plan with the lowest cost. This approach is used when the data dictionary has statistics for at least one of the tables accessed by the SQL statements. The CBO is made up of the query transformer, the estimator, and the plan generator.

compound query

A query that uses set operators (UNION, UNION ALL, INTERSECT, or MINUS) to combine two or more simple or complex statements. Each simple or complex statement in a compound query is called a component query.

contention

When some process has to wait for a resource that is being used by another process.

dictionary cache

A collection of database tables and views containing reference information about the database, its structures, and its users. Oracle accesses the data dictionary frequently during the parsing of SQL statements. Two special locations in memory are designated to hold dictionary data. One area is called the data dictionary cache, also known as the row cache because it holds data as rows instead of buffers (which hold entire blocks of data). The other area is the library cache. All Oracle user processes share these two caches for access to data dictionary information.

distributed statement

A statement that accesses data on two or more distinct nodes/instances of a distributed database. A remote statement accesses data on one remote node of a distributed database.

dynamic performance views

The views database administrators create on dynamic performance tables (virtual tables that record current database activity). Dynamic performance views are called fixed views because they cannot be altered or removed by the database administrator.

enqueue

This is another term for a lock.

equijoin

A join condition containing an equality operator.

estimator

Uses statistics to estimate the selectivity, cardinality, and cost of execution plans. The main goal of the estimator is to estimate the overall cost of an execution plan.

EXPLAIN PLAN

A SQL statement that enables examination of the execution plan chosen by the optimizer for DML statements. EXPLAIN PLAN causes the optimizer to choose an execution plan and then to put data describing the plan into a database table.

instance recovery

The automatic application of redo log records to Oracle uncommitted data blocks after a crash or system failure.

join

A query that selects data from more than one table. A join is characterized by multiple tables in the FROM clause. Oracle pairs the rows from these tables using the condition specified in the WHERE clause and returns the resulting rows. This condition is called the join condition and usually compares columns of all the joined tables.

latch

A simple, low-level serialization mechanism to protect shared data structures in the System Global Area.

library cache

A memory structure containing shared SQL and PL/SQL areas. The library cache is one of three parts of the shared pool.

LIO

Logical I/O. A block read which may or may not be satisfied from the buffer cache.

literal

A constant value, written at compile-time and read-only at run-time. Literals can be accessed quickly, and are used when modification is not necessary.

MTBF

Mean time between failures. A common database statistic important to tuning I/O.

mirroring

Maintaining identical copies of data on one or more disks. Typically, mirroring is performed on duplicate hard disks at the operating system level, so that if one of the disks becomes unavailable, the other disk can continue to service requests without interruptions.

nonequijoin

A join condition containing something other than an equality operator.

optimizer

Determines the most efficient way to execute SQL statements by evaluating expressions and translating them into equivalent, quicker expressions. The optimizer formulates a set of execution plans and picks the best one for a SQL statement. See CBO.

Oracle Trace

Used by the Oracle Server to collect performance and resource utilization data, such as SQL parse, execute, fetch statistics, and wait statistics. Oracle Trace provides several SQL scripts that can be used to access server event tables, collects server event data and stores it in memory, and allows data to be formatted while a collection is occurring.

outer join

A join condition using the outer join operator (+) with one or more columns of one of the tables. Oracle returns all rows that meet the join condition. Oracle also returns all rows from the table without the outer join operator for which there are no matching rows in the table with the outer join operator.

paging

A technique for increasing the memory space available by moving infrequently-used parts of a program's working memory from main memory to a secondary storage medium, usually a disk. The unit of transfer is called a page.

parse

A hard parse occurs when a SQL statement is executed, and the SQL statement is either not in the shared pool, or it is in the shared pool but it cannot be shared. A SQL statement is not shared if the metadata for the two SQL statements is different. This can happen if a SQL statement is textually identical as a preexisting SQL statement, but the tables referred to in the two statements resolve to physically different tables, or if the optimizer environment is different.

A soft parse occurs when a session attempts to execute a SQL statement, and the statement is already in the shared pool, and it can be used (that is, shared). For a statement to be shared, all data, (including metadata, such as the optimizer execution plan) pertaining to the existing SQL statement must be equally applicable to the current statement being issued.

parse call

A call to Oracle to prepare a SQL statement for execution. This includes syntactically checking the SQL statement, optimizing it, and building (or locating) an executable form of that statement.

parser

Performs syntax analysis and semantic analysis of SQL statements, and expands views (referenced in a query) into separate query blocks.

PGA

Program Global Area. A nonshared memory region that contains data and control information for a server process, created when the server process is started.

PIO

Physical I/O. A block read which could not be satisfied from the buffer cache, either because the block was not present or because the I/O is a direct I/O (and bypasses the buffer cache).

plan generator

Tries out different possible plans for a given query so that the CBO can choose the plan with the lowest cost. It explores different plans for a query block by trying out different access paths, join methods, and join orders.

predicate

A WHERE condition in SQL.

query transformer

Decides whether to rewrite a user query to generate a better query plan, merges views, and performs subquery unnesting.

RAID

Redundant arrays of inexpensive disks. RAID configurations provide improved data reliability with the option of striping (manually distributing data). Different RAID configurations (levels) are chosen based on performance and cost, and are suited to different types of applications, depending on their I/O characteristics.

RBO

Rule-based optimizer. Chooses an execution plan for SQL statements based on the access paths available and the ranks of these access paths (if there is more than one way, then the RBO uses the operation with the lowest rank). The RBO is used if no statistics are available, otherwise the CBO is used.

row source generator

Receives the optimal plan from the optimizer and outputs the execution plan for the SQL statement. A row source is an iterative control structure that processes a set of rows in an iterated manner and produces a row set.

segment

A set of extents allocated for a specific type of database object such as a table, index, or cluster.

simple statement

An INSERT, UPDATE, DELETE, or SELECT statement that involves only a single table.

simple query

A SELECT statement that references only one table and does not make reference to GROUP BY functions.

SGA

System Global Area. A memory region within main memory used to store data for fast access. Oracle uses the shared pool to allocate SGA memory for shared SQL and PL/SQL procedures.

SQL Compiler

Compiles SQL statements into a shared cursor. The SQL Compiler is made up of the parser, the optimizer, and the row source generator.

SQL statements (identical)

Textually identical SQL statements do not differ in any way.

SQL statements (similar)

Similar SQL statements differ only due to changing literal values. If the literal values were replaced with bind variables, then the SQL statements would be textually identical.

SQL Trace

A basic performance diagnostic tool to help monitor and tune applications running against the Oracle server. SQL Trace lets you assess the efficiency of the SQL statements an application runs and generates statistics for each statement. The trace files produced by this tool are used as input for TKPROF.

SQL*Loader

Reads and interprets input files. It is the most efficient way to load large amounts of data.

Statspack

A set of SQL, PL/SQL, and SQL*Plus scripts that allow the collection, automation, storage, and viewing of performance data. Statspack supersedes the traditional UTLBSTAT/UTLESTAT tuning scripts.

striping

The interleaving of a related block of data across disks. Proper striping reduces I/O and improves performance.

  • Stripe depth is the size of the stripe, sometimes called stripe unit.
  • Stripe width is the product of the stripe depth and the number of drives in the striped set.
TKPROF

A diagnostic tool to help monitor and tune applications running against the Oracle Server. TKPROF primarily processes SQL trace output files and translates them into readable output files, providing a summary of user-level statements and recursive SQL calls for the trace files. It can also assess the efficiency of SQL statements, generate execution plans, and create SQL scripts to store statistics in the database.

transaction recovery

The part of instance recovery where Oracle applies the rollback segments to undo the uncommitted changes. Also known as the rolling back phase of instance recovery.

UGA

User Global Area. A memory region in the large pool used for user sessions.

wait events

Statistics that are incremented by a server process/thread to indicate that it had to wait for an event to complete before being able to continue processing. Wait events are one of the first places for investigation when performing reactive performance tuning.

wait events (idle)

These events indicate that the server process is waiting because it has no work. These events should be ignored when tuning, because they do not indicate the nature of the performance bottleneck.

work area

A private allocation of memory used for sorts, hash joins, and other operations that are memory-intensive. A sort operator uses a work area (the sort area) to perform the in-memory sort of a set of rows. Similarly, a hash-join operator uses a work area (the hash area) to build a hash table from its left input.

AIX 常用命令汇总

| 1 Comment

引言

正如您所知道的,AIX® 具有无数的命令,使您能够执行大量的任务。取决于您需要完成的任务,您可能会仅仅使用到这些命令的某个子集。这些子集随不同的用户和不同的需要而异。然而,有一些您通常要使用的核心命令。您需要这些命令来回答您自己的问题,或者为支持人员的询问提供答案。

在本文中,我将讨论这其中的一些核心命令。其目的旨在为您提供一个可用作便捷参考的列表。虽然这些命令的行为在所有 AIX 版本中都应该相同,但是仅在 AIX 5.3 下对它们进行了测试。

注意:
以下段落中讨论的 bootinfo 不是用户级别的命令,并且在 AIX 4.2 或更高版本中不受支持。






命令

内核

如何知道自己在运行 32 位内核还是 64 位内核?

要显示内核启用的是 32 位还是 64 位,可输入以下命令:

bootinfo -K

如何知道自己在运行单处理器还是多处理器内核?

/unix 是指向已启动内核的符号链接。要了解正在运行什么内核模式,可输入 ls -l /unix 并查看 /unix 链接到什么文件。下面是 ls -l /unix 命令的三种可能输出及其对应的内核:

/unix -> /usr/lib/boot/unix_up 		# 32 bit uniprocessor kernel 
/unix -> /usr/lib/boot/unix_mp 		# 32 bit multiprocessor kernel
/unix -> /usr/lib/boot/unix_64 		# 64 bit multiprocessor kernel       

注意:
AIX 5L Version 5.3 不支持单处理器内核。

如何从一种内核模式更改为另一种内核模式?

在安装过程期间,会缺省启用一种适合该 AIX 版本和操作中的硬件的内核。让我们使用前一个问题中的方法并假设启用了 32 位内核。我们还假设您希望在 64 位内核模式下启动。这可以通过按顺序执行以下命令来实现:

ln -sf /usr/lib/boot/unix_64    /unix
ln -sf /usr/lib/boot/unix_64    /usr/lib/boot/unix

bosboot -ad  /dev/hdiskxx
shutdown -r

/dev/hdiskxx 目录是启动逻辑卷 /dev/hd5 所在的位置。要弄清 hdiskxx 中有哪些 xx,可运行以下命令:

 lslv -m hd5
 

注意:
在 AIX 5.2 中,缺省安装的是 32 位内核。在 AIX 5.3 中,缺省情况下会在 64 位硬件上安装 64 位内核,在 32 位硬件上安装 32 位内核。

用法说明:这个 nmon 工具并未受到正式支持。没有提供或隐含任何保证,并且您无法从 IBM 获取相关的帮助。

nmon 工具运行于:

  • AIX® 4.1.5、4.2.0、4.3.2 和 4.3.3(nmon Version 9a:该版本的功能已经确定,并且不会对其进行进一步的开发。)
  • AIX 5.1、5.2 和 5.3(nmon Version 10:该版本现在支持 AIX 5.3 和基于 POWER5™ 处理器的计算机,并且提供了 SMT 和共享 CPU 微分区的支持。)
  • pSeries® p5 和 OpenPower™ 上的 Linux™ SUSE SLES 9、Red Hat EL 3 和 4、Debian
  • Linux SUSE、Red Hat 和许多最新的 x86(32 位模式的 Intel 和 AMD)上的发布版
  • zSeries® 或 mainframe 上的 Linux SUSE 和 Red Hat

nmon 工具大约每六个月更新一次,或者在可用的新的操作系统发布版中对其进行更新。要将您的名字放入到请求更新的电子邮件列表中,请与 Nigel Griffiths 联系。

这个工具可以与 nmon 分析程序一同使用,后者将加载 nmon 的输出文件并自动地创建大量的图形。

引言

nmon 工具可以为 AIX 和 Linux 性能专家提供监视和分析性能数据的功能,其中包括:

  • CPU 使用率
  • 内存使用情况
  • 内核统计信息和运行队列信息
  • 磁盘 I/O 速度、传输和读/写比率
  • 文件系统中的可用空间
  • 磁盘适配器
  • 网络 I/O 速度、传输和读/写比率
  • 页面空间和页面速度
  • CPU 和 AIX 规范
  • 消耗资源最多的进程
  • IBM HTTP Web 缓存
  • 用户自定义的磁盘组
  • 计算机详细信息和资源
  • 异步 I/O,仅适用于 AIX
  • 工作负载管理器 (WLM),仅适用于 AIX
  • IBM TotalStorage® Enterprise Storage Server® (ESS) 磁盘,仅适用于 AIX
  • 网络文件系统 (NFS)
  • 动态 LPAR (DLPAR) 更改,仅适用于面向 AIX 或 Linux 的 pSeries p5 和 OpenPower

还包括一个用来从 nmon 的输出生成图形并创建可以在 Web 站点显示的 .gif 文件的新工具。

有关详细信息,请参阅自述文件。





回页首


伯克希尔哈撒韦公司总裁、刚刚跃升为福布斯世界首富的巴菲特,每年都要在公司的年报中给股东写一封信,总结在过去一年中的成败得失。从挑选经理、选择投资目标、评估公司,到有效地使用金融信息,这些信涵盖面甚广。

最重要的是,他会阐述自己的投资艺术,告诉你如何投资。因此,每年的"致股东信"都会成为世界杰出投资经理和优秀CEO的必读经典。

  在今年的"致股东信"中,股神提醒大家别对股市期望太高,还谈到了他在外汇市场上的操作、他的继承人问题、衍生金融工具、他犯下的错误以及公司的保险业务等。本报特摘译致股东信的一些亮点,以供投资爱好者和企业家参考。

恒源祥之后国内广告

| 14 Comments

1,脑白金

鼠年过年不收礼 收礼还收脑白金
牛年过年不收礼 收礼还收脑白金
虎年过年不收礼 收礼还收脑白金
兔年过年不收礼 收礼还收脑白金
龙年过年不收礼 收礼还收脑白金
蛇年过年不收礼 收礼还收脑白金
马年过年不收礼 收礼还收脑白金
羊年过年不收礼 收礼还收脑白金
猴年过年不收礼 收礼还收脑白金
鸡年过年不收礼 收礼还收脑白金
狗年过年不收礼 收礼还收脑白金
猪年过年不收礼 收礼还收脑白金

4,汇仁肾宝

汇仁肾宝 你好我也好
汇仁肾宝 你爸好我爸也好
汇仁肾宝 你妈好我妈也好
汇仁肾宝 你爷爷好我爷爷也好
汇仁肾宝 你奶奶好我奶奶也好
汇仁肾宝 你弟弟好我弟弟也好
汇仁肾宝 你妹妹好我妹妹也好
汇仁肾宝 你姐姐好我姐姐也好
汇仁肾宝 你姨父好我姨父也好
汇仁肾宝 你舅舅好我舅舅也好

.....................


5, 西门子冰箱:0℃不结冰,长久保持第一天的新鲜

西门子冰箱:0℃不结冰,长久保持第2天的新鲜

西门子冰箱:0℃不结冰,长久保持第3天的新鲜

西门子冰箱:0℃不结冰,长久保持第4天的新鲜

西门子冰箱:0℃不结冰,长久保持第5天的新鲜

西门子冰箱:0℃不结冰,长久保持第6天的新鲜

西门子冰箱:0℃不结冰,长久保持第7天的新鲜

西门子冰箱:0℃不结冰,长久保持第8天的新鲜

..................

6, 喝了新盖中盖口服液,嘿,一口气上五楼,还不费劲儿...

喝了新盖中盖口服液,嘿,一口气上六楼,还不费劲儿...

喝了新盖中盖口服液,嘿,一口气上七楼,还不费劲儿...

喝了新盖中盖口服液,嘿,一口气上八楼,还不费劲儿...

喝了新盖中盖口服液,嘿,一口气上九楼,还不费劲儿...

.....................

.....................

喝了新盖中盖口服液,嘿,一口气上九十七楼,还不费劲儿...

喝了新盖中盖口服液,嘿,一口气上九十八楼,还不费劲儿...

喝了新盖中盖口服液,嘿,一口气上九十九楼,还不费劲儿...

喝了新盖中盖口服液,嘿,一口气上一百楼楼,还不费劲儿...


7,我们的目标是:没有猪牙!

我们的目标是:没有鼠牙!

我们的目标是:没有牛牙!

我们的目标是:没有虎牙!

我们的目标是:没有兔牙!

我们的目标是:没有龙牙!

我们的目标是:没有蛇牙!

我们的目标是:没有马牙!

我们的目标是:没有羊牙!

我们的目标是:没有猴牙!

我们的目标是:没有鸡牙!

我们的目标是:没有狗牙!


8, 波导手机...手机中的战斗鸡!

波导手机...手机中的战斗猪!

波导手机...手机中的战斗猴!

波导手机...手机中的战斗牛!

....

....
9, 农夫果园 喝前摇一摇

农夫果园 喝前晃一晃

农夫果园 喝前摔一摔

农夫果园 喝前抖一抖

农夫果园 喝前搅一搅

农夫果园 喝前踩一踩

农夫果园 喝前顶一顶

10,用了大宝,唉!真对的起咱这张脸
  用了大宝,唉!真对的起咱这条腿
  用了大宝,唉!真对的起咱这双手
  用了大宝,唉!真对的起咱这只脚
  用了大宝,唉!真对的起咱这头发
  用了大宝,唉!真对的起咱这个胸
  用了大宝,唉!真对的起咱的这腹
  用了大宝,唉!真对的起咱的这腚
11,大宝明天见!大宝啊天天见!
  大宝后天见!大宝啊天天见!
  大宝大后天见!大宝啊天天见!
  大宝大大后天见!大宝啊天天见!
  大宝下月见!大宝啊月月见!
  大宝下下月见!大宝啊月月见!
  大宝下下下月见!大宝啊月月见!
  ...................
  大宝明年见!大宝啊年年见!
  大宝后年见!大宝啊年年见!
  大宝后后年见!大宝啊年年见!


12,森马


  谢霆峰----我的球技很逊,但起码我好看
  张柏芝----我的制服很逊,但起码我好看
  阿 娇----我的普通话很逊,但起码我好看
陈冠希----我的相机很逊,但起码照片好看


15, 爱因斯坦大脑活跃 飞鹤奶粉......
  阿基米德大脑活跃 飞鹤奶粉......
  亚里士多德大脑活跃 飞鹤奶粉......
  成吉思汗大脑活跃 飞鹤奶粉......
  东方不败大脑活跃 飞鹤奶粉......
  芙蓉姐姐大脑活跃 飞鹤奶粉......
  杨二车娜姆大脑活跃 飞鹤奶粉......


总结陈词:

唉,恒源祥真是害群之马啊!
  害群之牛啊!
  害群之鸡啊!
  害群之虎啊!
  害群之蛇啊!

Diagnostic event 10262

| 6 Comments

Tonight,Friend ask me about Oracle Event 10262,The first time I notice this Event.
Get the detail From Internet:

If this diagnostic event is set, Oracle will not check for memory leaks.
The amount of leaked bytes to be ignored is specified with the level. In the following example, a memory leak of less than 2000 bytes is not reported.

event = "10262 trace name context forever, level 2000"

if the level is 1, the memory leak check is totally ignored:

event = "10262 trace name context forever, level 1"

Oracle IS The Information Company

| 4 Comments

  "信息化公司",是Oracle对软件和信息服务传统角色的一次重要的反思考。因为在Oracle的信息架构基础上,企业能够实现随需应变的目标,从而让管理者可以花费更多的时间思考如何管理企业。

  12月的旧金山进入了一个较为寒冷的雨季,但是从世界各地涌来的25000名观众让旧金山的Moscone中心热闹非常,原来12月5日~9日Oracle OpenWorld(Oracle技术与应用大会)在这里举行。

   此次大会是Oracle首次将原来在北美举办的Oracle技术大会(OracleWorld)与Oracle应用大会(Oracle AppsWorld)结合起来,向世界全面展示全新应用和技术产品,以及合作伙伴解决方案。


  Oracle全球总裁菲利普斯说:Oracle的业务就是信息化----即如何管理信息、使用信息、共享信息和保护信息

  

  "我们是信息化公司"

  Information(信息)可能是本次大会中演讲者说得最多的词,甚至Oracle在本次大会举行之际连公司的Logo都换了----在原来的图标下面加上了"The Information Company(信息化公司)",Oracle希望通过本次大会向合作伙伴、用户、媒体透露一个重要的信息----Oracle要做信息化公司。

  从一个专业的企业级软件厂商向信息厂商转变,Oracle有着充分的准备。"我们正在进入一个信息时代(Information Age),信息正在成为驱动企业发展的核心动力。信息化的核心将是如何向用户提供正确和高质量的数据。"Oracle全球总裁查尔斯·菲利普斯(Charles Phillips)在本次大会的首场演讲中说,"Oracle的业务就是信息化----即如何管理信息、使用信息、共享信息和保护信息。"在整个演讲过程中,他一直都在强调"Information matters(信息是至关重要的)"。第三天Oracle CEO 埃里森在演讲中提出:"Oracle作为信息公司,不仅能改变人们管理企业的方式,而且能改变人们对企业本身的思考方式。而Oracle的最新技术就是对软件和信息服务传统角色的一次重要的反思考。"因为在Oracle的信息架构基础上,企业能够实现随需应变的目标,从而让管理者可以花费更多的时间思考如何管理企业

  从一年前在公司内部提出Oracle信息架构(Oracle Information Architecture),到7月上海的Oracle OpenWorld上提出Oracle信息架构,再到本次大会上Oracle明确展示Oracle信息架构的组成,我们可以看出Oracle向信息公司的转变是有备而来。在本次大会上,菲利普斯展示了Oracle信息架构的组成,涵盖了Oracle可以提供的数据库、应用服务器和协作基础架构软件,以及企业范围的应用产品和行业解决方案。

  

  热点集中轰炸

  整个大会持续4天,主题演讲及小型讲座超过600场。而在整个大会中,真正的热点还是集中在Oracle信息架构中的几个重要组成部分:商业智能、网格计算、集成和数据管理、应用产品

  要解决企业信息分散在不同系统中的问题,就必须考虑集成和数据管理的解决办法。而在此次大会期间,Oralce一个重点推广的内容就是Data Hub(数据中心),埃里森的演讲有一半的内容都是在围绕Data Hub进行。Data Hub的目标是将客户所有数据库中的数据收集在一起,并进行相应的客户化,从而让客户看到的所有信息都集中在同一个数据库中。"Oracle花了5年的时间完成公司全球统一数据库的建设,我一直在考虑如何让其他的公司也能够和我们一样建立全球统一数据库并获得成功。"埃里森表示,"Data Hub的概念就是这个时候出现的。Data Hub能够实现各种应用系统的数据集成,并且最重要的是它是实时的。"去年,Oracle推出了Customer Data Hub,经过用户的验证效果不错。于是,Oracle计划推广Data Hub,并计划相继推出Citizen Data Hub、Finacial Service Accounting Hub。

  在本次大会中,Oracle服务器技术执行副总裁Charles Rozwat在他"依靠网格运行"的演讲中介绍了企业计算网格的进展,"从去年Oracle宣布第一个企业网格计算软件Oracle 10g,到一年后的今天,网格计算正在成为一种主流。"而DELL公司董事长迈克尔·戴尔则在他的演讲中强调,"戴尔的可伸缩企业的实质与Oracle的企业网格的实质一样。"从去年Oracle推出第一个网格产品Oracle企业服务器10g,到今年大会期间Oracle推出Oracle企业服务器10g的第二版;戴尔、EMC、英特尔和Oracle联合推出MetaGrid项目以建立企业网格计算最佳模式;Oracle从推广网格计算以来,数据库新许可证销售额一直以15%的幅度增长......Oracle将继续加大网格计算的推广。

  此次商业智能和应用产品的讨论都集中在Oralce的新产品上,重点突出Oracle信息架构的完整性。

  

  力争中国应用市场主导

  本次Oracle邀请的中国内地媒体有17家,加上台湾、香港共有25家中国媒体出现在本次大会上。这从一个侧面看出Oracle对中国市场的看重。Oracle亚太区执行副总裁Derek Williams接受采访时表示,Oracle亚太区将力争在企业应用软件市场中的主导地位,主要集中在三个方面的发展:第一、协助各种规模的公司降低与信息技术和企业系统管理相关的成本和复杂性;第二、满足关键行业的需求;第三、抓住中国、印度等新兴市场上涌现的机会以加速业务增长。中国应用市场在Oracle眼中的重要性可见一斑。

  按照计划,明年Oracle的最大目标是中国应用市场。"未来18个月,我们将力争大幅度改变亚太地区企业应用产品市场的竞争格局。"Oracle亚太区应用产品部高级副总裁Mark Gibbs说,"电子商务套件11i.10除了在技术上的优势外,我们还将加大渠道方面的力度,建设一个良好的合作伙伴生态环境。"

   Oracle的应用产品在国内有近60%的业务是通过合作伙伴完成的,而为了加大推广力度,Oracle成立了专门的应用产品组,由专门的渠道合作组来负责整个应用产品的渠道开拓。而最近的活动就是电子商务套件11i.10的全国推广。

  菲利普斯在演讲中强调了中小企业市场的重要性,而按照Gartner的划分,中国的中小企业占了整个市场的99%(员工人数少于2000,年收入低于3亿美元,全部资产小于4亿美元),Mark Gibbs更明确表示Oracle将加大中国中小企业市场的推广力度。"我们将从世界各地选派相应的技术支持人员和咨询专家前来中国,协助开拓中国的应用产品市场。"Mark Gibbs自信地说:"我们推出的电子商务套件特别版(定价3万元)也就是瞄准了中小企业市场。"

  

  记者手记Information Company的发展方向

  此次Oracle Open World的参加者住满了旧金山大大小小47个酒店,各界的参会者云集于此。此次大会的演讲嘉宾包括惠普董事长兼CEO卡莉、戴尔董事长迈克尔·戴尔、英特尔副总裁William Swope、Sun董事长兼CEO麦克尼里、EMC总裁兼CEO Joe Tucci......在整个展会中,Oracle的主基调Information随处可见。Oracle此次展会目的是让业界接受它的转型。

   从紧跟电子商务推出电子商务套件,到On-Demand流行时提出Oracle On Demand,Oracle让人记住更多的是收购和数据库,此次重点突出Information Company是Oracle第一次站出来指出自己的发展方向。为了符合Information Company的发展方向,在此次大会上Oracle提出了很多的概念和一些支持这些概念的产品。这次参会者可能都记住了Oracle要做一个Information Company,但是更多的还是在观望这个Information Company能够为自己提供怎么样的Information Service。

原文发表时间:2004-12-13
链接:http://media.ccidnet.com/media/ciw/1372/a3301.htm

Graduates of Yale University, I apologize if you have endured this type of prologue before, but I want you to do something for me. Please, take a good look around you.
Look at the classmate on your left. Look at the classmate on your right. Now, consider this:five years from now, 10 years from now, even 30 years from now, odds are the person on your left is going to be a loser. The person on your right, meanwhile, will also be a loser. And you, in the middle? What can you expect? Loser. Loserhood. Loser Cum Laude.

"In fact, as I look out before me today, I don't see a thousand hopes for a bright tomorrow. I don't see a thousand future leaders in a thousand industries. I see a thousand losers.
"You're upset. That's understandable. After all, how can I, Lawrence 'Larry' Ellison,college dropout, have the audacity to spout such heresy to the graduating class of one of the nation's most prestigious institutions? I'll tell you why. Because I, Lawrence "Larry" Ellison, second richest man on the planet, am a college dropout, and you are not.

"Because Bill Gates, richest man on the planet ---- for now, anyway ---- is a college dropout, and you are not.
"Because Paul Allen, the third richest man on the planet, dropped out of college, and you did not.
"And for good measure, because Michael Dell, No. 9 on the list and moving up fast, is a college dropout, and you, yet again, are not.
"Hmm . . . you're very upset. That's understandable. So let me stroke your egos for a moment by pointing out, quite sincerely, that your diplomas were not attained in vain. Most of you, I imagine, have spent four to five years here, and in many ways what you've learned and endured will serve you well in the years ahead. You've established good work habits. You've established a network of people that will help you down the road. And you've established what will be lifelong relationships with the word 'therapy.' All that of is good. For in truth, you will need that network. You will need those strong work habits. You will need that therapy.

"You will need them because you didn't drop out, and so you will never be among the richest people in the world. Oh sure, you may, perhaps, work your way up to No. 10 or No. 11, like Steve Ballmer. But then, I don't have to tell you who he really works for, do I?
And for the record, he dropped out of grad school. Bit of a late bloomer.
"Finally, I realize that many of you, and hopefully by now most of you, are wondering, 'Is there anything I can do? Is there any hope for me at all?' Actually, no. It's too late. You've absorbed too much, think you know too much. You're not 19 anymore. You have a built-in cap, and I'm not referring to the mortar boards on your heads.

"Hmm...... you're really very upset. That's understandable. So perhaps this would be a good time to bring up the silver lining. Not for you, Class of '00. You are a write-off,so I'll let you slink off to your pathetic $200,000-a-year jobs, where your checks will be signed by former classmates who dropped out two years ago.

"Instead, I want to give hope to any underclassmen here today. I say to you, and I can't stress this enough: leave. Pack your things and your ideas and don't come back. Drop out. Start up.
"For I can tell you that a cap and gown will keep you down just as surely as these security guards dragging me off this stage are keeping me down . . ."
(At this point The Oracle CEO was ushered off stage.)


口令老化(Password aging)是一种增强的系统口令生命期认证机制,虽然它会一定程序的削弱用户使用的便利性,但是它能够确保用户的口令定期更换,这是一种非常好的安全措施。大部分的Linux发行版默认都不会打开口令老化功能,但是我们可以很容易地启用它。

1、编辑/etc/login.defs文件
我们可以通过以下参数来修改口令老化的默认配置:

# Password aging controls: #PASS_MAX_DAYS 密码有效期天数设置为9999,实际上就是关闭了口令老化功能 #PASS_MIN_DAYS 表示自从上次密码修改以来多少天后用户才被允许修改口令 #PASS_MIN_LEN #PASS_WARN_AGE 表示在口令到期前多少天开始通知用户口令即将到期

PASS_MAX_DAYS 9999
PASS_MIN_DAYS 0
PASS_WARN_AGE 7

2、编辑/etc/default/useradd文件
在其中查找INACTIVE和EXPIRE关键字:

# useradd defaults file GROUP=100 HOME=/home INACTIVE=14

//设置在口令已过期而用户一直没有修改口令多少天后用户帐户将置为不可用而锁定,以上设置是14天,

EXPIRE=

//直接指明新用户的口令的失效日期,格式为YYYY-MM-DD。
SHELL=/bin/bash



以上的设置都只对配置修改后创建的新用户有效,如果要更改已经创建的用户配置,可以使用chage工具:

[root@rhel4 ~]#chage -M 60 shangwen

以上将设置用户shangwen的PASS_MAX_DAYS为60天,并且相应的更新shadow文件。我们可以使用-l选项查看用户密码老化相关信息,-m设置PASS_MIN_DAYS,-W设置PASS_WARN_AGE等等。chage工具可以让我们设置口令老化的方方面面参数。以下是chage的详细参数信息:


用法:chage [选项] 用户名

选项:

-d, --lastday 最近日期 将最近一次密码设置时间设为"最近日期"
-E, --expiredate 过期日期 将帐户过期时间设为"过期日期"
-h, --help 显示此帮助信息并退出
-I, --inactive 失效密码 将因过期而失效的密码设为"失效密码"
-l, --list 显示帐户年龄信息
-m, --mindays 最小天数 将两次改变密码之间相距的最小天数设为"最小天数"
-M, --maxdays 最大天数 将两次改变密码之间相距的最大天数设为"最大天数"
-W, --warndays 警告天数 将过期警告天数设为"警告天数"

分区表维护的常用命令:

ALTER TABLE
-- DROP -- PARTITION
-- ADD |
-- RENAME |
-- MODIFITY |
-- TRUNCATE |
-- SPILT |
-- MOVE |
-- EXCHANGE |

分区索引的常用维护命令:

ALTER INDEX
-- DROP -- PARTITION
-- REBUILD |
-- RENAME |
-- MODIFITY |
-- SPILT |
-- PARALLEL
-- UNUSABLE

1、ALTER TABLE DROP PARTITION
用于删除table中某个PARTITION和其中的数据,主要是用于历史数据的删除。如果还想保留数据,就需要合并到另一个partition中。
删除该partition之后,如果再insert该partition范围内的值,要存放在更高的partition中。如果你删除了最大的partition,就会出错。
删除table partition的同时,删除相应的local index。即使该index是IU状态。
如果table上有global index,且该partition不空,drop partition会使所有的global index 为IU状态。如果不想REBUIL INDEX,可以用SQL语句手工删除数据,然后再DROP PARTITION.
例子:

ALTR ATBEL sales DROP PARTITION dec96;

到底是DROP PARTITION或者是DELETE?
如果GLOBAL INDEX是最重要的,就应该先DELETE 数据再DROP PARTITION。
在下面情况下,手工删除数据的代价比DROP PARTITION要小
- 如果要删除的数据只占整个TABLE的小部分
- 在TABLE中有很多的GLOBAL INDEX。

在下面情况下,手工删除数据的代价比DROP PARTITION要大
- 如果要删除的数据占整个TABLE的绝大部分
- 在TABLE中没有很多的GLOBAL INDEX。

如果在TABLE是父TABLE,有被引用的约束,且PARTITION不空,DROP PARTITION时出错。
如果要删除有数据的PARTITION,应该先删除引用约束。或者先DELETE,然后再DROP PARTITION。
如果TABLE只有一个PARTITON,不能DROP PARTITION,只能DROP TABLE。


2、ALTER INDEX .. DROP PARTITION
删除PARTIOTN GLOBAL INDEX上删除INDEX和INDEX ENTRY,一般用于平衡I/O。
INDEX必须是GLOBAL INDEX。不能显式的drop local index partition,不能删除最大的index。
删除之后,insert属于该partition的值时候,index建立在更高的partition。
如果包含数据的partition删除之后,下一个partition是IU状态,必须rebuild。可以删除IU状态的partition,即使它包含数据。

3、ALTER TABLE / INDEX RENAME PARTITION
主要用于改变隐式建立的INDEX NAME。
INDEX 可以是IU状态。
一般的INDEX可以用ALTER INDEX RENAME ....

4、ALTER TABLE .. ADD PARTITION...
只能加到最后一个PARTITION之后。一般用于数据会单调增长的地方,比如每周/月/年会增加新的历史数据等。
SPLIT可以在中间插入PARTITION。
如果VALUES LESS THAN的第一个值是MAXVALUE,就不能增加PARTITION.必须SPLIT。
该命令也可以给自动增加PARTITION LOCAL INDEX。新的LOCAL INDEX PARTITION名字和TABLE PARTITION一致。新的LOCAL INDEX PARTITION使用前一个INDEX PARTITION的缺省值,存放在TABLE PARTITION同样的TABLESPACE。
不影响GLOBAL INDEX。
即使TABLE有INDEX或者INDEX PARTITION是IU状态也可以增加PARTITION.

5、ALTER TABLE/INDEX MODIFY PARTITION
1)ALTER TABLE MODIFY PARTITION
修改PARTITION的物理属性,比如分配更多的EXTEND。
如果要移动到新的TABLESPACE,或者改变CREATE建立的属性,就需要ALTER TABLE MOVE PARTITION。

2)ALTER INDEX MODIFY PARTITION
修改INDEX的物理属性。
可以增减更多的EXTENT
必须是GLOBAL/LOCAL PARTITION INDEX。
ALTER TABLE/INDEX ... MODIFY PARTITION ... UNUSABLE。
如果要把UNUSABLE变成USABLE,
- REBUILD INDEX PARTITION
- DROP + RECREATE 包含这个PARTITION的INDEX。

如果修改TABLE TABLE ... 的物理属性,值放在数据字典,只有ADD PARTITION的时候才使用。不会改变现有的PARTITION的属性。
比如:ALTER TABLE sales PCTFREE 0 PCTUSED 20.

ALTER INDEX直接修改PARTITION和NONPARTITION的物理属性。
如果修改PARTITION INDEX的物理属性,也是值放在数据字典,只有建立新的INDEXPARTITION的时候才使用。不会改变现有的PARTITION的属性。
如果INDEX是GLOBAL的,在ALTER INDEX SPLIT PARTITION的时候用到。如果是LOCAL INDEX,在隐式的增加INDEX PARTITION的时候用到,比如ALTER TABLE ADD PARTITION或者SPLIT PARTITION。这样就可以控制ALTER TABLE建立LOCAL INDEX的属性了。
如果INDEX是NONPARTITION的,标记为INDEX UNUSABLE ,不允许ALTER 命令。只能在RECREATE的时候设置其属性。


6、ALTER TABLE MODIFY PARTITION UNUSABLE LOCAL INDEXES
把TABLE所有相关的LOCAL INDEX设置为UNUSABLE。用于要进行大规模的DML操作的时候。
UNUSABLE-->USABLE的方法:
- ALTER INDEX REBUILD PARTITION
- ALTER TABLE MODIFY PARTITION REBUILD UNUSABLE LOCAL INDEXES
可以查询DBA/ALL/USER_PARTITIONS看INDEX的状态。

7、ALTER TABLE MODIFY PARTITION REBUILD LOCAL INDEXES
REBUILD该TABLE上所有不可用的LOCAL INDEX。

8、ALTER INDEX ... UNUSABLE
- 可以对PARTITION/NONPARTITION INDEX。
- 可以使NONPARTITION INDEX 为不可用状态。
- 可以使所有的INDEX PARTITION为不可用状态。
- 处于IU状态的NOPARTITION INDEX必须REBUILD,或者DROP+RECREATE。
- 一次只能REBUILD一个PARTITION INDEX。
- 对处于不可用状态的GLOBAL INDEX ,DROP+RECREATE的效率要高于REBUILD。

9、ALTER INDEX ... REBUILD PARTITION...
用于REBUILD INDEX的一个PARTITION,如果不需要RECREATE一个大的INDEX,用这个命令修复之。
也可以用于把一个INDEX PARTITION移动到另外的TABLESPACE,或者改变CREATE时候的物理参数,或者作为SPLIT操作的最后一步。
并行rebuild:
- 如果rebuild的时候指定parallel,则使用之;
- 否则使用index缺省的parallel属性;
- 否则使用table缺省的parallel属性;
- 否则不使用并行。

10、alter session set skip_unusable_indexes
允许用户在有unusable index或者index partition的table上进行DML操作。否则就会产生错误。用在进行大规模的修改和加载数据的时候,推迟index的维护。
但是如果query指定不可用的index或者index partition,依然会报错。
不能跳过对不可用的唯一索引的维护。

11、alter table split partition
建立两个新的partition,有自己新的segment,新的物理属性,和initial extent。原来partition的segment都丢弃。
用在如果partition太大,导致备份、恢复和维护操作时间很长,可以考虑使用split tablespace。
也可以用在重新分布I/O负载。
在split partition的时候,同样建立相应的local index。
如果在split的时候出现问题,新的segment就删除,语句rollback。
index即使是不可用的,index partition也可以split。
例子:
ALTER TABLE parts SPLIT PARTITION depot4
AT('40-001') INTO
( PARTITION depot4 TABLESPACE ts009 MINEXTENTS 2,
PARTITION depot9 TABLESPACE ts010
);

原来的index partition缺省的 物理属性用于新的local index partition,存放在table partition的tablespace里。除非已经定义了tablespace。
新分离出来的包含数据的index partition被设置为不可用,空的index partition的index是valid的。

12、alter index split partition
把global index的一个partition分为两个partition。注意必须是global的,不能自己来split local index。
建立新的index segment,不再使用原来的空间。
如果是切分不可用的index partition,则新的index partition都是不可用的。必须rebuild。
如果index partition包含数据,则新的partition都是不可用的。

13、alter table move partition
删除旧的数据segment,建立新的segment,即使没有指定新的tablespace。
用于把数据移动到其他的partition,重新组织数据减少碎片,或者改变物理属性。
如果指定了partition 名字,则move partition之后,影响所有的index为不可用。包括
- 所有global index partition
- 每个local index的相应partition,但是它们的tablespace属性不变。
并行度:
如果在move中指定,则使用之,
否则使用table缺省的并行设置,
否则就不使用并行了。
但是要注意的是move命令中的parallel不改变table本身的parallel设置。
如果使用NOLOGGING,这个PARTITION应该周期性的备份。

14、ALTER TABLE EXCHANGE PARTITION
可以把非分区的TABLE和分区的数据交换。
这个过程是双向的。
实际上不交换数据。
在数据字典进行更改。
这个TABLE必须是存在的,不能是PARTITION TABLE或者是CLUSTER TABLE。
用户必须对两个表有ALTER 权限。
这两个TABLE不能有任何约束。
不激活任何TRIGGER。
这两个PT和T必须有相同的结构:相同的CLOUMN,相同的CLOUMN类型和大小。
影响到它们的GLOBAL INDEX。

例子:
ALTER TABLE sales EXCHANGE PARTITION feb97 WITH TABLE sales_feb97;

可以带的参数是
WITH VALIDATION:检查sales_feb97表,如果有问题返回错误。
WITHOUT VALIDATION:不检查TABLE sales_feb97,由用户自己检查。
iINCLUDING INDEXES:交换它们的index,其中的index必须相同的类型。
EXCLUING INDEXES:相关的INDEX都是不可用的。

TABLE和PARTITION的相关统计信息也交换,包括TABLE,CLUMON,INDEX统计和直方图。PARTITION TABLE的总体信息要重新统计。

它们的LOG属性也交换。

15、修改table的逻辑属性

比如增加新的column,约束,改变cloumn的类型,或者enable约束。如果是partition table,这些属性是针对所有的partition的。
改变逻辑属性的规则:
- 不能改变用作table partition key的cloumn类型、长度。
- 不能改变用作index partition key的cloumn类型、长度。
- 不能添加LONG, LONG RAW
- 不能把列改为LONG, LONG RAW
- 对有PARTITION在只读TABLESPACE上的TABLE,新的列不能有缺省值
- 对有PARTITION在只读TABLESPACE上的TABLE,不能从VARCHAR,VARCHAR2改为CHAR
- 对有PARTITION在只读TABLESPACE上的TABLE,不能增加CHAR的长度。

如果要增加唯一索引/PK,ORACLE会做相应的操作:
- 如果在这些COLUMN上已经有唯一索引,则使用之。
- 如果有了非唯一索引,则返回错误
- 如果已经有了唯一索引,但是是不可用的,则返回错误
- 否则,ORACLE建立GLOBAL NOPARTITION INDEX.

16、ALTER TABLE ..TRUNCATE PARTITION
删除PARTITION中的所有数据,比DELETE快。
同时删除对应的LOCAL INDEX数据,即使是不可用的INDEX。同时那些不可用的INDEX设置为VALID。INDEX的空间是释放还是等待再使用,取决于TABLE PARTITION的DROP STORAGE或者REUSE STORAGE。
如果有GLOBAL INDEX,且PARTITION包含数据,则它就变成不可用的了。如果想避免这样,可以先DELETE数据,再TRUNCATE PARTITION。
如果TABLE被其他表引用,且PARTITION不空,则返回错误。你可以先DISABLE约束,或者先DELETE再TRUNCATE。
不激发TRIGGER.

17、ALTER INDEX .. PARALLEL
改变INDEX的并行属性。

以下操作需要ALTER权限和DROP ANY TABLE的权限
- ALTER TABLE DROP PARTITION
- ALTER TABLE TRUNCATE PARTITION

以下操作需要ALTER权限和在TABLESPACE上的空间分配权限
- ALTER INDEX MODIFY PARTITION
- ALTER INDEX REBUILD PARTITION
- ALTER INDEX SPLIT PARTITION
- ALTER TABLE ADD PARTITION
- ALTER TABLE SPLIT PARTITION
- ALTER TABLE MODIFY PARTITION
- ALTER TABLE MOVE PARTITION


19、相关的数据字典
USER/ALL/DBA_PART_TABLES
USER/ALL/DBA_PART_TINDEXES
USER/ALL/DBA_PART_KEY_COLUMNS
USER/ALL/DBA_TAB_PARTITIONS
USER/ALL/DBA_IND_PARTITIONS
USER/ALL/DBA_PART_COL_STATISTICS
USER/ALL/DBA_TAB_COL_STATISTICS
USER/ALL/DBA_PART_HISTOGRAMS
USER/ALL/DBA_TAB_HISTOGRAMS
USER/ALL/DBA_OBJECTS
USER/ALL/DBA_TABLES
USER/ALL/DBA_INDEXES
USER/ALL/DBA_TAB_COLUMNS

20、PLAN_TABLE中的新COLUMN
PARTITION_START
PARTITION_STOP
PARTITION_ID
在分析步骤中加了新的步骤:PARTITION
另外在TABLE/INDEX的存取步骤中有引用PARTITION的步骤。

PARTITION_START和PARTITION_STOP
确定开始/结束的PARTITION范围
值包括:
NUMBER(n):由SQL编译器认定的第N个PARTITION
KEY:从某个PARTITION KEY值开始的开始时间
ROW LOCATION:从某行开始/结束的时间
INVALID:存取的PARTITION范围是空的。


PARTITION ID:存放开始结束的PARTITION 值对。

OPTION列:

对PARTITION步骤时,可以有CONCATENATED/SINGLE/EMPTY
CONCATENATED:合并存取的PARTITION结果集合
SINGLE:指示在运行时是单个PARTITION
EMPTY:存取的PARTITION是空的

对TABLE存取时候,按照ROWID范围确定,可以有如下值:
BY USER ROWID
BY INDEX ROWID
BU GLOBAL INDEX ROWID
BY LOCAL INDEX ROWID


21、常规路径的SQL*Loader
可以对一个partition table使用常规路径的SQL*Loader,没有新增语法,使用insert语句,同时更新local/global index。可以同时对一个table进行多个load。
可以一次load一个partition的数据,必须在load的控制文件里面指定table和partition。不属于该partition的数据badfile中。

22、直接路径的sql*loader
没有增加新的语法。
index自动更新。
指定table和partition name,DIRECT=TRUE
如果你在LOAD整个TABLE,不能同时运行其他的LOAD
如果没有GLOBAL INDEX,可以在不同的PARTITION上运行LOAD。
也可以对一个partition进行并行直接load:
- 必须指定PARALLEL=TRUE
相关的LOCAL INDEX PARTITION设置为不可用,必须自己重建。
不能有GLOBAL INDEX
可以并发的在一个TABLE上对不同的PARTITION进行直接路径LOAD。

23、EXPORT
依然支持FULL/USER/TABLE
PARTITION只支持TABLE方式
必须指定TABLE:PARTITION

24、IMPORT
可以把从PARTITION/NONPARTITION TABLE中DUMP出来的文件中,IMPORT到分区或者不分区的文件中。
支持FULL/TABLE/USER
如果原来的TABLE是PARTITION的,IMPORT建立PARTITION TABLE。
所有高于现在的PARTITION TABLE最高KEY的值都会被拒绝。
必须指定TABLE:PARTITION。
可以设置SKIP_UNUSABLE_INDEXES,跳过不可以用的INDEX.

25、ALALYZE
分析的目标可以是单个PARTITION,整个TABLE或者INDEX。
分析TABLE,INDEX,COLUMN的统计信息,并合并在一起。但是不合并它们的HISTOGRAM。
ORACLE优化器发现相关PARTITION没有被分析,使用缺省的TABLE/INDEX。

傻逼,别这样,对自己好一点儿
------------罗永浩说苹果粉丝用没有右键的苹果鼠标很累

靠身体吃饭的人,我向来都是鄙视的,他们就跟妓女一样;靠力气吃饭的人,我向来都是同情的,他们就跟老牛一样。刘翔,是个没有才华的人。他靠的就是身体,靠的就是力气,奔跑起来没有任何的技术含量,根本就不用脑子,唯一的办法就是以犀牛为榜样,使劲地往前冲,快到终点的时候一头砸下去,不管前面是空气还是大树,反正先砸下去再说。看看时间,12秒88!靠,第一,世界第一!百米飞人!于是露出了笑容,就跟傻子一样。
------------张怀旧

故宫不是首都机场。
------------芮成钢博客的呐喊,最终让星巴克从故宫搬了出去

我的能量和天分不做总统夫人算得上是一种浪费。
------------杨二车娜姆博客向离婚的法国总统表达爱意

爱好文学的女人都不是好女人。
------------张怀旧

董方卓像曼联的老板,所有队友都在拼命给他喂球,否则就要被扣工资似的。
------------董路曼联来华的比赛

我认识16号(阿森纳的弗拉米尼),化成灰我都认识他,只是我面前的屏幕太小了,只有巴掌大,就是我亲爹在场上踢球我也不一定能看得清楚啊......
------------董路在博客上说这句话不是自己的最好语录

每个男人心中都有一个狐狸精
------------王小峰

这个夜晚,所有中国职业球员、半职业球员乃至业余球员,每个人都会坚信一点:自己有能力成为中国国家队的一员......
------------董路说中国队7:0战胜缅甸队

拉莫斯带球,他看见禁区线就像看到了床,他倒了下去......但,没有点球。
------------董路

昨天我的车挂不上两档,今天维修后,问题还是存在,所以基本上一直用1档和3,4档在跑。但还好车速还是比较快,加上退出比赛的朋友帮我把车调的操控比昨天好了很多,所以名次还排在第3,领先了第4名一分钟。
------------这是韩寒博客上的一句话,进入了湖北一些名校联考的语文试卷,要求考生从中挑出4个语法错误

一个人的个人魅力大小取决于另一批无知者数量的多少。
------------王小峰

有人瞎扯,有人瞎踢。
------------董路说中国足球

在牛市中你选什么股都是对的。在熊市中最好的操作就是不操作。
------------凯恩斯

你上网么孙子?还跃然纸上我早跃然网上了!
------------王朔向因为侯耀文猝死而询问是否与自己有关的记者说

像我这样一个在食堂吃面都思考巴基斯坦局势的人,对高油价怎能坐视不管呢
------------王佩

Pages

Powered by Movable Type 6.3.2

About this Archive

This page is an archive of entries from March 2008 listed from newest to oldest.

February 2008 is the previous archive.

April 2008 is the next archive.

回到 首页 查看最近文章或者查看所有归档文章.