Optimize hundreds of millions of data queries in 10 minutes

Source: Internet
Author: User
A few days ago, a user developed QQ to contact me, as shown below: Free dolphins. At 16:12:01 AM, I couldn't find the result of one of my SQL statements. Can you check it for me? How long will it take for an orchid island owner to arrive at 16:12:10? Free dolphins did not deliver any results at 16:12:17 and never saw any results. 16:12:26, good. Orchid island master 16:12:39

A few days ago, a user developed QQ to contact me, as shown below: Free dolphins. At 16:12:01 AM, I couldn't find the result of one of my SQL statements. Can you check it for me? How long will it take for an orchid island owner to arrive at 16:12:10? Free dolphins did not deliver any results at 16:12:17 and never saw any results. 16:12:26, good. Orchid island master 16:12:39

A user developed QQ to contact me a few days ago, as shown below:

Free dolphins. 16:12:01

Island Lord, I cannot find the result of one of my SQL statements. Can you check it for me?

Orchid island master 16:12:10

How long will it take?

Free dolphin 16:12:17

No results are returned for a long time.

Orchid island master 16:12:26

Haha, good.

Orchid island master 16:12:39

Send SQL statements and execution plans.

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 master 16:13:12

Are these two tables big?

Free dolphin 16:13:16

Tab1 is small, with more than tabps and tens of millions of data in two weeks.

Lanhua island master 16:13:22

OK.

Orchid island master 16:16:29

So change the SQL statement:

With t1 (
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 master 16:16:43

Remove the execution plan.

Free dolphin 16:16:57

Okay.

Free dolphin 16:17:25

Orchid island master 16:17:57

Okay. Try it.

Free dolphin 16:19:28

The result is 37 s.

Orchid island master 17:20:21

Well, good.

Orchid island master 17:20:34

Can this happen?

Free dolphin 17:20:47

Yes.

Orchid island master 17:21:11

Well, well, let's do it first and stop calling it.

Free dolphin 17:21:30

Thank you, island master.

Orchid island master 17:21:53

You're welcome. You have to contact me.

Free dolphin 17:22:18

Well, you are busy...

At this point, the optimization of the user's SQL has ended. In fact, there should be room for optimization of this statement, but the user can say it is okay, because the optimization is endless and, further Optimization may require further information and sometimes requires greater changes. In view of various factors, we have processed the statements and plans and recorded them here!

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.