Skip to content

Commit

Permalink
fix incorrect result of TIME type by distinguishing the processing of…
Browse files Browse the repository at this point in the history
… TIME type from other time types
  • Loading branch information
duanjr authored and mergify[bot] committed May 18, 2023
1 parent 9805e07 commit 6c11356
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 2 deletions.
67 changes: 67 additions & 0 deletions mysql-test/suite/tianmu/r/issue1175.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
DROP DATABASE IF EXISTS issue1175_test;
# Creating test database issue1175_test
CREATE DATABASE issue1175_test;
USE issue1175_test;
# Create test table with tianmu engine
CREATE TABLE t1 (
id INT AUTO_INCREMENT PRIMARY KEY,
t TIME,
d DATE,
dt DATETIME,
ts TIMESTAMP
) ENGINE=TIANMU;
# Insert data into test table
INSERT INTO t1 (t, d, dt, ts) VALUES
('00:00:00', '2000-01-01', '2000-01-01 00:00:00', '2000-01-01 00:00:00'),
('-838:59:59', '2001-02-28', '2001-02-28 00:00:00', '2001-02-28 00:00:00'),
('838:59:59', '2002-03-31', '2002-03-31 23:59:59', '2002-03-31 23:59:59'),
('-100:00:00', '2010-12-31', '2010-12-31 12:34:56', '2010-12-31 12:34:56'),
('200:00:00', '2011-11-30', '2011-11-30 18:00:00', '2011-11-30 18:00:00'),
('-400:00:00', '2012-02-29', '2012-02-29 01:23:45', '2012-02-29 01:23:45'),
('720:00:00', '2020-10-31', '2020-10-31 14:00:00', '2020-10-31 14:00:00'),
('05:30:15', '1985-04-12', '1985-04-12 05:30:15.123', '1985-04-12 05:30:15.123'),
('-23:45:01', '1995-08-24', '1995-08-24 15:45:30.987', '1995-08-24 15:45:30.987'),
('67:15:45', '2005-06-15', '2005-06-15 10:59:59.001', '2005-06-15 10:59:59.001'),
('-115:00:00', '2007-12-25', '2007-12-25 23:30:45.500', '2007-12-25 23:30:45.500'),
('350:30:15', '2015-09-05', '2015-09-05 12:00:00.999', '2015-09-05 12:00:00.999'),
('-500:45:30', '2017-03-01', '2017-03-01 01:23:45.250', '2017-03-01 01:23:45.250'),
('600:15:00', '2021-05-01', '2021-05-01 17:30:00.123', '2021-05-01 17:30:00.123'),
('12:34:56', '1970-01-01', '1970-01-01 12:34:56', '1970-01-01 12:34:56'),
('-300:00:00.123', '1980-06-30', '1980-06-30 18:30:45.123', '1980-06-30 18:30:45.123'),
('450:00:00', '1990-03-15', '1990-03-15 11:59:59.999', '1990-03-15 11:59:59.999'),
('-600:00:00.9', '1999-09-09', '1999-09-09 06:45:00.250', '1999-09-09 06:45:00.250'),
('-09:00:00', '2005-02-28', '2005-02-28 15:00:00.123', '2005-02-28 15:00:00.123'),
('-123:45:00', '2008-08-08', '2008-08-08 20:15:30.987', '2008-08-08 20:15:30.987'),
('99:00:00', '2013-07-07', '2013-07-07 17:30:45.500', '2013-07-07 17:30:45.500'),
('-220:00:00', '2016-04-30', '2016-04-30 02:00:00.999', '2016-04-30 02:00:00.999'),
('580:00:00', '2019-12-31', '2019-12-31 01:23:45.250', '2019-12-31 01:23:45.250'),
('-750:00:00', '2021-08-31', '2021-08-31 09:45:00.123', '2021-08-31 09:45:00.123');
# Select all data from test table
SELECT * FROM t1 ORDER BY id;
id t d dt ts
1 00:00:00 2000-01-01 2000-01-01 00:00:00 2000-01-01 00:00:00
2 -838:59:59 2001-02-28 2001-02-28 00:00:00 2001-02-28 00:00:00
3 838:59:59 2002-03-31 2002-03-31 23:59:59 2002-03-31 23:59:59
4 -100:00:00 2010-12-31 2010-12-31 12:34:56 2010-12-31 12:34:56
5 200:00:00 2011-11-30 2011-11-30 18:00:00 2011-11-30 18:00:00
6 -400:00:00 2012-02-29 2012-02-29 01:23:45 2012-02-29 01:23:45
7 720:00:00 2020-10-31 2020-10-31 14:00:00 2020-10-31 14:00:00
8 05:30:15 1985-04-12 1985-04-12 05:30:15 1985-04-12 05:30:15
9 -23:45:01 1995-08-24 1995-08-24 15:45:31 1995-08-24 15:45:31
10 67:15:45 2005-06-15 2005-06-15 10:59:59 2005-06-15 10:59:59
11 -115:00:00 2007-12-25 2007-12-25 23:30:46 2007-12-25 23:30:46
12 350:30:15 2015-09-05 2015-09-05 12:00:01 2015-09-05 12:00:01
13 -500:45:30 2017-03-01 2017-03-01 01:23:45 2017-03-01 01:23:45
14 600:15:00 2021-05-01 2021-05-01 17:30:00 2021-05-01 17:30:00
15 12:34:56 1970-01-01 1970-01-01 12:34:56 1970-01-01 12:34:56
16 -300:00:00 1980-06-30 1980-06-30 18:30:45 1980-06-30 18:30:45
17 450:00:00 1990-03-15 1990-03-15 12:00:00 1990-03-15 12:00:00
18 -600:00:01 1999-09-09 1999-09-09 06:45:00 1999-09-09 06:45:00
19 -09:00:00 2005-02-28 2005-02-28 15:00:00 2005-02-28 15:00:00
20 -123:45:00 2008-08-08 2008-08-08 20:15:31 2008-08-08 20:15:31
21 99:00:00 2013-07-07 2013-07-07 17:30:46 2013-07-07 17:30:46
22 -220:00:00 2016-04-30 2016-04-30 02:00:01 2016-04-30 02:00:01
23 580:00:00 2019-12-31 2019-12-31 01:23:45 2019-12-31 01:23:45
24 -750:00:00 2021-08-31 2021-08-31 09:45:00 2021-08-31 09:45:00
# Dropping test database issue1175_test
DROP DATABASE issue1175_test;
54 changes: 54 additions & 0 deletions mysql-test/suite/tianmu/t/issue1175.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS issue1175_test;
--enable_warnings

