In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about what is MYSQL development ideas, many people may not understand, in order to make you better understand, the editor summed up the following content, I hope you can gain something according to this article.
Yesterday, the dear operation and maintenance came to me to count a thing, the specific situation is this, to judge a machine in the priority of 1 in 900s, and count, if such a situation is more than 1, then alarm, and there is a situation, even if there is only 1 priority in 900 seconds, but the priority may be 23 456 as long as there is any one, call the police.
The following is such a sentence, there is no problem to write, this student used to be ORACLE's DBA. Ask me if there is any good way to improve the current poor performance of data query.
SELECT
S.DeviceReportedTime, # Statistical reporting time
S.Priority, # priority, there are 6, all of which are digits 1-6
S.FromHost, # host IP
S.Message # alarm message
FROM
SystemEvents s # assumes that there is 50 million data and time has an index
WHERE
S.FromHost = '10.50.131.1'
AND s.Priority = 1
AND s.DeviceReportedTime > DATE_SUB (NOW (), INTERVAL 900SECOND)
AND EXISTS (
SELECT
one
FROM
SystemEvents se
WHERE
Se.DeviceReportedTime > DATE_SUB (NOW (), INTERVAL 900SECOND)
AND se.FromHost = '10.50.131.1'
HAVING
COUNT (1) > = 2
);
First of all, logically speaking, MYSQL always wants to make complex things simple.
The alarm logic above has only two summaries.
More than 1 entry is recorded when 1 priority = 1
When 2 priority = 1, there are other priority records that exist in parallel.
It is simply expressed in SQL.
1 select count (*) from table where priority = 1 (count (*) > 2)
2 select count (*) from table where priority 1 + select count (*) from table where priority = 1 > 1
The above two situations will be called to the police.
If you use the above statement type through SQL SERVER ORACLE PG, it is a very good solution.
But MYSQL is not. MYSQL programming or extracting data are both short and fast, which is more in line with the scenario used by MYSQL's database.
Because it is to be calculated in ZABBIX, the final solution is
1 split the above SQL
The number of alarms in ZABBIX has changed from one to two.
Call the police
Select count (*) from table where
FromHost = '10.50.131.1'
AND Priority = 1
AND DeviceReportedTime > DATE_SUB (NOW (), INTERVAL 900)
Select count (*) from table
Where
FromHost = '10.50.131.1'
AND Priority 1
AND DeviceReportedTime > DATE_SUB (NOW (), INTERVAL 900)
Through the script, judge two statements if statement 1 > 1 gives an alarm
Statement 1 alarm when statement 2 > 1 in the case of = 1
If statement 1 = 0, there is no alarm.
Change the above complex SQL into statements + scripts to deal with
This is also an idea in the use of MYSQL, do not use MYSQL as an ORALCE, any long SQL will be piled up, it is definitely looking for trouble for the future.
After reading the above, do you have any further understanding of what is the development idea of MYSQL? 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: 276
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.