时间戳比MySQL中的datetime列快多少? [英] How much faster is timestamp than datetime column in MySQL?

查看:334
本文介绍了时间戳比MySQL中的datetime列快多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这包括两个问题:

  1. 在"order by"查询中,MySQL的timestamp字段真的比datetime字段快吗?

  1. Is MySQL's timestamp field really faster than datetime field in "order by" query?

如果上述问题的答案是肯定的,那么速度可能会快多少?假设存在一个1亿行的表中,并且经常基于MySQL内部的timestamp字段对一堆100-200k行进行排序,那么通过在外部程序中将timestamp转换为可读的字符串格式,可以抵消排序时间的改善吗?

If the answer to above question is yes, how much faster it could be? Supposed in a table of 100 million rows and frequently sort a bunch of 100-200k rows based on timestamp field inside MySQL, will the sort time improvement be offseted by converting timestamp to readable string format in outside program?

推荐答案

最简单的查找方法是编写单元测试,并实际获得一些数字.

The easiest way to find out is to write a unit test, and actually get some numbers.

我的理论是时间戳会更快,但是根据此博客,我错了: http://dbscience.blogspot.com/2008 /08/can-timestamp-be-slower-than-datetime.html

My theory was that timestamp would be faster, but according to this blog I am wrong: http://dbscience.blogspot.com/2008/08/can-timestamp-be-slower-than-datetime.html

这就是为什么我倾向于在确定优化位置之前通过剖析来获取数字,因为有时我的直觉会很不正确.

This is why I tend to get numbers, by profiling, before I decide where to optimize, as my gut feeling can be quite wrong at times.

因此,它可能取决于您使用的MySQL版本,但看来日期时间可能会更快.

So, it may depend on the version of MySQL you are using, but it appears that datetime may be faster.

这篇关于时间戳比MySQL中的datetime列快多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