High Performance My SQL, Third Edition

Date and Time Types

My SQL has many types for various kinds of date and time values, such as YEAR and
DATE. The finest granularity of time My SQL can store is one second. (Maria DB has
microsecond-granularity temporal types.) However, it can do temporal computations
with microsecond granularity, and we’ll show you how to work around the storage
limitations.

Most of the temporal types have no alternatives, so there is no question of which one
is the best choice. The only question is what to do when you need to store both the
date and the time. My SQL offers two very similar data types for this purpose: DATETIME

and TIMESTAMP. For many applications, either will work, but in some cases, one

works better than the other. Let’s take a look:

DATETIME

This type can hold a large range of values, from the year 1001 to the year 9999,
with a precision of one second. It stores the date and time packed into an integer
in YYYYMMDDHHMMSS format, independent of time zone. This uses eight bytes
of storage space.

By default, My SQL displays DATETIME values in a sortable,unambiguous format,

such as 2008-01-16 22:37:08. This is the ANSI standard way to represent dates
and times.

TIMESTAMP

As its name implies, the TIMESTAMP type stores the number of seconds elapsed since
midnight, January 1, 1970, Greenwich Mean Time (GMT)—the same as a Unix
timestamp. TIMESTAMP uses only four bytes of storage, so it has a much smaller
range than DATETIME: from the year 1970 to partway through the year 2038. My SQL
provides the FROM_UNIXTIME() and  UNIX_TIMESTAMP() functions to convert a Unix
timestamp to a date, and vice versa.

My SQL 4.1 and newer versions format TIMESTAMP values just like  DATETIME values,

but My SQL 4.0 and older versions display them without any punctuation between

the parts. This is only a display formatting difference; the TIMESTAMP storage format is the same in all My SQL versions.

The value a TIMESTAMP displays also depends on the time zone. The My SQL server,
operating system, and client connections all have time zone settings.

Thus, a TIMESTAMP that stores the value 

0 actually displays it as 1969-12-31 19:00:00
in Eastern Standard Time (EST), which has a five-hour offset from GMT. It’s worth
emphasizing this difference: if you store or access data from multiple time zones,
the behavior of TIMESTAMP and  DATETIME will be very different. The former preserves
values relative to the time zone in use, while the latter preserves the textual repre-
sentation of the date and time.
TIMESTAMP also has special properties that
DATETIME doesn’t have. By default,
My SQL will set the first TIMESTAMP column to the current time when you insert a
row without specifying a value for the column.

My SQL also updates the first
TIMESTAMP column’s value by default when you update the row, unless you assign
a value explicitly in the UPDATE statement. You can configure the insertion and
update behaviors for any TIMESTAMP column. Finally, TIMESTAMP columns are
NOT NULL by default, which is different from every other data type.

Special behavior aside, in general if you can use TIMESTAMP you should, because it is
more space-efficient than DATETIME. Sometimes people store Unix timestamps as integer
values, but this usually doesn’t gain you anything. The integer format is often less
convenient to deal with, so we do not recommend doing this.
What if you need to store a date and time value with subsecond resolution? My SQL
currently does not have an appropriate data type for this, but you can use your own
storage format: you can use the BIGINT data type and store the value as a timestamp in
microseconds, or you can use a DOUBLE and store the fractional part of the second after
the decimal point. Both approaches will work well. Or you can use Maria DB instead
of My SQL.

