SQL optimization (SQL TUNING) 10 minutes completed billion-level data Volume performance optimization (SQL tuning)

Source: Internet
Author: User

A few days ago. A user develops QQ to find me, for example the following:

The free Dolphin. 16:12:01

The island owner, my SQL can not find the results, could you help me see?

Orchid Island Main 16:12:10

How long is the result?

The Free Dolphin 16:12:17

How long has not produced the result, has not seen the result.

Orchid Island Main 16:12:26

Oh. Good.

Orchid Island Main 16:12:39

Send the SQL and run the plan.

The Free Dolphin 16:12:55

Select N.c1, N.C2,N.C3,N.C4,N.C5
From (select count (t.c1), T.C1, t.c2,t.c3,t.c4,t.c5
From Tab1 t
where T.c2 not in (' Val1 ', ' val2 ', ' val3 ', ' val4 ', ' VAL5 ')
Group by T.C1, T.C2,T.C3,T.C4,T.C5) n
Where NOT EXISTS
(SELECT * FROM (
Select count (S.C2), S.C1, S.C2
From (select M.c1, m.c2,m.c3,m.c4,m.c5
From Tab1 m
where exists (select C1
From TaB2 N
where C2 > sysdate-14
and m.c1 = n.c1)
And M.C1 is not NULL
and M.c2 not in (' Val1 ', ' val2 ', ' val3 ', ' val4 ', ' VAL5 ')) s
Group by S.C1, S.C2) t1 where t1.c2 = n.c2)
And N.C1 is not null;

Orchid Island Main 16:13:12

Are these two tables large?

The Free Dolphin 16:13:16

TAB1 Small, tab2 more than hundred million class. Two weeks data in tens of millions of.

Lan Hua Main 16:13:22

Ok.

Orchid Island Main 16:16:29

So change the SQL:

with T1 as (
Select count (t.c1), t.c1,t.c2,t.c3,t.c4,t.c5
From Tab1 t
where T.c2 not in (' Val1 ', ' val2 ', ' val3 ', ' val4 ', ' VAL5 ')
and C1 is not NULL
Group by T.C1, T.C2,T.C3,T.C4,T.C5)
Select T1.c1,t1.c2,t1.c3,t1.c4,t1.c5
from T1
Where NOT EXISTS (
Select/*+ Use_hash (m,n) */M.C1, M.C2,M.C3,M.C4,M.C5
from T1 m,tab2 N
where N.c2 > Sysdate-14
and m.c1 = N.c1
and t1.c2 = M.C2);

Orchid Island Main 16:16:43

Remove the Run schedule.

The Free Dolphin 16:16:57

Good.

The Free Dolphin 16:17:25


Orchid Island Main 16:17:57

Good. Give it a try.

The Free Dolphin 16:19:28

The result, 37s.

Orchid Island Main 17:20:21

Yes, well.

Orchid Island Main 17:20:34

is that possible?

The Free Dolphin 17:20:47

to be able to

Orchid Island Main 17:21:11

Yes, well. That's the first thing. No, keep moving.

The Free Dolphin 17:21:30

Well, thank you, Island Master.

Orchid Island Main 17:21:53

you're welcome. Be busy. Have a connection.

The Free Dolphin 17:22:18

Oh, yes. You are busy ...

At this point, the user of this SQL optimization end, in fact, this statement should also have the optimization of space, simply, the user said to be able to, because the optimization is endless, and further optimization may require further information. And sometimes there is a need for greater modification. In view of various factors, the statement and plan are processed, recorded in this, mutual encouragement.











SQL optimization (SQL TUNING) 10 minutes completed billion-level data Volume performance optimization (SQL tuning)

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.