diff --git a/dbms/include/DB/ColumnType.h b/dbms/include/DB/ColumnType.h index 16a1f7588c1..b5ae9f3ab1b 100644 --- a/dbms/include/DB/ColumnType.h +++ b/dbms/include/DB/ColumnType.h @@ -112,7 +112,9 @@ public: void deserializeBinary(DB::Field & field, std::istream & istr) const { Poco::BinaryReader r(istr); - r >> boost::get(field); + UInt x; + r >> x; + field = x; } void serializeText(const DB::Field & field, std::ostream & ostr) const @@ -122,7 +124,9 @@ public: void deserializeText(DB::Field & field, std::istream & istr) const { - istr >> boost::get(field); + UInt x; + istr >> x; + field = x; } }; @@ -144,7 +148,7 @@ public: Poco::BinaryReader r(istr); Poco::UInt32 x; r >> x; - boost::get(field) = x; + field = UInt(x); } void serializeText(const DB::Field & field, std::ostream & ostr) const @@ -156,7 +160,7 @@ public: { Poco::UInt32 x; istr >> x; - boost::get(field) = x; + field = UInt(x); } }; @@ -176,7 +180,9 @@ public: void deserializeBinary(DB::Field & field, std::istream & istr) const { Poco::BinaryReader r(istr); - r >> boost::get(field); + Int x; + r >> x; + field = x; } void serializeText(const DB::Field & field, std::ostream & ostr) const @@ -186,7 +192,9 @@ public: void deserializeText(DB::Field & field, std::istream & istr) const { - istr >> boost::get(field); + Int x; + istr >> x; + field = x; } }; @@ -208,7 +216,7 @@ public: Poco::BinaryReader r(istr); Poco::Int32 x; r >> x; - boost::get(field) = x; + field = Int(x); } void serializeText(const DB::Field & field, std::ostream & ostr) const @@ -220,7 +228,7 @@ public: { Poco::Int32 x; istr >> x; - boost::get(field) = x; + field = Int(x); } }; @@ -238,7 +246,9 @@ public: void deserializeBinary(DB::Field & field, std::istream & istr) const { - readVarUInt(boost::get(field), istr); + UInt x; + readVarUInt(x, istr); + field = x; } void serializeText(const DB::Field & field, std::ostream & ostr) const @@ -248,7 +258,9 @@ public: void deserializeText(DB::Field & field, std::istream & istr) const { - istr >> boost::get(field); + UInt x; + istr >> x; + field = x; } }; @@ -266,7 +278,9 @@ public: void deserializeBinary(DB::Field & field, std::istream & istr) const { - readVarInt(boost::get(field), istr); + Int x; + readVarInt(x, istr); + field = x; } void serializeText(const DB::Field & field, std::ostream & ostr) const @@ -276,7 +290,9 @@ public: void deserializeText(DB::Field & field, std::istream & istr) const { - istr >> boost::get(field); + Int x; + istr >> x; + field = x; } }; @@ -296,10 +312,12 @@ public: void deserializeBinary(DB::Field & field, std::istream & istr) const { - field = std::string(""); - std::string & str = boost::get(field); + field = String(""); + String & str = boost::get(field); UInt size; readVarUInt(size, istr); + if (!istr.good()) + return; str.resize(size); /// непереносимо, но (действительно) быстрее istr.read(const_cast(str.data()), size); @@ -312,6 +330,7 @@ public: void deserializeText(DB::Field & field, std::istream & istr) const { + field = std::string(""); istr >> boost::get(field); } }; @@ -346,7 +365,7 @@ public: void deserializeBinary(DB::Field & field, std::istream & istr) const { - field = std::string(""); + field = String(""); std::string & str = boost::get(field); str.resize(size); /// непереносимо, но (действительно) быстрее @@ -360,6 +379,7 @@ public: void deserializeText(DB::Field & field, std::istream & istr) const { + field = String(""); istr >> boost::get(field); } }; @@ -392,9 +412,12 @@ public: void deserializeBinary(DB::Field & field, std::istream & istr) const { + field = FieldVector(); FieldVector & vec = boost::get(field); UInt size; readVarUInt(size, istr); + if (!istr.good()) + return; vec.resize(size); for (UInt i(0); i < size; ++i) nested_type->deserializeBinary(vec[i], istr); @@ -453,6 +476,7 @@ public: void deserializeBinary(DB::Field & field, std::istream & istr) const { + field = FieldVector(); FieldVector & vec = boost::get(field); vec.resize(size); for (UInt i(0); i < size; ++i) diff --git a/dbms/src/PrimaryKeyNone.cpp b/dbms/src/PrimaryKeyNone.cpp index f1e7186f8a9..e8c5df22d33 100644 --- a/dbms/src/PrimaryKeyNone.cpp +++ b/dbms/src/PrimaryKeyNone.cpp @@ -62,16 +62,13 @@ bool PrimaryKeyNoneTablePartReader::fetch(Row & row) if (key.size() > pk->column_group->column_numbers.size()) throw Exception("Too many columns specified for key", ErrorCodes::TOO_MANY_COLUMNS_FOR_KEY); + row.resize(pk->column_group->column_numbers.size()); + while (1) { for (size_t i = 0; i < pk->column_group->column_numbers.size(); ++i) pk->table->columns->at(pk->column_group->column_numbers[i]).type->deserializeBinary(row[i], istr); - /// проверим, что ключи совпадают (замечание: столбцы ключа всегда идут первыми) - for (size_t i = 0; i < key.size(); ++i) - if (key[i] != row[i]) - continue; - if (istr.eof()) return false; @@ -79,6 +76,11 @@ bool PrimaryKeyNoneTablePartReader::fetch(Row & row) throw Exception("Cannot read data file " + pk->data_file_name , ErrorCodes::CANT_READ_DATA_FILE); + /// проверим, что ключи совпадают (замечание: столбцы ключа всегда идут первыми) + for (size_t i = 0; i < key.size(); ++i) + if (key[i] != row[i]) + continue; + return true; } } diff --git a/dbms/src/tests/primary_key_none.cpp b/dbms/src/tests/primary_key_none.cpp index cc700af80cf..c13a42223f2 100644 --- a/dbms/src/tests/primary_key_none.cpp +++ b/dbms/src/tests/primary_key_none.cpp @@ -46,6 +46,7 @@ int main(int argc, char ** argv) /// создаём набор данных DB::AggregatedRowSet data; + std::string text("http://www.google.com/custom?cof=LW%3A277%3BL%3Ahttp%3A%2F%2Fwww.boost.org%2Fboost.png%3BLH%3A86%3BAH%3Acenter%3BGL%3A0%3BS%3Ahttp%3A%2F%2Fwww.boost.org%3BAWFID%3A9b83d16ce652ed5a%3B&sa=Google+Search&domains=www.boost.org%3Blists.boost.org&hq=site%3Awww.boost.org+OR+site%3Alists.boost.org&q=boost%3A%3Ablank"); { DB::Row key; key.push_back(DB::Field(DB::UInt(0))); @@ -56,11 +57,11 @@ int main(int argc, char ** argv) stopwatch.restart(); - for (int i = 0; i < 1000000; ++i) + for (DB::UInt i = 0; i < 1000000; ++i) { - key[0] = DB::UInt(i); - key[1] = DB::UInt(i * 123456789 % 1000000); - key[2] = "http://www.google.com/custom?cof=LW%3A277%3BL%3Ahttp%3A%2F%2Fwww.boost.org%2Fboost.png%3BLH%3A86%3BAH%3Acenter%3BGL%3A0%3BS%3Ahttp%3A%2F%2Fwww.boost.org%3BAWFID%3A9b83d16ce652ed5a%3B&sa=Google+Search&domains=www.boost.org%3Blists.boost.org&hq=site%3Awww.boost.org+OR+site%3Alists.boost.org&q=boost%3A%3Ablank"; + key[0] = i; + key[1] = i * 123456789 % 1000000; + key[2] = text; data[key] = value; } @@ -81,5 +82,30 @@ int main(int argc, char ** argv) std::cout << "Saving data: " << static_cast(stopwatch.elapsed()) / 1000000 << std::endl; } + /// читаем таблицу + DB::AggregatedRowSet data_read; + { + DB::Row key; + Poco::SharedPtr reader(column_group0.primary_key->read(key)); + + stopwatch.restart(); + + DB::Row row; + DB::UInt i = 0; + while (reader->fetch(row)) + { + if (boost::get(row[0]) != i + || boost::get(row[1]) != i * 123456789 % 1000000 + || boost::get(row[2]) != text) + throw Poco::Exception("Incorrect data"); + ++i; + } + if (i != 1000000) + throw Poco::Exception("Number of rows doesn't match"); + + stopwatch.stop(); + std::cout << "Reading data: " << static_cast(stopwatch.elapsed()) / 1000000 << std::endl; + } + return 0; }