[請益] 關於 where 前後順序是否會影響效能
※ [本文轉錄自 Database 看板 #1JPwsaNg ]
作者: tas72732002 (蔥頭) 看板: Database
標題: [SQL ] 關於 where 前後順序是否會影響效能
時間: Mon May 5 23:26:26 2014
資料庫名稱:MySQL
資料庫版本:5.1.33
內容/問題描述:
我想請問一下,假設account是帳號, is_ban(1:代表被鎖帳號)
(1) select * from where account='123' and is_ban=0;
(2) select * from where is_ban=0 and account='123';
以上述兩句sql,第1句sql是否優於第二句還是一樣??
以第1句sql來說資料庫運作方式是否是先找出account='123'的rows再找該rows is_ban=0,
還是說先篩選account='123' 再篩選is_ban=0,兩個篩選出來的rows再做and??
較常理來說先找account='123'再找is_ban=0會優於先找is_ban再找account='123'嗎?
最後題外問個問題 where account='123' and is_ban=0; database換按照sql由左而右的語法進行篩選是嘛?? 也就是先篩選account='123' 再篩選is_ban=0
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.249.120.106
※ 文章網址: http://www.ptt.cc/bbs/Database/M.1399303588.A.5EA.html
※ 編輯: tas72732002 (111.249.120.106), 05/05/2014 23:27:43
推
05/06 01:30, , 1F
05/06 01:30, 1F
※ 發信站: 批踢踢實業坊(ptt.cc)
※ 轉錄者: tas72732002 (203.69.59.91), 05/06/2014 13:35:39
→
05/06 14:48, , 2F
05/06 14:48, 2F
推
05/06 17:58, , 3F
05/06 17:58, 3F
→
05/06 20:51, , 4F
05/06 20:51, 4F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章