Skip to content

Commit 3ea7e49

Browse files
authored
Merge pull request #58 from rpopescu/performance-improvements
Performance improvements
2 parents 3255b18 + ee86577 commit 3ea7e49

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

clickhouse/base/wire_format.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class WireFormat {
1212
static bool ReadFixed(CodedInputStream* input, T* value);
1313

1414
static bool ReadString(CodedInputStream* input, std::string* value);
15+
static bool SkipString(CodedInputStream* input);
1516

1617
static bool ReadBytes(CodedInputStream* input, void* buf, size_t len);
1718

@@ -53,6 +54,21 @@ inline bool WireFormat::ReadString(
5354
return false;
5455
}
5556

57+
inline bool WireFormat::SkipString(
58+
CodedInputStream* input)
59+
{
60+
uint64_t len;
61+
62+
if (input->ReadVarint64(&len)) {
63+
if (len > 0x00FFFFFFULL) {
64+
return false;
65+
}
66+
return input->Skip((size_t)len);
67+
}
68+
69+
return false;
70+
}
71+
5672
inline bool WireFormat::ReadBytes(
5773
CodedInputStream* input, void* buf, size_t len)
5874
{

clickhouse/client.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,14 @@ void Client::Impl::Insert(const std::string& table_name, const Block& block) {
225225
RetryGuard([this]() { Ping(); });
226226
}
227227

228-
std::vector<std::string> fields;
229-
fields.reserve(block.GetColumnCount());
230-
231-
// Enumerate all fields
232-
for (unsigned int i = 0; i < block.GetColumnCount(); i++) {
233-
fields.push_back(NameToQueryString(block.GetColumnName(i)));
234-
}
235-
236228
std::stringstream fields_section;
229+
const auto num_columns = block.GetColumnCount();
237230

238-
for (auto elem = fields.begin(); elem != fields.end(); ++elem) {
239-
if (std::distance(elem, fields.end()) == 1) {
240-
fields_section << *elem;
231+
for (unsigned int i = 0; i < num_columns; ++i) {
232+
if (i == num_columns - 1) {
233+
fields_section << NameToQueryString(block.GetColumnName(i));
241234
} else {
242-
fields_section << *elem << ",";
235+
fields_section << NameToQueryString(block.GetColumnName(i)) << ",";
243236
}
244237
}
245238

@@ -462,10 +455,9 @@ bool Client::Impl::ReadBlock(Block* block, CodedInputStream* input) {
462455
return false;
463456
}
464457

458+
std::string name;
459+
std::string type;
465460
for (size_t i = 0; i < num_columns; ++i) {
466-
std::string name;
467-
std::string type;
468-
469461
if (!WireFormat::ReadString(input, &name)) {
470462
return false;
471463
}
@@ -491,9 +483,7 @@ bool Client::Impl::ReceiveData() {
491483
Block block;
492484

493485
if (REVISION >= DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES) {
494-
std::string table_name;
495-
496-
if (!WireFormat::ReadString(&input_, &table_name)) {
486+
if (!WireFormat::SkipString(&input_)) {
497487
return false;
498488
}
499489
}

0 commit comments

Comments
 (0)