Oracle join on Data Filtering

Source: Internet
Author: User

Copy codeThe Code is as follows:
Select a. f_username
From
(
SELECT/* + parallel (gu, 4) */distinct gu. f_username
FROM t_base_succprouser gu
Where gu. f_expectenddate> (select trunc (sysdate, 'y') from dual)
And gu. f_lotid = 1
And gu. f_playid = 4
And gu. f_paymoney >=1500
)
Left join
(
Select
From t_base_vip_customes
And (vu. f_passeddate is null) or (vu. f_passeddate> trunc (sysdate, 'y ')))
And (vu. f_lotid is null) or (vu. f_lotid = 1 ))
And (vu. f_playid is null) or (vu. f_playid = 4 ))
And (vu. f_condtionid is null) or (vu. f_condtionid = 3 ))
) B
On A. f_username = B. f_usernam
Where B. f_username is null

Only some users can be identified using the following statement
Copy codeThe Code is as follows:
SELECT/* + parallel (gu, 4) */distinct gu. f_username
FROM t_base_succprouser gu
Left join t_base_vip_customes VU on gu. f_username = vu. f_username
Gu. f_expectenddate> (select trunc (sysdate, 'y') from dual)
And gu. f_lotid = rec_viplotplay.f_lotid
And gu. f_playid = rec_viplotPlay.f_Playid
And gu. f_paymoney> = rec_viplotPlay.F_Conditon_ValuesA
And (vu. f_passeddate is null) or (vu. f_passeddate> trunc (sysdate, 'y ')))
And (vu. f_lotid is null) or (vu. f_lotid = rec_viplotplay.f_lotid ))
And (vu. f_playid is null) or (vu. f_playid = rec_viplotPlay.f_Playid ))
And (vu. f_condtionid is null) or (vu. f_condtionid = rec_viplotPlay.F_CondtionID ))
And vu. f_username is null

Execution Plan:
Copy codeThe Code is as follows:
Select statement, GOAL = ALL_ROWS
HASH UNIQUE
NESTED LOOPS OUTER
PARTITION RANGE ALL
Table access full Object name = T_BASE_SUCCPROUSER
VIEW
FILTER
Table access full Object name = T_BASE_VIP_CUSTOMES
FAST DUAL

Later, I changed it to the following to check it out.
Copy codeThe Code is as follows:
SELECT/* + parallel (gu, 4) */distinct gu. f_username
FROM t_base_succprouser gu
Left join t_base_vip_customes VU on gu. f_username = vu. f_username
And (vu. f_passeddate is null) or (vu. f_passeddate> trunc (sysdate, 'y ')))
And (vu. f_lotid is null) or (vu. f_lotid = rec_viplotplay.f_lotid ))
And (vu. f_playid is null) or (vu. f_playid = rec_viplotPlay.f_Playid ))
And (vu. f_condtionid is null) or (vu. f_condtionid = rec_viplotPlay.F_CondtionID ))

Where gu. f_expectenddate> (select trunc (sysdate, 'y') from dual)
And gu. f_lotid = rec_viplotplay.f_lotid
And gu. f_playid = rec_viplotPlay.f_Playid
And gu. f_paymoney> = rec_viplotPlay.F_Conditon_ValuesA
And vu. f_username is null
Execution Plan:
Select statement, GOAL = ALL_ROWS
HASH UNIQUE
FILTER
NESTED LOOPS OUTER
Table access by global index rowid Object name = T_BASE_SUCCPROUSER
Index range scan Object name = IX_BASE_PROUSER_LOWEX
FAST DUAL
VIEW
Table access full Object name = T_BASE_VIP_CUSTOMES

Oracle doesn't understand how to filter out the data and connect to it first? Too stupid! In this way, the qualified data is also filtered out.

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.