mysql时间区间效率_对于sql中使用to_timestamp判断时间区间和不使用的效率对比及结论...
關(guān)于日期函數(shù)TO_TIMESTAMP
拓展:
date類型是Oracle常用的日期型變量,時(shí)間間隔是秒。兩個(gè)日期型相減得到是兩個(gè)時(shí)間的間隔,注意單位是“天”。
timestamp是DATE類型的擴(kuò)展,可以精確到小數(shù)秒(fractional_seconds_precision),可以是?0to9,缺省是6。兩個(gè)timestamp相減的話,不能直接的得到天數(shù),而是得到,多少天,多少小時(shí),多少秒等。
使用TO_TIMESTAMP函數(shù):
select
distinct hiui.salesman_id as salesmanId,
hui.user_name as salesmanName,
hui.user_phone as salesmanPhone,
hiui.class_id as classId,
hiui.department_id as departmentId,
get_affiliaction_name(hiui.class_id, hiui.department_id) as affiliactionName
from hz_invited_user_info as hiui
inner join hz_user_info as hui on hui.user_id = hiui.salesman_id
where
to_timestamp('2018-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') <= hiui.create_time
and to_timestamp('2019-05-28 00:00:00','yyyy-mm-dd hh24:mi:ss') >= hiui.create_time
時(shí)間: 0.949s? ? ? ? ? ??時(shí)間: 0.973s? ? ? ? ? ? ? ?時(shí)間: 0.783s
不使用:
select
distinct hiui.salesman_id as salesmanId,
hui.user_name as salesmanName,
hui.user_phone as salesmanPhone,
hiui.class_id as classId,
hiui.department_id as departmentId,
get_affiliaction_name(hiui.class_id, hiui.department_id) as affiliactionName
from hz_invited_user_info as hiui
inner join hz_user_info as hui on hui.user_id = hiui.salesman_id
where
'2018-01-01 00:00:00' <= hiui.create_time
and '2019-05-26 00:00:00' >= hiui.create_time
時(shí)間: 0.79s? ? ? ? ? ? ?時(shí)間: 0.743s? ? ? ? ? ? ? ? ? ?時(shí)間: 0.747s
兩者分別執(zhí)行了3次,發(fā)現(xiàn)不使用效率更高,因?yàn)樵趕ql執(zhí)行的時(shí)候,會(huì)自動(dòng)把時(shí)間字符串轉(zhuǎn)換成時(shí)間戳。但是使用效率也區(qū)別不是很明顯,可能是小數(shù)據(jù)的原因。
總結(jié)
以上是生活随笔為你收集整理的mysql时间区间效率_对于sql中使用to_timestamp判断时间区间和不使用的效率对比及结论...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 洛谷P2463 Sandy的卡片【后缀数
- 下一篇: [Microsoft][SQL Serv