Commit 1ed40339 authored by unknown's avatar unknown

ndb - make YEAR and TIMESTAMP into ndb types


mysql-test/r/ndb_index_ordered.result:
  make YEAR and TIMESTAMP into ndb types
mysql-test/t/ndb_index_ordered.test:
  make YEAR and TIMESTAMP into ndb types
ndb/include/kernel/signaldata/DictTabInfo.hpp:
  make YEAR and TIMESTAMP into ndb types
ndb/include/ndbapi/NdbDictionary.hpp:
  make YEAR and TIMESTAMP into ndb types
ndb/include/util/NdbSqlUtil.hpp:
  make YEAR and TIMESTAMP into ndb types
ndb/src/common/util/NdbSqlUtil.cpp:
  make YEAR and TIMESTAMP into ndb types
ndb/src/ndbapi/NdbDictionary.cpp:
  make YEAR and TIMESTAMP into ndb types
ndb/src/ndbapi/NdbDictionaryImpl.cpp:
  make YEAR and TIMESTAMP into ndb types
ndb/src/ndbapi/NdbRecAttr.cpp:
  make YEAR and TIMESTAMP into ndb types
ndb/test/include/NdbSchemaOp.hpp:
  make YEAR and TIMESTAMP into ndb types
sql/ha_ndbcluster.cc:
  make YEAR and TIMESTAMP into ndb types