--echo # Creating test database issue1175_test
CREATE DATABASE issue1175_test;

USE issue1175_test;

--disable_warnings

--echo # Create test table with tianmu engine
CREATE TABLE t1 (
id INT AUTO_INCREMENT PRIMARY KEY,
t TIME,
d DATE,
dt DATETIME,
ts TIMESTAMP
) ENGINE=TIANMU;

--echo # Insert data into test table
INSERT INTO t1 (t, d, dt, ts) VALUES
('00:00:00', '2000-01-01', '2000-01-01 00:00:00', '2000-01-01 00:00:00'),
('-838:59:59', '2001-02-28', '2001-02-28 00:00:00', '2001-02-28 00:00:00'),
('838:59:59', '2002-03-31', '2002-03-31 23:59:59', '2002-03-31 23:59:59'),
('-100:00:00', '2010-12-31', '2010-12-31 12:34:56', '2010-12-31 12:34:56'),
('200:00:00', '2011-11-30', '2011-11-30 18:00:00', '2011-11-30 18:00:00'),
('-400:00:00', '2012-02-29', '2012-02-29 01:23:45', '2012-02-29 01:23:45'),
('720:00:00', '2020-10-31', '2020-10-31 14:00:00', '2020-10-31 14:00:00'),
('05:30:15', '1985-04-12', '1985-04-12 05:30:15.123', '1985-04-12 05:30:15.123'),
('-23:45:01', '1995-08-24', '1995-08-24 15:45:30.987', '1995-08-24 15:45:30.987'),
('67:15:45', '2005-06-15', '2005-06-15 10:59:59.001', '2005-06-15 10:59:59.001'),
('-115:00:00', '2007-12-25', '2007-12-25 23:30:45.500', '2007-12-25 23:30:45.500'),
('350:30:15', '2015-09-05', '2015-09-05 12:00:00.999', '2015-09-05 12:00:00.999'),
('-500:45:30', '2017-03-01', '2017-03-01 01:23:45.250', '2017-03-01 01:23:45.250'),
('600:15:00', '2021-05-01', '2021-05-01 17:30:00.123', '2021-05-01 17:30:00.123'),
('12:34:56', '1970-01-01', '1970-01-01 12:34:56', '1970-01-01 12:34:56'),
('-300:00:00.123', '1980-06-30', '1980-06-30 18:30:45.123', '1980-06-30 18:30:45.123'),
('450:00:00', '1990-03-15', '1990-03-15 11:59:59.999', '1990-03-15 11:59:59.999'),
('-600:00:00.9', '1999-09-09', '1999-09-09 06:45:00.250', '1999-09-09 06:45:00.250'),
('-09:00:00', '2005-02-28', '2005-02-28 15:00:00.123', '2005-02-28 15:00:00.123'),
('-123:45:00', '2008-08-08', '2008-08-08 20:15:30.987', '2008-08-08 20:15:30.987'),
('99:00:00', '2013-07-07', '2013-07-07 17:30:45.500', '2013-07-07 17:30:45.500'),
('-220:00:00', '2016-04-30', '2016-04-30 02:00:00.999', '2016-04-30 02:00:00.999'),
('580:00:00', '2019-12-31', '2019-12-31 01:23:45.250', '2019-12-31 01:23:45.250'),
('-750:00:00', '2021-08-31', '2021-08-31 09:45:00.123', '2021-08-31 09:45:00.123');