but this usually doesn’t gain you anything.的更多相关文章

  1. Theoretical comparison between the Gini Index and Information Gain criteria

    Knowledge Discovery in Databases (KDD) is an active and important research area with the promise for ...

  2. (转载)高速ADC的关键指标:量化误差、offset/gain error、DNL、INL、ENOB、分辨率、RMS、SFDR、THD、SINAD、dBFS、TWO-TONE IMD

    (一)一个基本概念 分贝(dB):按照对数定义的一个幅度单位.对于电压值,dB以20log(VA/VB)给出:对于功率值,以10log(PA/PB)给出.dBc是相对于一个载波信号的dB值:dBm是相 ...

  3. 通俗易懂的信息熵与信息增益(IE, Information Entropy; IG, Information Gain)

    信息熵与信息增益(IE, Information Entropy; IG, Information Gain) 信息增益是机器学习中特征选择的关键指标,而学习信息增益前,需要先了解信息熵和条件熵这两个 ...

  4. 增益 Gain 分贝 dB

    https://zh.wikipedia.org/wiki/%E5%88%86%E8%B2%9D 分贝(decibel)是量度两个相同单位之数量比例的单位,主要用于度量声音强度,常用dB表示. “分” ...

  5. gain 基尼系数

    转至:http://blog.csdn.net/bitcarmanlee/article/details/51488204 在信息论与概率统计学中,熵(entropy)是一个很重要的概念.在机器学习与 ...

  6. 信息增益(Information Gain)(转)

    当我们需要对一个随机事件的概率分布进行预测时,我们的预测应当满足全部已知的条件,而对未知的情况不要做任何主观假设.在这种情况下,概率分布最均匀,预测的风险最小.因为这时概率分布的信息熵最大,所以称之为 ...

  7. xgboost 里边的gain freq, cover

    assuming that you're using xgboost to fit boosted trees for binary classification. The importance ma ...

  8. PS 图像调整— — gain and bias

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); Image=im ...

  9. Opencv— — Bias and Gain

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

随机推荐

  1. phpcms筛选功能

    phpcms论坛的看到的-----做筛选功能-----自定义函数 <?php /** * extention.func.php 用户自定义函数库 * * @copyright (C) 2005- ...

  2. hdu 4302 优先队列

    进一步学习了优先队列的用法 题意:一只小动物在直线上走,起始位置为零,之后会出现食物,动物要去距离自己最短的食物那,若两边的食物距离相等,则选择之前走的方向的食物 0 x,代表x的位置出现了食物,1代 ...

  3. hdu 4022 STL

    题意:给你n个敌人的坐标,再给你m个炸弹和爆炸方向,每个炸弹可以炸横排或竖排的敌人,问你每个炸弹能炸死多少个人. /* HDU 4022 G++ 1296ms */ #include<stdio ...

  4. 64位ubuntu安装32位jdk

    转自:http://blog.csdn.net/anladeyatou/article/details/8213334 ubuntu-11.10-desktop-amd64 jdk-6u23-linu ...

  5. Android常用布局

    FrameLayout(框架布局):从屏幕的左上角开始显示对象,一个覆盖一个,主要用于选项卡视图和图像切换器.# 所有的组件都放在屏幕的左上角,并且以层叠进行显示. LinearLayout(线性布局 ...

  6. matlab练习程序(矩形变换为单连通形状)

    变换使用的模板必须是单连通的,而且模板中心必须在模板内,如果在模板中打个结或是月牙形,这里的程序就处理不了了. 虽然非单连通模板也有办法处理,不过不是这里要讨论的. 这里用到的方法和矩形变换为圆那片文 ...

  7. 不自动生成Android Dependencies的解决方式

    今天遇到的奇怪问题是网上下载的demo导入第三方包运行后Android: NoClassDefFoundError的错误,原因是第三方的jar包并没有打包进apk里,运行是肯定要出错的. 网上百度了N ...

  8. 浅谈c++ new and delete or new [] and delete []

    http://www.cnblogs.com/hazir/p/new_and_delete.html 在 C++ 中,你也许经常使用 new 和 delete 来动态申请和释放内存,但你可曾想过以下问 ...

  9. hbase shell中log4j重复问题

    [root@centos ~]# hbase shellSLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding ...

  10. 暴力 hihoCoder 1251 Today Is a Rainy Day (15北京C)

    题目传送门 题意:一串数字变成另一串数字,可以单个数字转变,或者一类数字转变,问最少操作次数 分析:首先一类转换比单个转换优,先枚举找出最优的映射方案,然后将零碎的操作加上.6位6进制表示map映射, ...