IFNULL trong vấn đề tốc độ mysql (IFNULL in mysql speed issue)


問題描述

IFNULL trong vấn đề tốc độ mysql (IFNULL in mysql speed issue)

select IFNULL(col1, (select col2 from table2 where ...)) from table1 

Will it run select for table2 if table1 would have not null value? This is a speed issue question. I have no appropriate database to check. 


參考解法

方法 1:

The sub‑query will only be executed if col1 is null but each time it is null. So if there are many null values in col1 this will become very slow.

The following may work better for you:

select coalesce(col1,col2) from table1,table2 
                     where (relationship between both tables)

(by Yevgeniy AfanasyevMr Bear)

參考文件

  1. IFNULL in mysql speed issue (CC BY‑SA 3.0/4.0)

#MySQL #database-performance #ifnull






相關問題

MySQL WHERE 時間戳 >= SUBDATE(MAX(timestamp), INTERVAL 5 DAY) (MySQL WHERE timestamp >= SUBDATE(MAX(timestamp), INTERVAL 5 DAY))

無法連接 - 數據庫或編碼錯誤 (Could Not Connect - Database or Coding Error)

在 MySQL 中查看授權 (View grants in MySQL)

修改列與更改列 (Modify column Vs change column)

SQL 查詢沒有返回任何值 (SQL query did not return any values)

IFNULL trong vấn đề tốc độ mysql (IFNULL in mysql speed issue)

Tối ưu hóa truy vấn MySQL PHP - Phản hồi (MySQL PHP Query Optimization - Feedbacks)

我將如何從我的數據庫中顯示用戶個人資料圖片? (How would I go about displaying user profile pictures from my database?)

自聯接以比較同一張表中的季度數據? (Self join to compare quarterly data from same table?)

設置默認數據庫連接 Mysql Workbench 5.2 (Set Default Database connection Mysql Workbench 5.2)

在 Mac 上將 PHP/MySQL/HTML 生成的報告轉換為 PDF 格式 (Convert reports generated in PHP/MySQL/HTML to PDF format on a Mac)

MYSQL查詢神奇地抓取數值 (MYSQL query magically grabs numeric value)







留言討論