Chapter IV SQL optimization statistics

Shenkaoziliao:
This series of blog mainly Cenkaoziliao have CUUG database Rannai Gang teacher teaching notes, "SQL optimization core idea" (Luobing Sen, Huang Chao Zhong Jiao with), "PostgreSQL Inside: query optimization Depth" (Zhang Shujie a), ranking in no particular order.

 

1 Statistic Description

Data in the database has been a change, then the implementation plan and sometimes also to dynamic, cite a simple example, today's commodity ID a particular table is evenly distributed, then a promotion, may make this product a corresponding ID the data explosion, the original query the index to go, may go the whole table. Monitoring is a man-made table change is impossible and can not be achieved. However, the optimizer has been doing this work, the optimizer will automatically adjust the implementation plan.

So the question is, how do optimizer.

First, relational database has a complete theoretical foundations of mathematics, relational algebra, it can be based on equivalent variations, provide better execution plan.

However, the equivalent transformation is optimized ground rules, but these equivalent variations, and changes in access paths (index reading or full table scan), but also can have some reference data, reference data that these statistics.

2 statistics collection script,

BEGIN

  DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=>'SCOTT',

                                TABNAME=>'TEST1',

                                ESTIMATE_PERCENT=>100,

                                METHOD_OPT=>'FOR COLUMNS OWNER SIZE SKEWONLY',

                                NO_INVALIDATE=>FALSE,

                                DEGREE=>1,

                                CASCADE=>TRUE);

END;

/

This parameter everyone inside their own online access to the following, we focus here just talk about METHOD_OPT, this column decided histogram generation.

So what is a histogram of it, simply, the histogram describes the data evenly distributed condition of a column, this is an important parameter optimizer choose the access path and table connection.

3 Extended Statistics

Sometimes, just to collect statistical information for a column, the optimizer does not make good execution plan chosen, you need to collect multiple columns together, which is extended statistics collection, the hope that their investigation.

Guess you like

Origin blog.csdn.net/songjian1104/article/details/91349933