MySQL 怎麼用in,or,union all

MySQL 技術 IT圈的那些事兒 2017-04-01

首先測試 返回結果集只有一條的情況

測試表為用戶登錄日誌logs,value1是我們要進行測試的查詢字段條件

MySQL 怎麼用in,or,union all

表數據的總條數

MySQL 怎麼用in,or,union all

關閉緩存之後開始查詢每個查詢執行5次

select * from logs where value1 in(3895,15869)

MySQL 怎麼用in,or,union all

select * from logs where value1=3895 or value1=15869

MySQL 怎麼用in,or,union all

select * from logs where value1=15869 union all select * from logs where value1=3895

MySQL 怎麼用in,or,union all

然後show profiles看執行時間

MySQL 怎麼用in,or,union all

然後計算了一下5次平均用時

用in的平均用時 0.00026185

用or的平均用時 0.00024945

用union all 的平均用時 0.0004072

總結 :從用時間看,如果每個條件返回的結果為一條的話,用union all 用時是最長的,用or用時最短。


歡迎添加 微信號 ‘xha911’ 共同探討

相關推薦

推薦中...