Improve Livestatus query performance

fixes #8594
This commit is contained in:
Gunnar Beutner 2015-03-04 10:58:22 +01:00
parent 24db685806
commit afd1927a98
3 changed files with 26 additions and 4 deletions

View File

@ -181,6 +181,14 @@ void Array::Clear(void)
m_Data.clear();
}
void Array::Reserve(size_t new_size)
{
ASSERT(!OwnsLock());
ObjectLock olock(this);
m_Data.reserve(new_size);
}
void Array::CopyTo(const Array::Ptr& dest) const
{
ASSERT(!OwnsLock());

View File

@ -62,6 +62,8 @@ public:
void Resize(size_t new_size);
void Clear(void);
void Reserve(size_t new_size);
void CopyTo(const Array::Ptr& dest) const;
Array::Ptr ShallowClone(void) const;

View File

@ -508,16 +508,26 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream)
if (m_Aggregators.empty()) {
Array::Ptr header = new Array();
typedef std::pair<String, Column> ColumnPair;
std::vector<ColumnPair> column_objs;
column_objs.reserve(columns.size());
BOOST_FOREACH(const String& columnName, columns)
column_objs.push_back(std::make_pair(columnName, table->GetColumn(columnName)));
rs->Reserve(1 + objects.size());
BOOST_FOREACH(const LivestatusRowValue& object, objects) {
Array::Ptr row = new Array();
BOOST_FOREACH(const String& columnName, columns) {
Column column = table->GetColumn(columnName);
row->Reserve(column_objs.size());
BOOST_FOREACH(const ColumnPair& cv, column_objs) {
if (m_ColumnHeaders)
header->Add(columnName);
header->Add(cv.first);
row->Add(column.ExtractValue(object.Row, object.GroupByType, object.GroupByObject));
row->Add(cv.second.ExtractValue(object.Row, object.GroupByType, object.GroupByObject));
}
if (m_ColumnHeaders) {
@ -558,6 +568,8 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream)
Array::Ptr row = new Array();
row->Reserve(m_Columns.size() + m_Aggregators.size());
/*
* add selected columns next to stats
* may not be accurate for grouping!