parent 4e5a513c
...@@ -323,16 +323,16 @@ index(ye), ...@@ -323,16 +323,16 @@ index(ye),
index(ti), index(ti),
index(ts) index(ts)
) engine=ndb; ) engine=ndb;
insert into t1 (pk,dt,da,ye,ti) values insert into t1 (pk,dt,da,ye,ti,ts) values
(1, '1901-05-05 23:00:59', '1901-05-05', '1901', '23:00:59'), (1, '1901-05-05 23:00:59', '1901-05-05', '1901', '23:00:59', '2001-01-01 23:00:59'),
(2, '1912-09-05 13:00:59', '1912-09-05', '1912', '13:00:59'), (2, '1912-09-05 13:00:59', '1912-09-05', '1912', '13:00:59', '2001-01-01 13:00:59'),
(3, '1945-12-31 00:00:00', '1945-12-31', '1945', '00:00:00'), (3, '1945-12-31 00:00:00', '1945-12-31', '1945', '00:00:00', '2001-01-01 00:00:00'),
(4, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00'), (4, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00', '2001-01-01 00:00:00'),
(5, '1963-06-06 06:06:06', '1963-06-06', '1963', '06:06:06'), (5, '1963-06-06 06:06:06', '1963-06-06', '1963', '06:06:06', '2001-01-01 06:06:06'),
(6, '1993-06-06 06:06:06', '1993-06-06', '1993', '06:06:06'), (6, '1993-06-06 06:06:06', '1993-06-06', '1993', '06:06:06', '2001-01-01 06:06:06'),
(7, '2001-01-01 10:11:10', '2001-01-01', '2001', '10:11:10'), (7, '2001-01-01 10:11:10', '2001-01-01', '2001', '10:11:10', '2001-01-01 10:11:10'),
(8, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11'), (8, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11', '2001-01-01 10:11:11'),
(9, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59'); (9, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59', '2001-01-01 23:59:59');
select count(*)-9 from t1 use index (dt) where dt > '1900-01-01 00:00:00'; select count(*)-9 from t1 use index (dt) where dt > '1900-01-01 00:00:00';
count(*)-9 count(*)-9
0 0
...@@ -420,6 +420,30 @@ count(*)-8 ...@@ -420,6 +420,30 @@ count(*)-8
select count(*)-9 from t1 use index (ti) where ti <= '23:59:59'; select count(*)-9 from t1 use index (ti) where ti <= '23:59:59';
count(*)-9 count(*)-9
0 0
select count(*)-9 from t1 use index (ts) where ts >= '2001-01-01 00:00:00';
count(*)-9
0
select count(*)-7 from t1 use index (ts) where ts > '2001-01-01 00:00:00';
count(*)-7
0
select count(*)-7 from t1 use index (ts) where ts > '2001-01-01 05:05:05';
count(*)-7
0
select count(*)-5 from t1 use index (ts) where ts > '2001-01-01 06:06:06';
count(*)-5
0
select count(*)-5 from t1 use index (ts) where ts < '2001-01-01 10:11:11';
count(*)-5
0
select count(*)-6 from t1 use index (ts) where ts <= '2001-01-01 10:11:11';
count(*)-6
0
select count(*)-8 from t1 use index (ts) where ts < '2001-01-01 23:59:59';
count(*)-8
0
select count(*)-9 from t1 use index (ts) where ts <= '2001-01-01 23:59:59';
count(*)-9
0
drop table t1; drop table t1;
create table t1(a int primary key, b int not null, index(b)); create table t1(a int primary key, b int not null, index(b));
insert into t1 values (1,1), (2,2); insert into t1 values (1,1), (2,2);
......
...@@ -189,16 +189,16 @@ create table t1 ( ...@@ -189,16 +189,16 @@ create table t1 (
index(ts) index(ts)
) engine=ndb; ) engine=ndb;
insert into t1 (pk,dt,da,ye,ti) values insert into t1 (pk,dt,da,ye,ti,ts) values
(1, '1901-05-05 23:00:59', '1901-05-05', '1901', '23:00:59'), (1, '1901-05-05 23:00:59', '1901-05-05', '1901', '23:00:59', '2001-01-01 23:00:59'),
(2, '1912-09-05 13:00:59', '1912-09-05', '1912', '13:00:59'), (2, '1912-09-05 13:00:59', '1912-09-05', '1912', '13:00:59', '2001-01-01 13:00:59'),
(3, '1945-12-31 00:00:00', '1945-12-31', '1945', '00:00:00'), (3, '1945-12-31 00:00:00', '1945-12-31', '1945', '00:00:00', '2001-01-01 00:00:00'),
(4, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00'), (4, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00', '2001-01-01 00:00:00'),
(5, '1963-06-06 06:06:06', '1963-06-06', '1963', '06:06:06'), (5, '1963-06-06 06:06:06', '1963-06-06', '1963', '06:06:06', '2001-01-01 06:06:06'),
(6, '1993-06-06 06:06:06', '1993-06-06', '1993', '06:06:06'), (6, '1993-06-06 06:06:06', '1993-06-06', '1993', '06:06:06', '2001-01-01 06:06:06'),
(7, '2001-01-01 10:11:10', '2001-01-01', '2001', '10:11:10'), (7, '2001-01-01 10:11:10', '2001-01-01', '2001', '10:11:10', '2001-01-01 10:11:10'),
(8, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11'), (8, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11', '2001-01-01 10:11:11'),
(9, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59'); (9, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59', '2001-01-01 23:59:59');
# datetime # datetime
select count(*)-9 from t1 use index (dt) where dt > '1900-01-01 00:00:00'; select count(*)-9 from t1 use index (dt) where dt > '1900-01-01 00:00:00';
...@@ -237,6 +237,16 @@ select count(*)-6 from t1 use index (ti) where ti <= '10:11:11'; ...@@ -237,6 +237,16 @@ 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(*)-8 from t1 use index (ti) where ti < '23:59:59';
select count(*)-9 from t1 use index (ti) where ti <= '23:59:59'; select count(*)-9 from t1 use index (ti) where ti <= '23:59:59';
# timestamp
select count(*)-9 from t1 use index (ts) where ts >= '2001-01-01 00:00:00';
select count(*)-7 from t1 use index (ts) where ts > '2001-01-01 00:00:00';
select count(*)-7 from t1 use index (ts) where ts > '2001-01-01 05:05:05';
select count(*)-5 from t1 use index (ts) where ts > '2001-01-01 06:06:06';
select count(*)-5 from t1 use index (ts) where ts < '2001-01-01 10:11:11';
select count(*)-6 from t1 use index (ts) where ts <= '2001-01-01 10:11:11';
select count(*)-8 from t1 use index (ts) where ts < '2001-01-01 23:59:59';
select count(*)-9 from t1 use index (ts) where ts <= '2001-01-01 23:59:59';
drop table t1; drop table t1;
# bug#7798 # bug#7798
......
...@@ -311,7 +311,9 @@ public: ...@@ -311,7 +311,9 @@ public:
ExtDate = NdbSqlUtil::Type::Date, ExtDate = NdbSqlUtil::Type::Date,
ExtBlob = NdbSqlUtil::Type::Blob, ExtBlob = NdbSqlUtil::Type::Blob,
ExtText = NdbSqlUtil::Type::Text, ExtText = NdbSqlUtil::Type::Text,
ExtTime = NdbSqlUtil::Type::Time ExtTime = NdbSqlUtil::Type::Time,
ExtYear = NdbSqlUtil::Type::Year,
ExtTimestamp = NdbSqlUtil::Type::Timestamp
}; };
// Attribute data interpretation // Attribute data interpretation
...@@ -446,6 +448,16 @@ public: ...@@ -446,6 +448,16 @@ public:
AttributeSize = DictTabInfo::an8Bit; AttributeSize = DictTabInfo::an8Bit;
AttributeArraySize = 3 * AttributeExtLength; AttributeArraySize = 3 * AttributeExtLength;
return true; return true;
case DictTabInfo::ExtYear:
AttributeType = DictTabInfo::StringType;
AttributeSize = DictTabInfo::an8Bit;
AttributeArraySize = 1 * AttributeExtLength;
return true;
case DictTabInfo::ExtTimestamp:
AttributeType = DictTabInfo::StringType;
AttributeSize = DictTabInfo::an8Bit;
AttributeArraySize = 4 * AttributeExtLength;
return true;
}; };
return false; return false;
} }
......
...@@ -188,7 +188,9 @@ public: ...@@ -188,7 +188,9 @@ public:
Date, ///< Precision down to 1 day(sizeof(Date) == 4 bytes ) Date, ///< Precision down to 1 day(sizeof(Date) == 4 bytes )
Blob, ///< Binary large object (see NdbBlob) Blob, ///< Binary large object (see NdbBlob)
Text, ///< Text blob Text, ///< Text blob
Time = 25 ///< Time without date Time = 25, ///< Time without date
Year = 26, ///< Year 1901-2155 (1 byte)
Timestamp = 27 ///< Unix time
}; };
/** /**
......
...@@ -84,7 +84,9 @@ public: ...@@ -84,7 +84,9 @@ public:
Date, // Precision down to 1 day (size 4 bytes) Date, // Precision down to 1 day (size 4 bytes)
Blob, // Blob Blob, // Blob
Text, // Text blob Text, // Text blob
Time = 25 // Time without date Time = 25, // Time without date
Year = 26, // Year (size 1 byte)
Timestamp = 27 // Unix seconds (uint32)
}; };
Enum m_typeId; Enum m_typeId;
Cmp* m_cmp; // comparison method Cmp* m_cmp; // comparison method
...@@ -137,6 +139,8 @@ private: ...@@ -137,6 +139,8 @@ private:
static Cmp cmpBlob; static Cmp cmpBlob;
static Cmp cmpText; static Cmp cmpText;
static Cmp cmpTime; static Cmp cmpTime;
static Cmp cmpYear;
static Cmp cmpTimestamp;
}; };
#endif #endif
...@@ -179,6 +179,14 @@ NdbSqlUtil::m_typeList[] = { ...@@ -179,6 +179,14 @@ NdbSqlUtil::m_typeList[] = {
{ {
Type::Time, Type::Time,
cmpTime cmpTime
},
{
Type::Year,
cmpYear
},
{
Type::Timestamp,
cmpTimestamp
} }
}; };
...@@ -592,6 +600,34 @@ NdbSqlUtil::cmpTime(const void* info, const Uint32* p1, const Uint32* p2, Uint32 ...@@ -592,6 +600,34 @@ NdbSqlUtil::cmpTime(const void* info, const Uint32* p1, const Uint32* p2, Uint32
return 0; return 0;
} }
int
NdbSqlUtil::cmpYear(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;
if (u1.v[0] < u2.v[0])
return -1;
if (u1.v[0] > u2.v[0])
return +1;
return 0;
}
int
NdbSqlUtil::cmpTimestamp(const void* info, const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size)
{
assert(full >= size && size > 0);
union { Uint32 p[1]; Uint32 v; } u1, u2;
u1.v = p1[0];
u2.v = p2[0];
if (u1.v < u2.v)
return -1;
if (u1.v > u2.v)
return +1;
return 0;
}
// check charset // check charset
bool bool
......
...@@ -950,6 +950,12 @@ operator<<(NdbOut& out, const NdbDictionary::Column& col) ...@@ -950,6 +950,12 @@ operator<<(NdbOut& out, const NdbDictionary::Column& col)
case NdbDictionary::Column::Time: case NdbDictionary::Column::Time:
out << "Time"; out << "Time";
break; break;
case NdbDictionary::Column::Year:
out << "Year";
break;
case NdbDictionary::Column::Timestamp:
out << "Timestamp";
break;
case NdbDictionary::Column::Undefined: case NdbDictionary::Column::Undefined:
out << "Undefined"; out << "Undefined";
break; break;
......
...@@ -149,6 +149,8 @@ NdbColumnImpl::init(Type t) ...@@ -149,6 +149,8 @@ NdbColumnImpl::init(Type t)
m_cs = default_cs; m_cs = default_cs;
break; break;
case Time: case Time:
case Year:
case Timestamp:
m_precision = 0; m_precision = 0;
m_scale = 0; m_scale = 0;
m_length = 1; m_length = 1;
...@@ -1184,6 +1186,8 @@ columnTypeMapping[] = { ...@@ -1184,6 +1186,8 @@ columnTypeMapping[] = {
{ DictTabInfo::ExtBlob, NdbDictionary::Column::Blob }, { DictTabInfo::ExtBlob, NdbDictionary::Column::Blob },
{ DictTabInfo::ExtText, NdbDictionary::Column::Text }, { DictTabInfo::ExtText, NdbDictionary::Column::Text },
{ DictTabInfo::ExtTime, NdbDictionary::Column::Time }, { DictTabInfo::ExtTime, NdbDictionary::Column::Time },
{ DictTabInfo::ExtYear, NdbDictionary::Column::Year },
{ DictTabInfo::ExtTimestamp, NdbDictionary::Column::Timestamp },
{ -1, -1 } { -1, -1 }
}; };
......
...@@ -156,10 +156,11 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r) ...@@ -156,10 +156,11 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
return out; return out;
} }
if (r.arraySize() > 1) uint length = r.getColumn()->getLength();
if (length > 1)
out << "["; out << "[";
for (Uint32 j = 0; j < r.arraySize(); j++) for (Uint32 j = 0; j < length; j++)
{ {
if (j > 0) if (j > 0)
out << " "; out << " ";
...@@ -192,14 +193,14 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r) ...@@ -192,14 +193,14 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
break; break;
case NdbDictionary::Column::Char: case NdbDictionary::Column::Char:
out.print("%.*s", r.arraySize(), r.aRef()); out.print("%.*s", r.arraySize(), r.aRef());
j = r.arraySize(); j = length;
break; break;
case NdbDictionary::Column::Varchar: case NdbDictionary::Column::Varchar:
{ {
short len = ntohs(r.u_short_value()); short len = ntohs(r.u_short_value());
out.print("%.*s", len, r.aRef()+2); out.print("%.*s", len, r.aRef()+2);
} }
j = r.arraySize(); j = length;
break; break;
case NdbDictionary::Column::Float: case NdbDictionary::Column::Float:
out << r.float_value(); out << r.float_value();
...@@ -207,6 +208,74 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r) ...@@ -207,6 +208,74 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
case NdbDictionary::Column::Double: case NdbDictionary::Column::Double:
out << r.double_value(); out << r.double_value();
break; break;
// for dates cut-and-paste from field.cc
case NdbDictionary::Column::Datetime:
{
ulonglong tmp=r.u_64_value();
long part1,part2,part3;
part1=(long) (tmp/LL(1000000));
part2=(long) (tmp - (ulonglong) part1*LL(1000000));
char buf[40];
char* pos=(char*) buf+19;
*pos--=0;
*pos--= (char) ('0'+(char) (part2%10)); part2/=10;
*pos--= (char) ('0'+(char) (part2%10)); part3= (int) (part2 / 10);
*pos--= ':';
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
*pos--= ':';
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
*pos--= (char) ('0'+(char) part3);
*pos--= '/';
*pos--= (char) ('0'+(char) (part1%10)); part1/=10;
*pos--= (char) ('0'+(char) (part1%10)); part1/=10;
*pos--= '-';
*pos--= (char) ('0'+(char) (part1%10)); part1/=10;
*pos--= (char) ('0'+(char) (part1%10)); part3= (int) (part1/10);
*pos--= '-';
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
*pos=(char) ('0'+(char) part3);
out << buf;
}
break;
case NdbDictionary::Column::Date:
{
uint tmp=uint3korr(r.aRef());
int year=(int) ((uint32) tmp/10000L % 10000);
int month=(int) ((uint32) tmp/100 % 100);
int day=(int) ((uint32) tmp % 100);
char buf[40];
sprintf(buf, "%04d-%02d-%02d", year, month, day);
out << buf;
}
break;
case NdbDictionary::Column::Time:
{
long tmp=(long) sint3korr(r.aRef());
int hour=(uint) (tmp/10000);
int minute=(uint) (tmp/100 % 100);
int second=(uint) (tmp % 100);
char buf[40];
sprintf(buf, "%02d:%02d:%02d", hour, minute, second);
out << buf;
}
break;
case NdbDictionary::Column::Year:
{
uint year = 1900 + r.u_char_value();
char buf[40];
sprintf(buf, "%04d", year);
out << buf;
}
break;
case NdbDictionary::Column::Timestamp:
{
time_t time = r.u_32_value();
out << (uint)time;
}
break;
case NdbDictionary::Column::Blob: case NdbDictionary::Column::Blob:
{ {
const NdbBlob::Head* h = (const NdbBlob::Head*)r.aRef(); const NdbBlob::Head* h = (const NdbBlob::Head*)r.aRef();
...@@ -215,7 +284,7 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r) ...@@ -215,7 +284,7 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
unsigned n = r.arraySize() - sizeof(*h); unsigned n = r.arraySize() - sizeof(*h);
for (unsigned k = 0; k < n && k < h->length; k++) for (unsigned k = 0; k < n && k < h->length; k++)
out.print("%02X", (int)p[k]); out.print("%02X", (int)p[k]);
j = r.arraySize(); j = length;
} }
break; break;
case NdbDictionary::Column::Text: case NdbDictionary::Column::Text:
...@@ -226,19 +295,19 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r) ...@@ -226,19 +295,19 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
unsigned n = r.arraySize() - sizeof(*h); unsigned n = r.arraySize() - sizeof(*h);
for (unsigned k = 0; k < n && k < h->length; k++) for (unsigned k = 0; k < n && k < h->length; k++)
out.print("%c", (int)p[k]); out.print("%c", (int)p[k]);
j = r.arraySize(); j = length;
} }
break; break;
default: /* no print functions for the rest, just print type */ default: /* no print functions for the rest, just print type */
out << (int) r.getType(); out << (int) r.getType();
j = r.arraySize(); j = length;
if (j > 1) if (j > 1)
out << " " << j << " times"; out << " " << j << " times";
break; break;
} }
} }
if (r.arraySize() > 1) if (length > 1)
{ {
out << "]"; out << "]";
} }
......
...@@ -575,10 +575,6 @@ convertColumnTypeToAttrType(NdbDictionary::Column::Type _type) ...@@ -575,10 +575,6 @@ convertColumnTypeToAttrType(NdbDictionary::Column::Type _type)
case NdbDictionary::Column::Binary: case NdbDictionary::Column::Binary:
case NdbDictionary::Column::Varbinary: case NdbDictionary::Column::Varbinary:
return String; return String;
case NdbDictionary::Column::Datetime:
case NdbDictionary::Column::Date:
case NdbDictionary::Column::Time:
case NdbDictionary::Column::Undefined:
default: default:
return NoAttrTypeDef; return NoAttrTypeDef;
} }
......
...@@ -3360,14 +3360,14 @@ static int create_ndb_column(NDBCOL &col, ...@@ -3360,14 +3360,14 @@ static int create_ndb_column(NDBCOL &col,
col.setLength(1); col.setLength(1);
break; break;
// Date types // Date types
case MYSQL_TYPE_TIMESTAMP:
col.setType(NDBCOL::Unsigned);
col.setLength(1);
break;
case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_DATETIME:
col.setType(NDBCOL::Datetime); col.setType(NDBCOL::Datetime);
col.setLength(1); col.setLength(1);
break; break;
case MYSQL_TYPE_DATE: // ?
col.setType(NDBCOL::Char);
col.setLength(field->pack_length());
break;
case MYSQL_TYPE_NEWDATE: case MYSQL_TYPE_NEWDATE:
col.setType(NDBCOL::Date); col.setType(NDBCOL::Date);
col.setLength(1); col.setLength(1);
...@@ -3376,10 +3376,13 @@ static int create_ndb_column(NDBCOL &col, ...@@ -3376,10 +3376,13 @@ static int create_ndb_column(NDBCOL &col,
col.setType(NDBCOL::Time); col.setType(NDBCOL::Time);
col.setLength(1); col.setLength(1);
break; break;
case MYSQL_TYPE_DATE: // ? case MYSQL_TYPE_YEAR:
case MYSQL_TYPE_YEAR: col.setType(NDBCOL::Year);
col.setType(NDBCOL::Char); col.setLength(1);
col.setLength(field->pack_length()); break;
case MYSQL_TYPE_TIMESTAMP:
col.setType(NDBCOL::Timestamp);
col.setLength(1);
break; break;
// Char types // Char types
case MYSQL_TYPE_STRING: case MYSQL_TYPE_STRING:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment