Filter conversion can be optimized at one time, and filter conversion can be optimized.

Source: Internet
Author: User

Filter conversion can be optimized at one time, and filter conversion can be optimized.

There is a problem with SQL Performance. When a filter is found in the execution plan, you should be careful when it comes to it. Like nestloop, my previous blog has studied it.Explore the filter principles in execution plans. Using exists can easily cause filter.

Before optimization:

Select ggpi. ID,

GGPI. PLAN_STATE,
GGPI. PLAN_TYPE,
GGPI. PLAN_CODE,
GGPI. PLAN_SOURCE_TYPE,
GGPI. PLAN_BEGIN_DATE,
GGPI. PLAN_END_DATE,
GGPI. REAL_BEGIN_DATE,
GGPI. REAL_END_DATE,
GGPI. WORK_MASTER_UNAME,
GGPI. WORK_MASTER_UID,
GGPI. WORK_TEAM_ONAME,
GGPI. WORK_SITE_NAMES,
GGPI. WORK_CONTENT,
GGPI. WORK_TYPE,
GGPI. WORK_MEMBER_UNAMES,
GGPI. DIGGATCH_WORK_UNAME,
GGPI. WORKING
FROM GG_PD_PP_INFO GGPI
WHERE PLAN_STATE IN (50, 60, 70)
AND (GGPI. PLAN_BEGIN_DATE> = sysdate and GGPI. PLAN_BEGIN_DATE <= sysdate) or
(GGPI. PLAN_END_DATE> = sysdate and GGPI. PLAN_END_DATE <= sysdate) or
(GGPI. PLAN_BEGIN_DATE <sysdate and GGPI. PLAN_END_DATE> sysdate ))
And ggpi. BUREAU_CODE = '20140901'
AND (GGPI. WORK_MASTER_UID = 'fa3502d1291a4a07a3b9e3e0f9a41904 'OR EXISTS
(SELECT 1
FROM GG_PD_PP_WORK_MEMBER PMEM
Where pmem. PROD_PLAN_ID = GGPI. ID
And pmem. WORK_MEMBER_UID = 'fa3502d1291a4a07a3b9e3e0f9a41904'
And pmem. BUREAU_CODE = '000000 '));
Execution Plan
----------------------------------------------------------
Plan hash value: 980323934
Bytes -------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time | Pstart | Pstop |
Bytes -------------------------------------------------------------------------------------------------------------------------------
| 0 | select statement | 9670 | 2039K | 25694 (1) | 00:05:09 |
| * 1 | FILTER|
| 2 | partition list single | 72882 | 15 M | 25694 (1) | 00:05:09 | KEY |
| 3 | partition range all | 72882 | 15 M | 25694 (1) | 00:05:09 | 1 | 14 |
| * 4 | table access full | GG_PD_PP_INFO | 72882 | 15M | 25694 (1) | 00:05:09 |
| * 5 | table access by global index rowid | GG_PD_PP_WORK_MEMBER | 1 | 49 | 5 (0) | 00:00:01 | 4 | 4 |
| * 6 | index range scan | IDX_PP_WORK_MEMBER_PPID | 6 | 3 (0) | 00:00:01 |
Bytes -------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id ):
---------------------------------------------------
1-filter ("GGPI". "WORK_MASTER_UID" is null or exists (SELECT 0 FROM "GG_PD_PP_WORK_MEMBER"
"PMEM" WHERE "PMEM". "PROD_PLAN_ID" =: B1 AND "PMEM". "WORK_MEMBER_UID" = 'fa3502d1291a4a07a3b9e3e0f9a41904 'AND
"PMEM". "BUREAU_CODE" = '000000 '))
4-filter ("PLAN_STATE" = 50 OR "PLAN_STATE" = 60 OR "PLAN_STATE" = 70) AND ("GGPI". "PLAN_END_DATE"> SYSDATE @! AND
"GGPI". "PLAN_BEGIN_DATE" <SYSDATE @! OR "GGPI". "PLAN_BEGIN_DATE" = SYSDATE @! OR "GGPI". "PLAN_END_DATE" = SYSDATE @!))
5-filter ("PMEM". "WORK_MEMBER_UID" = 'fa3502d1291a4a07a3b9e3e0f9a41904 'AND "PMEM". "BUREAU_CODE" = '2016 ')
6-access ("PMEM". "PROD_PLAN_ID" =: B1)
Statistics
----------------------------------------------------------
1 recursive cballs
0 db block gets
103763 consistent gets
0 physical reads
0 redo size
3178 bytes sent via SQL * Net to client
524 bytes encoded ed via SQL * Net from client
2 SQL * Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
7 rows processed


