N
N
nikitasius2015-11-04 13:00:40
MySQL
nikitasius, 2015-11-04 13:00:40

Is UNIX_TIMESTAMP fixed within an INSERT?

Is the value of unix_timestamp constant within one (albeit huge) insert?
I did a test:
table

CREATE TABLE `test_UNIX_TIMESTAMP` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `datefrom` INT(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
)

Further insert of the form:
insert into test_UNIX_TIMESTAMP (datefrom) values
(UNIX_TIMESTAMP())
,(UNIX_TIMESTAMP())
,(UNIX_TIMESTAMP())
....много много
,(UNIX_TIMESTAMP());

result: Affected rows: 106,400 Rows found: 0 Warnings: 0 Duration of 1 query: 20,062 sec.
20 seconds because the server is remote.
Then:
select distinct(datefrom) from test_UNIX_TIMESTAMP;

gave me only one result.
I decided that 100k was not enough, reset the table:
Affected rows: 1 170 400 Found rows: 0 Warnings: 0 Duration 1 query: 00:03:51
Further on a new one:
select distinct(datefrom) from test_UNIX_TIMESTAMP;

And only one result.
Based on my tests UNIX_TIMESTAMP is fixed. But at the same time, the server waited until it received the packet, and executed it, and the server is very powerful. Therefore, by inserting 1 million inserts, the fix of the UNIX_TIMESTAMP value cannot be proved.
Who can give some arguments based on documentation or excerpts (albeit from the same stackoverflow) that UNIX_TIMESTAMP is calculated only 1 time for an insert and then it is simply duplicated.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neol, 2015-11-04
@nikitasius

Functions that return the current date or time each are evaluated only once per query at the start of query execution. This means that multiple references to a function such as NOW() within a single query always produce the same result.

dev.mysql.com/doc/refman/5.5/en/date-and-time-func...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question