問題描述
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 Afanasyev、Mr Bear)