HanG321 Blog
Be Shine, Be Smile, Be Wild

avoid subquery in mysql update statement

November 29, 2018|MySQL|生活記事, 科技資訊

公司最近有個deployment,要run個SQL patch。係QA 同staging 都冇事,點知一去production run左30mins 都未行完,terminated & rollback. 原來係其中一個update statement 行subquery,where id = (select  …) mysql 會run select on each row 🙁  DataSet 一大,慢到嘔。

slow query
MySQL
1
2
3
4
5
6
7
8
9
10
11
CREATE TABLE alarm_backup SELECT * FROM alarm;  
 
UPDATE alarm a
SET a.status = 'active' , .......
WHERE a.id = (
  SELECT al.id
  FROM alarm_backup ab
    JOIN device d ON ab.device_id = d.id
    JOIN ......
  WHERE .....
);

其實subquery 係唔需要⋯⋯

simple & effective
MySQL
1
2
3
4
5
6
7
CREATE TABLE alarm_backup SELECT * FROM alarm;  
 
UPDATE alarm a
JOIN device d ON a.device_id = d.id
JOIN ......
SET a.status = 'active' , .......
WHERE ..... ;

故事教訓我地: 1) 放假返黎之後小心點,你唔係到個時既Peer review 都要睇返。 2) 唔好咁容易信你上司,上左神枱技術係會回塘 😂

Read more »

hacktoberfest

October 6, 2018|git|科技資訊

funny, you can get a free tee shirt when you make 5 pull request in Oct 1-31. This is the 5th year but I only knew it now 😛 check out the details in https://hacktoberfest.digitalocean.com/

Read more »

Google Cloud Summit Sydney 2018 part 1

September 27, 2018|GCP, kubernetes|生活記事, 科技資訊

24 hours 快閃到sydney 訓一晚. 原本打算早點出門, 行過Sydney University 參觀吓先到會場, 可惜落雨都係uber. Keynote 比較大路,冇乜特別,都係話google 投資左好多錢咁啦。GCP 起步遲過AWS, 不過我覺得kubernetes 先係王道,比起vendor lock in AWS 好. 其次我覺得AWS product啲名好麻煩好難記 😅 1st: CI/CD pipelines in the cloud 由source code repo, build & test, artifact management, deliver. 以前係svn + maven + jenkins,而家係github/gitlab + Cloud Build + Container Registey + Spinnaker. 2nd: Kubernetes & Istio: The Efficient Approach to well-managed Infrastructure 之前聽Craig Box 嘅Podcast,今次卒之見到真人,係全日嘅session入邊佢係最流暢嘅presenter. k8s / envoy / sidecar / citadel  似乎真係要落手落腳做過先知深淺。GKE serverless Add-on looks promising. 3rd: AI drives an Exceptional Customer Experience 唔算好technical. High level concept on Contact Centre AI, 但係如果有budget implement 到真係升level 到另一個層次. Google 真係好強力推動 AI.   …. 我打字實在太慢,下次再續

Read more »
1234...30...

搜尋 Search

Copyright © 2004-2021 hang321.net. All Rights Reserved