What is the underlying storage of timestamp after Mysql5.6?

found an interesting problem with timestamp after the mysql5.6 version, as follows:

mysql> desc test_idx;
+--------+--------------+------+-----+---------+----------------+
| Field  | Type         | Null | Key | Default | Extra          |
+--------+--------------+------+-----+---------+----------------+
| id     | int(11)      | NO   | PRI | NULL    | auto_increment |
| name   | varchar(255) | NO   |     | NULL    |                |
| sid    | int(11)      | NO   | UNI | NULL    |                |
| time_1 | timestamp(6) | YES  |     | NULL    |                |
| time_2 | timestamp(2) | YES  |     | NULL    |                |
| time_3 | timestamp(4) | YES  |     | NULL    |                |
| time_4 | timestamp    | YES  |     | NULL    |                |
+--------+--------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

mysql> select * from test_idx;
+----+------+-----+----------------------------+------------------------+--------------------------+---------------------+
| id | name | sid | time_1                     | time_2                 | time_3                   | time_4              |
+----+------+-----+----------------------------+------------------------+--------------------------+---------------------+
|  2 | zhao |   1 | 2018-09-20 20:39:59.000000 | 2018-09-20 20:40:05.00 | 2018-09-20 20:40:09.0000 | 2018-09-20 20:40:55 |
+----+------+-----+----------------------------+------------------------+--------------------------+---------------------+
1 row in set (0.00 sec)

problem description: when the length of timestamp is specified when the table is created (the maximum is 6), timestamp can keep the last 6 decimal places, which are described as microseconds according to the official document.

question: does it mean that after 5. 6, timestamp is accurate to microseconds, and then timestamp occupies 4 bytes, so how does the bottom store these 6 decimal places?

Oct.31,2021

clipboard.png

clipboard.png

for example, TIME (0), TIME (2), TIME (4), and TIME (6) uses 3, 4, 5, and 6 bytes respectively

Menu