Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Why the sqlserver not in statement causes the program to crash

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to talk to you about why the sqlserver not in sentence caused Cheng Chong to collapse. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Two tables Organization structure Table (Organise) and payroll History Table (WagePerMonthHis) two tables are associated with Organise.Item_id and WagePerMonthHis.OrgIdS. There are about 6000 records and 11 fields in the Organise table (hereinafter referred to as the O table). WagePerMonthHis (hereinafter referred to as Table W) has 1.25 million records and 25 fields. The following statement in the original program queries all records that are not in the W table at organizational structure level 2. The copy code is as follows: select OrgId as company code, OrgName as company name from Organise where OrgLev=2 and item_id not in (select OrgidS from WagesPerMonthHis where WagesYear='2010' and WagesMonth= '01' Group by OrgidS,OrgNameS) order by Orgid

The execution of the statement takes as long as 33 seconds, and the configuration of the server is relatively high: 16 core 4CPU not only has 24G memory, and there are no bottlenecks in memory and CPU execution. At first, I thought it was caused by the slow execution of this statement (select OrgidS from WagesPerMonthHis where WagesYear='2010' and WagesMonth= '01' Group by OrgidS,OrgNameS). When executed alone, I found that the execution speed was very fast, about 2 seconds later, so the crux of the problem came out. It is the performance degradation brought about by the full-scan keyword not in. The most direct is to cause the page to lose response, a key function can not be used. Try the not exist sentence, found that the effect is the same, not like the Internet said can improve a lot of performance. So the re-optimization statement copies the code as follows: select a.OrgId as company code, a.OrgName as company name, a.item_id from Organise a left outer join (select distinct b.OrgIdS from WagesPerMonthHis b where WagesYear='2010' and WagesMonth='01') as b on a.item_id = b.OrgidS where a.OrgLev = 2 and b.OrgIdS is Null order by company code

After switching to the left outer connection (in fact, the left connection is also possible), the whole sentence execution speed is 400ms, 33 seconds and 400ms. I don't think many people thought of it.

After reading the above, do you have any further understanding of why the sqlserver not in statement crashed Cheng Chong? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report