--echo # Select all data from test table
SELECT * FROM t1 ORDER BY id;

--echo # Dropping test database issue1175_test
DROP DATABASE issue1175_test;
27 changes: 25 additions & 2 deletions storage/tianmu/core/tianmu_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ void TianmuTable::GetValueFromField(Field *f, Value &v, size_t col) {
break;
}
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_TIME2:
case MYSQL_TYPE_TIME2: {
MYSQL_TIME my_time;
std::memset(&my_time, 0, sizeof(my_time));
f->get_time(&my_time);
types::DT dt = {};
dt.time_hour = my_time.hour;
dt.minute = my_time.minute;
dt.second = my_time.second;
dt.neg = my_time.neg;
v.SetInt(dt.val);
break;
}
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_NEWDATE:
Expand Down Expand Up @@ -879,7 +890,19 @@ void TianmuTable::Field2VC(Field *f, loader::ValueCache &vc, size_t col) {
vc.ExpectedSize(sizeof(int64_t));
} break;
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_TIME2:
case MYSQL_TYPE_TIME2: {
MYSQL_TIME my_time;
std::memset(&my_time, 0, sizeof(my_time));
f->get_time(&my_time);
types::DT dt = {};
dt.time_hour = my_time.hour;
dt.minute = my_time.minute;
dt.second = my_time.second;
dt.neg = my_time.neg;

*reinterpret_cast<int64_t *>(vc.Prepare(sizeof(int64_t))) = dt.val;
vc.ExpectedSize(sizeof(int64_t));
} break;
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_NEWDATE:
Expand Down

0 comments on commit 6c11356

Please sign in to comment.