Got it

Huawei FusionInsight Hash join data is too large to rewrite

Latest reply: Dec 29, 2018 06:48:10 605 1 7 0 0

Hello, everyone!

This post will share with you a case about Huawei FusionInsight hash join data is too large to rewrite.

Because the amount of data is too large, the original business is 5 billion and 5 billion two tables

to do full table join, hash join data is too large.

The original SQL is: 

select
T3.name as "region",
Case t2.InsuredSex when 2 then 'female' else 'male' end as "gender",
Count(*) as "quantity"
From basicpolicy t1,insured t2,area_table t3
Where t1.PolicyNo=t2.PolicyNo
And t3.id=t1.EffPrefectureCode
Group by t3.name,t2.InsuredSex;

When the work_mem memory is set to 12GB, the data is downloaded, and the execution time is 3126085ms.

When the work_mem memory is set to 22GB, the data has no disk, and the execution time is 892271ms.

For this, analyze the business logic, modify the SQL, group by gender, and then slicing through union all.

After rewriting SQL: 

select t3.name as "region", t4.sex as "gender", t4.num as "quantity"
From area_table t3,
(select
t1.EffPrefectureCode,
'Female'::text as sex,
Count(t1.PolicyNo) as num
From basicpolicy t1,insured t2
Where t1.PolicyNo=t2.PolicyNo
And t2.InsuredSex=2
Group by t1.EffPrefectureCode) t4
Where t3.id=t4.EffPrefectureCode
Union all
Select t3.name as "region", t4.sex as "gender", t4.num as "quantity"
From area_table t3,
(select
t1.EffPrefectureCode,
'Male'::text as sex,
Count(t1.PolicyNo) as num
From basicpolicy t1,insured t2
Where t1.PolicyNo=t2.PolicyNo
And t2.InsuredSex=2
Group by t1.EffPrefectureCode) t4
Where t3.id=t4.EffPrefectureCode;

Work_mem memory uses 15GB, data has no download, execution time: 498279ms.

That's all, thanks!

work_mem memory is set to 12GB, the data is downloaded, and the execution time is 3126085ms.

When the work_mem memory is set to 22GB, the data has no disk, and the execution time is 892271ms.

For this, analyze the business logic, modify the SQL, group by gender, and then splicing through union all.

After rewriting SQL: select t3.name as "region", t4.sex as "gender", t4.num as "quantity"
View more
  • x
  • convention:

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.