From 6d036884221c4b43d5333f91fa8a6dd8303c457a Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Sat, 8 Jan 2005 05:32:47 +0100 Subject: [PATCH 1/7] Fix unportable 'tr' usage in libedit build process. (Bug #7669) --- cmd-line-utils/libedit/makelist.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd-line-utils/libedit/makelist.sh b/cmd-line-utils/libedit/makelist.sh index fbce06fcc50..b2502d16ed1 100644 --- a/cmd-line-utils/libedit/makelist.sh +++ b/cmd-line-utils/libedit/makelist.sh @@ -145,7 +145,7 @@ case $FLAG in # -fh) cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ - sort | tr '[a-z]' '[A-Z]' | $AWK ' + sort | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | $AWK ' BEGIN { printf("/* Automatically generated file, do not edit */\n"); printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); From 3e37933c7f366bd0e0e8d3893f38e1eef50fe74b Mon Sep 17 00:00:00 2001 From: "pekka@mysql.com" <> Date: Sat, 8 Jan 2005 13:59:57 +0100 Subject: [PATCH 2/7] ndb - wl-1442 bug#7725 datetime ordering --- mysql-test/t/ndb_index_ordered.test | 29 +++++++++++++++++++++++++++++ ndb/src/common/util/NdbSqlUtil.cpp | 24 ++++++++++-------------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/mysql-test/t/ndb_index_ordered.test b/mysql-test/t/ndb_index_ordered.test index 53177511bc6..c5d3a83a3ab 100644 --- a/mysql-test/t/ndb_index_ordered.test +++ b/mysql-test/t/ndb_index_ordered.test @@ -172,3 +172,32 @@ SELECT s.SubscrID,l.SbclID FROM test1 s left JOIN test2 l ON l.SbcrID=s.SubscrID WHERE s.UsrID=224 order by 1, 2; drop table test1; drop table test2; + +# bug#7424 + bug#7725 + +create table t1 ( + pk int primary key, + dt datetime not null, + da date not null, + ye year not null, + ti time not null, + ts timestamp not null, + index(dt), + index(da), + index(ye), + index(ti), + index(ts) +) engine=ndb; + +insert into t1 (pk,dt,da,ye,ti) values + (1, '1901-05-05 23:00:59', '1901-05-05', '1901', '23:00:59'), + (2, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00'), + (3, '1999-06-06 06:06:06', '1999-06-06', '1999', '06:06:06'), + (4, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11'), + (5, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59'); + +# datetime +select count(*) from t1 use index (dt) where dt > '1900-01-01 00:00:00'; +select count(*) from t1 use index (dt) where dt > '1955-12-31 00:00:00'; +select count(*) from t1 use index (dt) where dt < '2001-01-01 10:11:11'; +select count(*) from t1 use index (dt) where dt < '2001-01-01 10:11:12'; diff --git a/ndb/src/common/util/NdbSqlUtil.cpp b/ndb/src/common/util/NdbSqlUtil.cpp index 5b2381df50a..8491fa3c4a0 100644 --- a/ndb/src/common/util/NdbSqlUtil.cpp +++ b/ndb/src/common/util/NdbSqlUtil.cpp @@ -469,21 +469,17 @@ int NdbSqlUtil::cmpDatetime(const void* info, const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size) { assert(full >= size && size > 0); - /* - * Datetime is CC YY MM DD hh mm ss \0 - * - * Not used via MySQL. - */ - union { const Uint32* p; const unsigned char* v; } u1, u2; - u1.p = p1; - u2.p = p2; - // no format check - int k = memcmp(u1.v, u2.v, 4); - if (k != 0) - return k < 0 ? -1 : +1; if (size >= 2) { - k = memcmp(u1.v + 4, u2.v + 4, 4); - return k < 0 ? -1 : k > 0 ? +1 : 0; + union { Uint32 p[2]; Int64 v; } u1, u2; + u1.p[0] = p1[0]; + u1.p[1] = p1[1]; + u2.p[0] = p2[0]; + u2.p[1] = p2[1]; + if (u1.v < u2.v) + return -1; + if (u1.v > u2.v) + return +1; + return 0; } return CmpUnknown; } From 7ef7580bb738cd7ef5c3240c9f74c68e7cd99172 Mon Sep 17 00:00:00 2001 From: "pekka@mysql.com" <> Date: Sat, 8 Jan 2005 15:18:24 +0100 Subject: [PATCH 3/7] ndb - wl-1442 updated ndb_index_ordered.result --- mysql-test/r/ndb_index_ordered.result | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/mysql-test/r/ndb_index_ordered.result b/mysql-test/r/ndb_index_ordered.result index 50f904af750..a3eb5630131 100644 --- a/mysql-test/r/ndb_index_ordered.result +++ b/mysql-test/r/ndb_index_ordered.result @@ -310,3 +310,34 @@ SubscrID SbclID 3 NULL drop table test1; drop table test2; +create table t1 ( +pk int primary key, +dt datetime not null, +da date not null, +ye year not null, +ti time not null, +ts timestamp not null, +index(dt), +index(da), +index(ye), +index(ti), +index(ts) +) engine=ndb; +insert into t1 (pk,dt,da,ye,ti) values +(1, '1901-05-05 23:00:59', '1901-05-05', '1901', '23:00:59'), +(2, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00'), +(3, '1999-06-06 06:06:06', '1999-06-06', '1999', '06:06:06'), +(4, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11'), +(5, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59'); +select count(*) from t1 use index (dt) where dt > '1900-01-01 00:00:00'; +count(*) +5 +select count(*) from t1 use index (dt) where dt > '1955-12-31 00:00:00'; +count(*) +3 +select count(*) from t1 use index (dt) where dt < '2001-01-01 10:11:11'; +count(*) +3 +select count(*) from t1 use index (dt) where dt < '2001-01-01 10:11:12'; +count(*) +4 From 0462ccfe3c5f22ac4f79dbe5f7cf827603ef422d Mon Sep 17 00:00:00 2001 From: "pekka@mysql.com" <> Date: Sat, 8 Jan 2005 16:57:51 +0100 Subject: [PATCH 4/7] ndb - wl-1442 fix Date ordering --- mysql-test/r/ndb_index_ordered.result | 66 ++++++++++++++----- mysql-test/t/ndb_index_ordered.test | 32 ++++++--- ndb/include/kernel/signaldata/DictTabInfo.hpp | 6 +- ndb/include/ndbapi/NdbDictionary.hpp | 2 +- ndb/include/util/NdbSqlUtil.hpp | 4 +- ndb/src/common/util/NdbSqlUtil.cpp | 52 +++++++-------- ndb/src/ndbapi/NdbDictionary.cpp | 4 +- ndb/src/ndbapi/NdbDictionaryImpl.cpp | 4 +- ndb/test/include/NdbSchemaOp.hpp | 2 +- ndb/tools/restore/consumer.cpp | 4 +- sql/ha_ndbcluster.cc | 9 ++- 11 files changed, 118 insertions(+), 67 deletions(-) diff --git a/mysql-test/r/ndb_index_ordered.result b/mysql-test/r/ndb_index_ordered.result index a3eb5630131..466523aafa7 100644 --- a/mysql-test/r/ndb_index_ordered.result +++ b/mysql-test/r/ndb_index_ordered.result @@ -325,19 +325,53 @@ index(ts) ) engine=ndb; insert into t1 (pk,dt,da,ye,ti) values (1, '1901-05-05 23:00:59', '1901-05-05', '1901', '23:00:59'), -(2, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00'), -(3, '1999-06-06 06:06:06', '1999-06-06', '1999', '06:06:06'), -(4, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11'), -(5, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59'); -select count(*) from t1 use index (dt) where dt > '1900-01-01 00:00:00'; -count(*) -5 -select count(*) from t1 use index (dt) where dt > '1955-12-31 00:00:00'; -count(*) -3 -select count(*) from t1 use index (dt) where dt < '2001-01-01 10:11:11'; -count(*) -3 -select count(*) from t1 use index (dt) where dt < '2001-01-01 10:11:12'; -count(*) -4 +(2, '1912-09-05 13:00:59', '1912-09-05', '1912', '13:00:59'), +(3, '1945-12-31 00:00:00', '1945-12-31', '1945', '00:00:00'), +(4, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00'), +(5, '1963-06-06 06:06:06', '1963-06-06', '1963', '06:06:06'), +(6, '1993-06-06 06:06:06', '1993-06-06', '1993', '06:06:06'), +(7, '2001-01-01 10:11:10', '2001-01-01', '2001', '10:11:10'), +(8, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11'), +(9, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59'); +select count(*)-9 from t1 use index (dt) where dt > '1900-01-01 00:00:00'; +count(*)-9 +0 +select count(*)-6 from t1 use index (dt) where dt >= '1955-12-31 00:00:00'; +count(*)-6 +0 +select count(*)-5 from t1 use index (dt) where dt > '1955-12-31 00:00:00'; +count(*)-5 +0 +select count(*)-5 from t1 use index (dt) where dt < '1970-03-03 22:22:22'; +count(*)-5 +0 +select count(*)-7 from t1 use index (dt) where dt < '2001-01-01 10:11:11'; +count(*)-7 +0 +select count(*)-8 from t1 use index (dt) where dt <= '2001-01-01 10:11:11'; +count(*)-8 +0 +select count(*)-9 from t1 use index (dt) where dt <= '2055-01-01 00:00:00'; +count(*)-9 +0 +select count(*)-9 from t1 use index (da) where da > '1900-01-01'; +count(*)-9 +0 +select count(*)-6 from t1 use index (da) where da >= '1955-12-31'; +count(*)-6 +0 +select count(*)-5 from t1 use index (da) where da > '1955-12-31'; +count(*)-5 +0 +select count(*)-5 from t1 use index (da) where da < '1970-03-03'; +count(*)-5 +0 +select count(*)-6 from t1 use index (da) where da < '2001-01-01'; +count(*)-6 +0 +select count(*)-8 from t1 use index (da) where da <= '2001-01-02'; +count(*)-8 +0 +select count(*)-9 from t1 use index (da) where da <= '2055-01-01'; +count(*)-9 +0 diff --git a/mysql-test/t/ndb_index_ordered.test b/mysql-test/t/ndb_index_ordered.test index c5d3a83a3ab..ae2f7db53fb 100644 --- a/mysql-test/t/ndb_index_ordered.test +++ b/mysql-test/t/ndb_index_ordered.test @@ -191,13 +191,29 @@ create table t1 ( insert into t1 (pk,dt,da,ye,ti) values (1, '1901-05-05 23:00:59', '1901-05-05', '1901', '23:00:59'), - (2, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00'), - (3, '1999-06-06 06:06:06', '1999-06-06', '1999', '06:06:06'), - (4, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11'), - (5, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59'); + (2, '1912-09-05 13:00:59', '1912-09-05', '1912', '13:00:59'), + (3, '1945-12-31 00:00:00', '1945-12-31', '1945', '00:00:00'), + (4, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00'), + (5, '1963-06-06 06:06:06', '1963-06-06', '1963', '06:06:06'), + (6, '1993-06-06 06:06:06', '1993-06-06', '1993', '06:06:06'), + (7, '2001-01-01 10:11:10', '2001-01-01', '2001', '10:11:10'), + (8, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11'), + (9, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59'); # datetime -select count(*) from t1 use index (dt) where dt > '1900-01-01 00:00:00'; -select count(*) from t1 use index (dt) where dt > '1955-12-31 00:00:00'; -select count(*) from t1 use index (dt) where dt < '2001-01-01 10:11:11'; -select count(*) from t1 use index (dt) where dt < '2001-01-01 10:11:12'; +select count(*)-9 from t1 use index (dt) where dt > '1900-01-01 00:00:00'; +select count(*)-6 from t1 use index (dt) where dt >= '1955-12-31 00:00:00'; +select count(*)-5 from t1 use index (dt) where dt > '1955-12-31 00:00:00'; +select count(*)-5 from t1 use index (dt) where dt < '1970-03-03 22:22:22'; +select count(*)-7 from t1 use index (dt) where dt < '2001-01-01 10:11:11'; +select count(*)-8 from t1 use index (dt) where dt <= '2001-01-01 10:11:11'; +select count(*)-9 from t1 use index (dt) where dt <= '2055-01-01 00:00:00'; + +# date +select count(*)-9 from t1 use index (da) where da > '1900-01-01'; +select count(*)-6 from t1 use index (da) where da >= '1955-12-31'; +select count(*)-5 from t1 use index (da) where da > '1955-12-31'; +select count(*)-5 from t1 use index (da) where da < '1970-03-03'; +select count(*)-6 from t1 use index (da) where da < '2001-01-01'; +select count(*)-8 from t1 use index (da) where da <= '2001-01-02'; +select count(*)-9 from t1 use index (da) where da <= '2055-01-01'; diff --git a/ndb/include/kernel/signaldata/DictTabInfo.hpp b/ndb/include/kernel/signaldata/DictTabInfo.hpp index ae78c023c2a..392b691ae1e 100644 --- a/ndb/include/kernel/signaldata/DictTabInfo.hpp +++ b/ndb/include/kernel/signaldata/DictTabInfo.hpp @@ -308,7 +308,7 @@ public: ExtBinary = NdbSqlUtil::Type::Binary, ExtVarbinary = NdbSqlUtil::Type::Varbinary, ExtDatetime = NdbSqlUtil::Type::Datetime, - ExtTimespec = NdbSqlUtil::Type::Timespec, + ExtDate = NdbSqlUtil::Type::Date, ExtBlob = NdbSqlUtil::Type::Blob, ExtText = NdbSqlUtil::Type::Text }; @@ -428,10 +428,10 @@ public: AttributeSize = DictTabInfo::an8Bit; AttributeArraySize = 8 * AttributeExtLength; return true; - case DictTabInfo::ExtTimespec: + case DictTabInfo::ExtDate: AttributeType = DictTabInfo::StringType; AttributeSize = DictTabInfo::an8Bit; - AttributeArraySize = 12 * AttributeExtLength; + AttributeArraySize = 3 * AttributeExtLength; return true; case DictTabInfo::ExtBlob: case DictTabInfo::ExtText: diff --git a/ndb/include/ndbapi/NdbDictionary.hpp b/ndb/include/ndbapi/NdbDictionary.hpp index f0c8a10f488..0ca3744a3d9 100644 --- a/ndb/include/ndbapi/NdbDictionary.hpp +++ b/ndb/include/ndbapi/NdbDictionary.hpp @@ -185,7 +185,7 @@ public: Binary, ///< Len Varbinary, ///< Max len Datetime, ///< Precision down to 1 sec (sizeof(Datetime) == 8 bytes ) - Timespec, ///< Precision down to 1 nsec(sizeof(Datetime) == 12 bytes ) + Date, ///< Precision down to 1 day(sizeof(Date) == 4 bytes ) Blob, ///< Binary large object (see NdbBlob) Text ///< Text blob }; diff --git a/ndb/include/util/NdbSqlUtil.hpp b/ndb/include/util/NdbSqlUtil.hpp index 3062d1e4e1b..47bb2157e1a 100644 --- a/ndb/include/util/NdbSqlUtil.hpp +++ b/ndb/include/util/NdbSqlUtil.hpp @@ -81,7 +81,7 @@ public: Binary, // Len Varbinary, // Max len Datetime, // Precision down to 1 sec (size 8 bytes) - Timespec, // Precision down to 1 nsec (size 12 bytes) + Date, // Precision down to 1 day (size 4 bytes) Blob, // Blob Text // Text blob }; @@ -132,7 +132,7 @@ private: static Cmp cmpBinary; static Cmp cmpVarbinary; static Cmp cmpDatetime; - static Cmp cmpTimespec; + static Cmp cmpDate; static Cmp cmpBlob; static Cmp cmpText; }; diff --git a/ndb/src/common/util/NdbSqlUtil.cpp b/ndb/src/common/util/NdbSqlUtil.cpp index 8491fa3c4a0..6f490c7f611 100644 --- a/ndb/src/common/util/NdbSqlUtil.cpp +++ b/ndb/src/common/util/NdbSqlUtil.cpp @@ -153,8 +153,8 @@ NdbSqlUtil::m_typeList[] = { cmpDatetime }, { - Type::Timespec, - cmpTimespec + Type::Date, + cmpDate }, { Type::Blob, @@ -485,36 +485,34 @@ NdbSqlUtil::cmpDatetime(const void* info, const Uint32* p1, const Uint32* p2, Ui } int -NdbSqlUtil::cmpTimespec(const void* info, const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size) +NdbSqlUtil::cmpDate(const void* info, const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size) { +#ifdef ndb_date_is_4_byte_native_int + assert(full >= size && size > 0); + union { Uint32 p[2]; Int32 v; } u1, u2; + u1.p[0] = p1[0]; + u2.p[0] = p2[0]; + if (u1.v < u2.v) + return -1; + if (u1.v > u2.v) + return +1; + return 0; +#else assert(full >= size && size > 0); - /* - * Timespec is CC YY MM DD hh mm ss \0 NN NN NN NN - * - * Not used via MySQL. - */ union { const Uint32* p; const unsigned char* v; } u1, u2; u1.p = p1; u2.p = p2; - // no format check - int k = memcmp(u1.v, u2.v, 4); - if (k != 0) - return k < 0 ? -1 : +1; - if (size >= 2) { - k = memcmp(u1.v + 4, u2.v + 4, 4); - if (k != 0) - return k < 0 ? -1 : +1; - if (size >= 3) { - Uint32 n1 = *(const Uint32*)(u1.v + 8); - Uint32 n2 = *(const Uint32*)(u2.v + 8); - if (n1 < n2) - return -1; - if (n2 > n1) - return +1; - return 0; - } - } - return CmpUnknown; + // from Field_newdate::val_int + Uint64 j1 = uint3korr(u1.v); + Uint64 j2 = uint3korr(u2.v); + j1 = (j1 % 32L)+(j1 / 32L % 16L)*100L + (j1/(16L*32L))*10000L; + j2 = (j2 % 32L)+(j2 / 32L % 16L)*100L + (j2/(16L*32L))*10000L; + if (j1 < j2) + return -1; + if (j1 > j2) + return +1; + return 0; +#endif } int diff --git a/ndb/src/ndbapi/NdbDictionary.cpp b/ndb/src/ndbapi/NdbDictionary.cpp index f88bbc907a6..b47f7d2c15c 100644 --- a/ndb/src/ndbapi/NdbDictionary.cpp +++ b/ndb/src/ndbapi/NdbDictionary.cpp @@ -936,8 +936,8 @@ operator<<(NdbOut& out, const NdbDictionary::Column& col) case NdbDictionary::Column::Datetime: out << "Datetime"; break; - case NdbDictionary::Column::Timespec: - out << "Timespec"; + case NdbDictionary::Column::Date: + out << "Date"; break; case NdbDictionary::Column::Blob: out << "Blob(" << col.getInlineSize() << "," << col.getPartSize() diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/ndb/src/ndbapi/NdbDictionaryImpl.cpp index 7a293463c94..195fdce7e3f 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -130,7 +130,7 @@ NdbColumnImpl::init(Type t) case Binary: case Varbinary: case Datetime: - case Timespec: + case Date: m_precision = 0; m_scale = 0; m_length = 1; @@ -1174,7 +1174,7 @@ columnTypeMapping[] = { { DictTabInfo::ExtBinary, NdbDictionary::Column::Binary }, { DictTabInfo::ExtVarbinary, NdbDictionary::Column::Varbinary }, { DictTabInfo::ExtDatetime, NdbDictionary::Column::Datetime }, - { DictTabInfo::ExtTimespec, NdbDictionary::Column::Timespec }, + { DictTabInfo::ExtDate, NdbDictionary::Column::Date }, { DictTabInfo::ExtBlob, NdbDictionary::Column::Blob }, { DictTabInfo::ExtText, NdbDictionary::Column::Text }, { -1, -1 } diff --git a/ndb/test/include/NdbSchemaOp.hpp b/ndb/test/include/NdbSchemaOp.hpp index ac859f8abe8..b54c011ae8b 100644 --- a/ndb/test/include/NdbSchemaOp.hpp +++ b/ndb/test/include/NdbSchemaOp.hpp @@ -576,7 +576,7 @@ convertColumnTypeToAttrType(NdbDictionary::Column::Type _type) case NdbDictionary::Column::Varbinary: return String; case NdbDictionary::Column::Datetime: - case NdbDictionary::Column::Timespec: + case NdbDictionary::Column::Date: case NdbDictionary::Column::Undefined: default: return NoAttrTypeDef; diff --git a/ndb/tools/restore/consumer.cpp b/ndb/tools/restore/consumer.cpp index e94c31b2666..dc0567803dd 100644 --- a/ndb/tools/restore/consumer.cpp +++ b/ndb/tools/restore/consumer.cpp @@ -71,8 +71,8 @@ BackupConsumer::create_table_string(const TableS & table, case NdbDictionary::Column::Datetime: pos += sprintf(buf+pos, "%s", "datetime"); break; - case NdbDictionary::Column::Timespec: - pos += sprintf(buf+pos, "%s", "time"); + case NdbDictionary::Column::Date: + pos += sprintf(buf+pos, "%s", "date"); break; case NdbDictionary::Column::Undefined: // pos += sprintf(buf+pos, "%s", "varchar binary"); diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 3c6cd83d5dc..e181b421e29 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -2259,9 +2259,9 @@ void ha_ndbcluster::print_results() fprintf(DBUG_FILE, "Datetime\t%llu", value); break; } - case NdbDictionary::Column::Timespec: { + case NdbDictionary::Column::Date: { Uint64 value= (Uint64) *field->ptr; - fprintf(DBUG_FILE, "Timespec\t%llu", value); + fprintf(DBUG_FILE, "Date\t%llu", value); break; } case NdbDictionary::Column::Blob: { @@ -3323,8 +3323,11 @@ static int create_ndb_column(NDBCOL &col, col.setType(NDBCOL::Datetime); col.setLength(1); break; - case MYSQL_TYPE_DATE: case MYSQL_TYPE_NEWDATE: + col.setType(NDBCOL::Date); + col.setLength(1); + break; + case MYSQL_TYPE_DATE: // ? case MYSQL_TYPE_TIME: case MYSQL_TYPE_YEAR: col.setType(NDBCOL::Char); From 50c3a883b2a414e2657cb7e5c47277f99977d37e Mon Sep 17 00:00:00 2001 From: "pekka@mysql.com" <> Date: Sat, 8 Jan 2005 19:28:44 +0100 Subject: [PATCH 5/7] ndb - wl-1442 fix Time ordering --- mysql-test/r/ndb_index_ordered.result | 45 +++++++++++++++++++ mysql-test/t/ndb_index_ordered.test | 19 ++++++++ ndb/include/kernel/signaldata/DictTabInfo.hpp | 8 +++- ndb/include/ndbapi/NdbDictionary.hpp | 3 +- ndb/include/util/NdbSqlUtil.hpp | 4 +- ndb/src/common/util/NdbSqlUtil.cpp | 33 ++++++++++++++ ndb/src/ndbapi/NdbDictionary.cpp | 3 ++ ndb/src/ndbapi/NdbDictionaryImpl.cpp | 7 +++ ndb/test/include/NdbSchemaOp.hpp | 1 + ndb/tools/restore/consumer.cpp | 3 ++ sql/ha_ndbcluster.cc | 10 ++++- 11 files changed, 132 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/ndb_index_ordered.result b/mysql-test/r/ndb_index_ordered.result index 466523aafa7..75a5e42732b 100644 --- a/mysql-test/r/ndb_index_ordered.result +++ b/mysql-test/r/ndb_index_ordered.result @@ -375,3 +375,48 @@ count(*)-8 select count(*)-9 from t1 use index (da) where da <= '2055-01-01'; count(*)-9 0 +select count(*)-9 from t1 use index (ye) where ye > '1900'; +count(*)-9 +0 +select count(*)-6 from t1 use index (ye) where ye >= '1955'; +count(*)-6 +0 +select count(*)-5 from t1 use index (ye) where ye > '1955'; +count(*)-5 +0 +select count(*)-5 from t1 use index (ye) where ye < '1970'; +count(*)-5 +0 +select count(*)-6 from t1 use index (ye) where ye < '2001'; +count(*)-6 +0 +select count(*)-8 from t1 use index (ye) where ye <= '2001'; +count(*)-8 +0 +select count(*)-9 from t1 use index (ye) where ye <= '2055'; +count(*)-9 +0 +select count(*)-9 from t1 use index (ti) where ti >= '00:00:00'; +count(*)-9 +0 +select count(*)-7 from t1 use index (ti) where ti > '00:00:00'; +count(*)-7 +0 +select count(*)-7 from t1 use index (ti) where ti > '05:05:05'; +count(*)-7 +0 +select count(*)-5 from t1 use index (ti) where ti > '06:06:06'; +count(*)-5 +0 +select count(*)-5 from t1 use index (ti) where ti < '10:11:11'; +count(*)-5 +0 +select count(*)-6 from t1 use index (ti) where ti <= '10:11:11'; +count(*)-6 +0 +select count(*)-8 from t1 use index (ti) where ti < '23:59:59'; +count(*)-8 +0 +select count(*)-9 from t1 use index (ti) where ti <= '23:59:59'; +count(*)-9 +0 diff --git a/mysql-test/t/ndb_index_ordered.test b/mysql-test/t/ndb_index_ordered.test index ae2f7db53fb..71635159604 100644 --- a/mysql-test/t/ndb_index_ordered.test +++ b/mysql-test/t/ndb_index_ordered.test @@ -217,3 +217,22 @@ select count(*)-5 from t1 use index (da) where da < '1970-03-03'; select count(*)-6 from t1 use index (da) where da < '2001-01-01'; select count(*)-8 from t1 use index (da) where da <= '2001-01-02'; select count(*)-9 from t1 use index (da) where da <= '2055-01-01'; + +# year +select count(*)-9 from t1 use index (ye) where ye > '1900'; +select count(*)-6 from t1 use index (ye) where ye >= '1955'; +select count(*)-5 from t1 use index (ye) where ye > '1955'; +select count(*)-5 from t1 use index (ye) where ye < '1970'; +select count(*)-6 from t1 use index (ye) where ye < '2001'; +select count(*)-8 from t1 use index (ye) where ye <= '2001'; +select count(*)-9 from t1 use index (ye) where ye <= '2055'; + +# time +select count(*)-9 from t1 use index (ti) where ti >= '00:00:00'; +select count(*)-7 from t1 use index (ti) where ti > '00:00:00'; +select count(*)-7 from t1 use index (ti) where ti > '05:05:05'; +select count(*)-5 from t1 use index (ti) where ti > '06:06:06'; +select count(*)-5 from t1 use index (ti) where ti < '10:11:11'; +select count(*)-6 from t1 use index (ti) where ti <= '10:11:11'; +select count(*)-8 from t1 use index (ti) where ti < '23:59:59'; +select count(*)-9 from t1 use index (ti) where ti <= '23:59:59'; diff --git a/ndb/include/kernel/signaldata/DictTabInfo.hpp b/ndb/include/kernel/signaldata/DictTabInfo.hpp index 392b691ae1e..3e73ae67ebe 100644 --- a/ndb/include/kernel/signaldata/DictTabInfo.hpp +++ b/ndb/include/kernel/signaldata/DictTabInfo.hpp @@ -310,7 +310,8 @@ public: ExtDatetime = NdbSqlUtil::Type::Datetime, ExtDate = NdbSqlUtil::Type::Date, ExtBlob = NdbSqlUtil::Type::Blob, - ExtText = NdbSqlUtil::Type::Text + ExtText = NdbSqlUtil::Type::Text, + ExtTime = NdbSqlUtil::Type::Time }; // Attribute data interpretation @@ -440,6 +441,11 @@ public: // head + inline part [ attr precision lower half ] AttributeArraySize = (NDB_BLOB_HEAD_SIZE << 2) + (AttributeExtPrecision & 0xFFFF); return true; + case DictTabInfo::ExtTime: + AttributeType = DictTabInfo::StringType; + AttributeSize = DictTabInfo::an8Bit; + AttributeArraySize = 3 * AttributeExtLength; + return true; }; return false; } diff --git a/ndb/include/ndbapi/NdbDictionary.hpp b/ndb/include/ndbapi/NdbDictionary.hpp index 0ca3744a3d9..454b267d1b0 100644 --- a/ndb/include/ndbapi/NdbDictionary.hpp +++ b/ndb/include/ndbapi/NdbDictionary.hpp @@ -187,7 +187,8 @@ public: Datetime, ///< Precision down to 1 sec (sizeof(Datetime) == 8 bytes ) Date, ///< Precision down to 1 day(sizeof(Date) == 4 bytes ) Blob, ///< Binary large object (see NdbBlob) - Text ///< Text blob + Text, ///< Text blob + Time = 25 ///< Time without date }; /** diff --git a/ndb/include/util/NdbSqlUtil.hpp b/ndb/include/util/NdbSqlUtil.hpp index 47bb2157e1a..10024d9b616 100644 --- a/ndb/include/util/NdbSqlUtil.hpp +++ b/ndb/include/util/NdbSqlUtil.hpp @@ -83,7 +83,8 @@ public: Datetime, // Precision down to 1 sec (size 8 bytes) Date, // Precision down to 1 day (size 4 bytes) Blob, // Blob - Text // Text blob + Text, // Text blob + Time = 25 // Time without date }; Enum m_typeId; Cmp* m_cmp; // comparison method @@ -135,6 +136,7 @@ private: static Cmp cmpDate; static Cmp cmpBlob; static Cmp cmpText; + static Cmp cmpTime; }; #endif diff --git a/ndb/src/common/util/NdbSqlUtil.cpp b/ndb/src/common/util/NdbSqlUtil.cpp index 6f490c7f611..233698ae52b 100644 --- a/ndb/src/common/util/NdbSqlUtil.cpp +++ b/ndb/src/common/util/NdbSqlUtil.cpp @@ -163,6 +163,22 @@ NdbSqlUtil::m_typeList[] = { { Type::Text, cmpText + }, + { + Type::Undefined, // 5.0 Bit + NULL + }, + { + Type::Undefined, // 5.0 Longvarchar + NULL + }, + { + Type::Undefined, // 5.0 Longvarbinary + NULL + }, + { + Type::Time, + cmpTime } }; @@ -559,6 +575,23 @@ NdbSqlUtil::cmpText(const void* info, const Uint32* p1, const Uint32* p2, Uint32 return CmpUnknown; } +int +NdbSqlUtil::cmpTime(const void* info, const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size) +{ + assert(full >= size && size > 0); + union { const Uint32* p; const unsigned char* v; } u1, u2; + u1.p = p1; + u2.p = p2; + // from Field_time::val_int + Int32 j1 = sint3korr(u1.v); + Int32 j2 = sint3korr(u2.v); + if (j1 < j2) + return -1; + if (j1 > j2) + return +1; + return 0; +} + // check charset bool diff --git a/ndb/src/ndbapi/NdbDictionary.cpp b/ndb/src/ndbapi/NdbDictionary.cpp index b47f7d2c15c..0508d8bf277 100644 --- a/ndb/src/ndbapi/NdbDictionary.cpp +++ b/ndb/src/ndbapi/NdbDictionary.cpp @@ -947,6 +947,9 @@ operator<<(NdbOut& out, const NdbDictionary::Column& col) out << "Text(" << col.getInlineSize() << "," << col.getPartSize() << ";" << col.getStripeSize() << ";" << csname << ")"; break; + case NdbDictionary::Column::Time: + out << "Time"; + break; case NdbDictionary::Column::Undefined: out << "Undefined"; break; diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/ndb/src/ndbapi/NdbDictionaryImpl.cpp index 195fdce7e3f..59474943f3b 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -148,6 +148,12 @@ NdbColumnImpl::init(Type t) m_length = 4; m_cs = default_cs; break; + case Time: + m_precision = 0; + m_scale = 0; + m_length = 1; + m_cs = NULL; + break; case Undefined: assert(false); break; @@ -1177,6 +1183,7 @@ columnTypeMapping[] = { { DictTabInfo::ExtDate, NdbDictionary::Column::Date }, { DictTabInfo::ExtBlob, NdbDictionary::Column::Blob }, { DictTabInfo::ExtText, NdbDictionary::Column::Text }, + { DictTabInfo::ExtTime, NdbDictionary::Column::Time }, { -1, -1 } }; diff --git a/ndb/test/include/NdbSchemaOp.hpp b/ndb/test/include/NdbSchemaOp.hpp index b54c011ae8b..e2fb4015b88 100644 --- a/ndb/test/include/NdbSchemaOp.hpp +++ b/ndb/test/include/NdbSchemaOp.hpp @@ -577,6 +577,7 @@ convertColumnTypeToAttrType(NdbDictionary::Column::Type _type) return String; case NdbDictionary::Column::Datetime: case NdbDictionary::Column::Date: + case NdbDictionary::Column::Time: case NdbDictionary::Column::Undefined: default: return NoAttrTypeDef; diff --git a/ndb/tools/restore/consumer.cpp b/ndb/tools/restore/consumer.cpp index dc0567803dd..4d228230423 100644 --- a/ndb/tools/restore/consumer.cpp +++ b/ndb/tools/restore/consumer.cpp @@ -74,6 +74,9 @@ BackupConsumer::create_table_string(const TableS & table, case NdbDictionary::Column::Date: pos += sprintf(buf+pos, "%s", "date"); break; + case NdbDictionary::Column::Time: + pos += sprintf(buf+pos, "%s", "time"); + break; case NdbDictionary::Column::Undefined: // pos += sprintf(buf+pos, "%s", "varchar binary"); return -1; diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index e181b421e29..e4c45490050 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -2264,6 +2264,11 @@ void ha_ndbcluster::print_results() fprintf(DBUG_FILE, "Date\t%llu", value); break; } + case NdbDictionary::Column::Time: { + Uint64 value= (Uint64) *field->ptr; + fprintf(DBUG_FILE, "Time\t%llu", value); + break; + } case NdbDictionary::Column::Blob: { Uint64 len= 0; ndb_blob->getLength(len); @@ -3327,8 +3332,11 @@ static int create_ndb_column(NDBCOL &col, col.setType(NDBCOL::Date); col.setLength(1); break; - case MYSQL_TYPE_DATE: // ? case MYSQL_TYPE_TIME: + col.setType(NDBCOL::Time); + col.setLength(1); + break; + case MYSQL_TYPE_DATE: // ? case MYSQL_TYPE_YEAR: col.setType(NDBCOL::Char); col.setLength(field->pack_length()); From 247052fecccae6672bfd26bbfeec53d77340e322 Mon Sep 17 00:00:00 2001 From: "serg@sergbook.mylan" <> Date: Sat, 8 Jan 2005 21:25:31 +0100 Subject: [PATCH 6/7] few harmless warnings from automated code-checking tools fixed --- client/completion_hash.cc | 3 ++- client/mysql.cc | 9 ++++++--- cmd-line-utils/libedit/parse.c | 3 ++- pstack/pstack.c | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/client/completion_hash.cc b/client/completion_hash.cc index 536e7f9373a..7a3b363c93c 100644 --- a/client/completion_hash.cc +++ b/client/completion_hash.cc @@ -79,7 +79,8 @@ int completion_hash_update(HashTable *ht, char *arKey, uint nKeyLength, if (!memcmp(p->arKey, arKey, nKeyLength)) { entry *n; - n = (entry *) alloc_root(&ht->mem_root,sizeof(entry)); + if (!(n = (entry *) alloc_root(&ht->mem_root,sizeof(entry)))) + return FAILURE; n->pNext = p->pData; n->str = str; p->pData = n; diff --git a/client/mysql.cc b/client/mysql.cc index 0ea0f10f5d7..bfa827a6e95 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1502,7 +1502,10 @@ You can turn off this feature to get a quicker startup with -A\n\n"); if (!(field_names[i] = (char **) alloc_root(&hash_mem_root, sizeof(char *) * (num_fields*2+1)))) - break; + { + mysql_free_result(fields); + break; + } field_names[i][num_fields*2]= '\0'; j=0; while ((sql_field=mysql_fetch_field(fields))) @@ -2077,10 +2080,10 @@ print_table_data_html(MYSQL_RES *result) } while ((cur = mysql_fetch_row(result))) { + ulong *lengths=mysql_fetch_lengths(result); (void) tee_fputs("