· 6 years ago · Jul 18, 2019, 08:52 PM
1# returns 0
2select count(*) as COUNT_WITH_INDEX
3from a
4where id = 1 and begin_time='2018-11-04 01:01:00.000';
5
6# returns 1
7select count(*) as COUNT_WITHOUT_INDEX
8from a ignore index (PRIMARY)
9where id = 1 and begin_time='2018-11-04 01:01:00.000';
10
11create database if not exists test_dt;
12use test_dt;
13
14drop table if exists a;
15
16CREATE TABLE `a` (
17 `id` int(11) NOT NULL,
18 `begin_time` timestamp(3) NOT NULL DEFAULT '0000-00-00 00:00:00.000',
19 PRIMARY KEY (`id`,`begin_time`)
20) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
21
22
23set TIME_ZONE='+0:00';
24
25insert into a values(1, '2018-11-04 06:01:00.000');
26insert into a values(1, '2018-11-04 07:01:00.000');
27
28set TIME_ZONE='US/Eastern';
29
30select * from a;
31
32# returns 0
33select count(*) as COUNT_WITH_INDEX
34from a
35where id = 1 and begin_time='2018-11-04 01:01:00.000';
36
37# returns 1
38select count(*) as COUNT_WITHOUT_INDEX
39from a ignore index (PRIMARY)
40where id = 1 and begin_time='2018-11-04 01:01:00.000';
41
42set TIME_ZONE='US/Central';
43# repeat w/ Central if you like