Skip to content

Commit

Permalink
calculate estimated result size for stats queries
Browse files Browse the repository at this point in the history
output size is always zero here until we calculate the final result but it would be good to cancel runaway stats queries as well, ex. stats with high cardinality column set
  • Loading branch information
sni committed Feb 7, 2024
1 parent c330769 commit 532addb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,17 @@ bool Query::processDataset(void *data)
if( is_new ) {
_current_line++;
_sorter.insert( data, _limit+_offset );

// make sure we don't create too many aggregation entries. The size is only a rough estimation
// from the last entry mulitplies with the number of entries.
size_t rowsize = 0;
for (_stats_group_spec_t::iterator iit = groupspec.begin(); iit != groupspec.end(); ++iit)
rowsize += sizeof(char*) * strlen((*iit).c_str());
if (_sorter.size() * rowsize > g_max_response_size) {
logger(LG_INFO, "Maximum response size of %d bytes exceeded!", g_max_response_size);
_output->setError(RESPONSE_CODE_LIMIT_EXCEEDED, "Maximum response size of %d reached", g_max_response_size);
return false;
}
}
}
else
Expand Down

0 comments on commit 532addb

Please sign in to comment.