After optimization:
Select ggpi. ID,
GGPI. PLAN_STATE,
GGPI. PLAN_TYPE,
GGPI. PLAN_CODE,
GGPI. PLAN_SOURCE_TYPE,
GGPI. PLAN_BEGIN_DATE,
GGPI. PLAN_END_DATE,
GGPI. REAL_BEGIN_DATE,
GGPI. REAL_END_DATE,
GGPI. WORK_MASTER_UNAME,
GGPI. WORK_MASTER_UID,
GGPI. WORK_TEAM_ONAME,
GGPI. WORK_SITE_NAMES,
GGPI. WORK_CONTENT,
GGPI. WORK_TYPE,
GGPI. WORK_MEMBER_UNAMES,
GGPI. DIGGATCH_WORK_UNAME,
GGPI. WORKING
FROM GG_PD_PP_INFO GGPI
WHERE PLAN_STATE IN (50, 60, 70)
AND (GGPI. PLAN_BEGIN_DATE> = sysdate and GGPI. PLAN_BEGIN_DATE <= sysdate) or
(GGPI. PLAN_END_DATE> = sysdate and GGPI. PLAN_END_DATE <= sysdate) or
(GGPI. PLAN_BEGIN_DATE <sysdate and GGPI. PLAN_END_DATE> sysdate ))
And ggpi. BUREAU_CODE = '20140901'
And ggpi. WORK_MASTER_UID = 'fa3502d1291a4a07a3b9e3e0f9a41904'
Union all
Select ggpi. ID,
GGPI. PLAN_STATE,
GGPI. PLAN_TYPE,
GGPI. PLAN_CODE,
GGPI. PLAN_SOURCE_TYPE,
GGPI. PLAN_BEGIN_DATE,
GGPI. PLAN_END_DATE,
GGPI. REAL_BEGIN_DATE,
GGPI. REAL_END_DATE,
GGPI. WORK_MASTER_UNAME,
GGPI. WORK_MASTER_UID,
GGPI. WORK_TEAM_ONAME,
GGPI. WORK_SITE_NAMES,
GGPI. WORK_CONTENT,
GGPI. WORK_TYPE,
GGPI. WORK_MEMBER_UNAMES,
GGPI. DIGGATCH_WORK_UNAME,
GGPI. WORKING
FROM GG_PD_PP_INFO GGPI
WHERE PLAN_STATE IN (50, 60, 70)
AND (GGPI. PLAN_BEGIN_DATE> = sysdate and GGPI. PLAN_BEGIN_DATE <= sysdate) or
(GGPI. PLAN_END_DATE> = sysdate and GGPI. PLAN_END_DATE <= sysdate) or
(GGPI. PLAN_BEGIN_DATE <sysdate and GGPI. PLAN_END_DATE> sysdate ))
And ggpi. BUREAU_CODE = '20140901'
And ggpi. ID in
(Select pmem. PROD_PLAN_ID
FROM GG_PD_PP_WORK_MEMBER PMEM
Where pmem. WORK_MEMBER_UID = 'fa3502d1291a4a07a3b9e3e0f9a41904'
And pmem. BUREAU_CODE = '000000 ');
Execution Plan
----------------------------------------------------------
Plan hash value: 1911592856
Certificate -----------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time | Pstart | Pstop |
Certificate -----------------------------------------------------------------------------------------------------------------------------------
| 0 | select statement | 1227 | 316K | 3740 (1) | 00:00:45 |
| 1 | UNION-ALL |
| * 2 | table access by global index rowid | GG_PD_PP_INFO | 22 | 4752 | 160 (0) | 00:00:02 | ROWID |
| * 3 | index range scan | IND_GGPI_WORK_MASTER_UID | 222 | 5 (0) | 00:00:01 |
| 4 | nested loops | 1205 | 311K | 3580 (1) | 00:00:43 |
| 5 | nested loops | 1205 | 311K | 3580 (1) | 00:00:43 |
| 6 | sort unique | 1205 | 59045 | 2373 (1) | 00:00:29 |
| * 7 | table access by global index rowid | GG_PD_PP_WORK_MEMBER | 1205 | 59045 | 2373 (1) | 00:00:29 | 4 | 4 |
| * 8 | index range scan | IND_GGPW_WORK_MEMBER_UID | 4240 | 31 (0) | 00:00:01 |
| * 9 | index unique scan | PK_GG_PD_PP_INFO | 1 | 1 (0) | 00:00:01 |
| * 10 | table access by global index rowid | GG_PD_PP_INFO | 1 | 216 | 2 (0) | 00:00:01 | ROWID |
Certificate -----------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id ):
---------------------------------------------------
2-filter ("PLAN_STATE" = 50 OR "PLAN_STATE" = 60 OR "PLAN_STATE" = 70) AND ("GGPI". "PLAN_END_DATE"> SYSDATE @! AND
"GGPI". "PLAN_BEGIN_DATE" <SYSDATE @! OR "GGPI". "PLAN_BEGIN_DATE" = SYSDATE @! OR "GGPI". "PLAN_END_DATE" = SYSDATE @!) AND
"GGPI". "BUREAU_CODE" = '000000 ')
3-access ("GGPI". "WORK_MASTER_UID" = 'fa3502d1291a4a07a3b9e3e0f9a41904 ')
7-filter ("PMEM". "BUREAU_CODE" = '000000 ')
8-access ("PMEM". "WORK_MEMBER_UID" = 'fa3502d1291a4a07a3b9e3e0f9a41904 ')
9-access ("GGPI". "ID" = "PMEM". "PROD_PLAN_ID ")
10-filter ("GGPI". "PLAN_END_DATE"> SYSDATE @! AND "GGPI". "PLAN_BEGIN_DATE" <SYSDATE @! OR
"GGPI". "PLAN_BEGIN_DATE" = SYSDATE @! OR "GGPI". "PLAN_END_DATE" = SYSDATE @!) AND ("PLAN_STATE" = 50 OR "PLAN_STATE" = 60 OR
"PLAN_STATE" = 70) AND "GGPI". "BUREAU_CODE" = '20140901 ')
Statistics
----------------------------------------------------------
1 recursive cballs
0 db block gets
4321 consistent gets
550 physical reads
0 redo size
3228 bytes sent via SQL * Net to client
524 bytes encoded ed via SQL * Net from client
2 SQL * Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
7 rows processed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.