2011-08-27 22:43:31 +00:00
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
2012-02-27 07:54:16 +00:00
|
|
|
|
/*#include <Poco/Mutex.h>
|
|
|
|
|
#include <Poco/Ext/ThreadNumber.h>*/
|
|
|
|
|
|
2013-09-07 02:03:13 +00:00
|
|
|
|
#include <DB/Columns/ColumnConst.h>
|
2015-05-29 21:32:10 +00:00
|
|
|
|
#include <DB/Interpreters/Quota.h>
|
2015-06-21 06:06:04 +00:00
|
|
|
|
#include <DB/Interpreters/ProcessList.h>
|
2011-09-04 21:23:19 +00:00
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
2011-08-27 22:43:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
|
namespace ErrorCodes
|
|
|
|
|
{
|
|
|
|
|
extern const int TOO_MUCH_ROWS;
|
|
|
|
|
extern const int TOO_MUCH_BYTES;
|
|
|
|
|
extern const int TIMEOUT_EXCEEDED;
|
|
|
|
|
extern const int TOO_SLOW;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-27 22:43:31 +00:00
|
|
|
|
|
2011-09-04 21:23:19 +00:00
|
|
|
|
Block IProfilingBlockInputStream::read()
|
2011-08-27 22:43:31 +00:00
|
|
|
|
{
|
2015-02-15 06:08:31 +00:00
|
|
|
|
collectAndSendTotalRowsApprox();
|
|
|
|
|
|
2011-08-27 22:43:31 +00:00
|
|
|
|
if (!info.started)
|
2011-09-26 01:50:32 +00:00
|
|
|
|
{
|
2011-08-27 22:43:31 +00:00
|
|
|
|
info.total_stopwatch.start();
|
2015-06-08 20:22:02 +00:00
|
|
|
|
info.stream_name = getName();
|
2011-09-26 01:50:32 +00:00
|
|
|
|
|
2015-01-18 08:25:56 +00:00
|
|
|
|
for (const auto & child : children)
|
|
|
|
|
if (const IProfilingBlockInputStream * p_child = dynamic_cast<const IProfilingBlockInputStream *>(&*child))
|
|
|
|
|
info.nested_infos.push_back(&p_child->info);
|
|
|
|
|
|
|
|
|
|
/// Заметим, что после такого, элементы children нельзя удалять до того, как может потребоваться работать с nested_info.
|
2014-08-22 02:31:54 +00:00
|
|
|
|
|
2011-09-26 01:50:32 +00:00
|
|
|
|
info.started = true;
|
|
|
|
|
}
|
2012-05-09 08:16:09 +00:00
|
|
|
|
|
2013-11-17 19:14:17 +00:00
|
|
|
|
Block res;
|
|
|
|
|
|
2015-03-20 16:20:47 +00:00
|
|
|
|
if (is_cancelled.load(std::memory_order_seq_cst))
|
2013-11-17 19:14:17 +00:00
|
|
|
|
return res;
|
2012-05-31 00:47:05 +00:00
|
|
|
|
|
2015-11-03 18:58:43 +00:00
|
|
|
|
if (!limit_exceeded_need_break)
|
|
|
|
|
res = readImpl();
|
2011-08-27 22:43:31 +00:00
|
|
|
|
|
2011-09-25 05:07:47 +00:00
|
|
|
|
/* if (res)
|
2011-09-25 03:37:09 +00:00
|
|
|
|
{
|
2012-02-27 07:54:16 +00:00
|
|
|
|
static Poco::FastMutex mutex;
|
|
|
|
|
Poco::ScopedLock<Poco::FastMutex> lock(mutex);
|
2012-03-05 07:58:34 +00:00
|
|
|
|
|
2011-09-25 03:37:09 +00:00
|
|
|
|
std::cerr << std::endl;
|
2015-06-08 20:22:02 +00:00
|
|
|
|
std::cerr << "[ " << Poco::ThreadNumber::get() << " ]\t" << getName() << std::endl;
|
2012-03-05 07:58:34 +00:00
|
|
|
|
std::cerr << "[ " << Poco::ThreadNumber::get() << " ]\t";
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < res.columns(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i != 0)
|
|
|
|
|
std::cerr << ", ";
|
|
|
|
|
std::cerr << res.getByPosition(i).name << " (" << res.getByPosition(i).column->size() << ")";
|
|
|
|
|
}
|
2014-08-22 02:31:54 +00:00
|
|
|
|
|
2012-03-05 07:58:34 +00:00
|
|
|
|
std::cerr << std::endl;
|
2011-09-25 05:07:47 +00:00
|
|
|
|
}*/
|
2012-05-09 15:15:45 +00:00
|
|
|
|
|
2012-03-05 07:58:34 +00:00
|
|
|
|
if (res)
|
2013-09-07 02:03:13 +00:00
|
|
|
|
{
|
2012-05-17 19:15:53 +00:00
|
|
|
|
info.update(res);
|
2013-09-07 02:03:13 +00:00
|
|
|
|
|
|
|
|
|
if (enabled_extremes)
|
|
|
|
|
updateExtremes(res);
|
|
|
|
|
|
|
|
|
|
if (!checkLimits())
|
2015-11-03 18:58:43 +00:00
|
|
|
|
limit_exceeded_need_break = true;
|
2013-09-07 02:03:13 +00:00
|
|
|
|
|
2014-04-08 07:31:51 +00:00
|
|
|
|
if (quota != nullptr)
|
2013-09-07 02:03:13 +00:00
|
|
|
|
checkQuota(res);
|
|
|
|
|
}
|
2012-10-17 19:59:27 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/** Если поток закончился, то ещё попросим всех детей прервать выполнение.
|
|
|
|
|
* Это имеет смысл при выполнении запроса с LIMIT-ом:
|
|
|
|
|
* - бывает ситуация, когда все необходимые данные уже прочитали,
|
|
|
|
|
* но источники-дети ещё продолжают работать,
|
|
|
|
|
* при чём они могут работать в отдельных потоках или даже удалённо.
|
|
|
|
|
*/
|
|
|
|
|
cancel();
|
|
|
|
|
}
|
2011-09-25 03:37:09 +00:00
|
|
|
|
|
2014-10-25 18:33:52 +00:00
|
|
|
|
progress(Progress(res.rowsInFirstColumn(), res.bytes()));
|
2012-12-25 17:25:44 +00:00
|
|
|
|
|
2013-09-07 02:03:13 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-09-13 20:33:09 +00:00
|
|
|
|
void IProfilingBlockInputStream::readSuffix()
|
|
|
|
|
{
|
2015-01-18 08:25:56 +00:00
|
|
|
|
for (auto & child : children)
|
|
|
|
|
child->readSuffix();
|
2013-09-13 20:33:09 +00:00
|
|
|
|
|
|
|
|
|
readSuffixImpl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-09-07 02:03:13 +00:00
|
|
|
|
void IProfilingBlockInputStream::updateExtremes(Block & block)
|
|
|
|
|
{
|
|
|
|
|
size_t columns = block.columns();
|
|
|
|
|
|
|
|
|
|
if (!extremes)
|
|
|
|
|
{
|
|
|
|
|
extremes = block.cloneEmpty();
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < columns; ++i)
|
|
|
|
|
{
|
|
|
|
|
Field min_value;
|
|
|
|
|
Field max_value;
|
|
|
|
|
|
|
|
|
|
block.getByPosition(i).column->getExtremes(min_value, max_value);
|
|
|
|
|
|
|
|
|
|
ColumnPtr & column = extremes.getByPosition(i).column;
|
|
|
|
|
|
2015-10-28 21:21:18 +00:00
|
|
|
|
if (auto converted = column->convertToFullColumnIfConst())
|
|
|
|
|
column = converted;
|
2013-09-07 02:03:13 +00:00
|
|
|
|
|
|
|
|
|
column->insert(min_value);
|
|
|
|
|
column->insert(max_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < columns; ++i)
|
|
|
|
|
{
|
|
|
|
|
ColumnPtr & column = extremes.getByPosition(i).column;
|
2014-08-22 02:31:54 +00:00
|
|
|
|
|
2013-09-07 02:03:13 +00:00
|
|
|
|
Field min_value = (*column)[0];
|
|
|
|
|
Field max_value = (*column)[1];
|
|
|
|
|
|
|
|
|
|
Field cur_min_value;
|
|
|
|
|
Field cur_max_value;
|
|
|
|
|
|
|
|
|
|
block.getByPosition(i).column->getExtremes(cur_min_value, cur_max_value);
|
|
|
|
|
|
|
|
|
|
if (cur_min_value < min_value)
|
|
|
|
|
min_value = cur_min_value;
|
|
|
|
|
if (cur_max_value > max_value)
|
|
|
|
|
max_value = cur_max_value;
|
|
|
|
|
|
|
|
|
|
column = column->cloneEmpty();
|
|
|
|
|
column->insert(min_value);
|
|
|
|
|
column->insert(max_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool IProfilingBlockInputStream::checkLimits()
|
|
|
|
|
{
|
2012-12-25 17:25:44 +00:00
|
|
|
|
/// Проверка ограничений.
|
2015-12-24 19:57:27 +00:00
|
|
|
|
if (limits.max_rows_to_read && info.rows > limits.max_rows_to_read)
|
2012-12-25 17:25:44 +00:00
|
|
|
|
{
|
2014-02-17 23:56:45 +00:00
|
|
|
|
if (limits.read_overflow_mode == OverflowMode::THROW)
|
2013-11-12 23:32:04 +00:00
|
|
|
|
throw Exception(std::string("Limit for ")
|
|
|
|
|
+ (limits.mode == LIMITS_CURRENT ? "result rows" : "rows to read")
|
|
|
|
|
+ " exceeded: read " + toString(info.rows)
|
2013-06-21 20:34:19 +00:00
|
|
|
|
+ " rows, maximum: " + toString(limits.max_rows_to_read),
|
2012-12-25 17:25:44 +00:00
|
|
|
|
ErrorCodes::TOO_MUCH_ROWS);
|
|
|
|
|
|
2014-02-17 23:56:45 +00:00
|
|
|
|
if (limits.read_overflow_mode == OverflowMode::BREAK)
|
2013-09-07 02:03:13 +00:00
|
|
|
|
return false;
|
2012-12-25 17:25:44 +00:00
|
|
|
|
|
2013-05-17 08:02:34 +00:00
|
|
|
|
throw Exception("Logical error: unknown overflow mode", ErrorCodes::LOGICAL_ERROR);
|
2012-12-25 17:25:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-24 19:57:27 +00:00
|
|
|
|
if (limits.max_bytes_to_read && info.bytes > limits.max_bytes_to_read)
|
|
|
|
|
{
|
|
|
|
|
if (limits.read_overflow_mode == OverflowMode::THROW)
|
|
|
|
|
throw Exception(std::string("Limit for ")
|
|
|
|
|
+ (limits.mode == LIMITS_CURRENT ? "result bytes (uncompressed)" : "(uncompressed) bytes to read")
|
|
|
|
|
+ " exceeded: read " + toString(info.bytes)
|
|
|
|
|
+ " bytes, maximum: " + toString(limits.max_bytes_to_read),
|
2016-01-11 21:46:36 +00:00
|
|
|
|
ErrorCodes::TOO_MUCH_BYTES);
|
2015-12-24 19:57:27 +00:00
|
|
|
|
|
|
|
|
|
if (limits.read_overflow_mode == OverflowMode::BREAK)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
throw Exception("Logical error: unknown overflow mode", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-25 17:25:44 +00:00
|
|
|
|
if (limits.max_execution_time != 0
|
|
|
|
|
&& info.total_stopwatch.elapsed() > static_cast<UInt64>(limits.max_execution_time.totalMicroseconds()) * 1000)
|
|
|
|
|
{
|
2014-02-17 23:56:45 +00:00
|
|
|
|
if (limits.timeout_overflow_mode == OverflowMode::THROW)
|
2013-06-21 20:34:19 +00:00
|
|
|
|
throw Exception("Timeout exceeded: elapsed " + toString(info.total_stopwatch.elapsedSeconds())
|
|
|
|
|
+ " seconds, maximum: " + toString(limits.max_execution_time.totalMicroseconds() / 1000000.0),
|
2012-12-25 17:25:44 +00:00
|
|
|
|
ErrorCodes::TIMEOUT_EXCEEDED);
|
|
|
|
|
|
2014-02-17 23:56:45 +00:00
|
|
|
|
if (limits.timeout_overflow_mode == OverflowMode::BREAK)
|
2013-09-07 02:03:13 +00:00
|
|
|
|
return false;
|
2012-12-25 17:25:44 +00:00
|
|
|
|
|
2013-05-17 08:02:34 +00:00
|
|
|
|
throw Exception("Logical error: unknown overflow mode", ErrorCodes::LOGICAL_ERROR);
|
2012-12-25 17:25:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-07 02:03:13 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-09-01 04:55:41 +00:00
|
|
|
|
|
|
|
|
|
|
2013-09-07 02:03:13 +00:00
|
|
|
|
void IProfilingBlockInputStream::checkQuota(Block & block)
|
|
|
|
|
{
|
2013-11-12 23:15:09 +00:00
|
|
|
|
switch (limits.mode)
|
2013-09-07 02:03:13 +00:00
|
|
|
|
{
|
2013-11-12 23:15:09 +00:00
|
|
|
|
case LIMITS_TOTAL:
|
2013-11-03 05:32:42 +00:00
|
|
|
|
/// Проверяется в методе progress.
|
2013-09-07 02:03:13 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2013-11-12 23:15:09 +00:00
|
|
|
|
case LIMITS_CURRENT:
|
2014-08-22 02:31:54 +00:00
|
|
|
|
{
|
|
|
|
|
time_t current_time = time(0);
|
|
|
|
|
double total_elapsed = info.total_stopwatch.elapsedSeconds();
|
|
|
|
|
|
2014-08-22 22:30:21 +00:00
|
|
|
|
quota->checkAndAddResultRowsBytes(current_time, block.rowsInFirstColumn(), block.bytes());
|
2013-09-07 02:03:13 +00:00
|
|
|
|
quota->checkAndAddExecutionTime(current_time, Poco::Timespan((total_elapsed - prev_elapsed) * 1000000.0));
|
2014-08-22 02:31:54 +00:00
|
|
|
|
|
|
|
|
|
prev_elapsed = total_elapsed;
|
2013-09-07 02:03:13 +00:00
|
|
|
|
break;
|
2014-08-22 02:31:54 +00:00
|
|
|
|
}
|
2013-09-01 04:55:41 +00:00
|
|
|
|
|
2013-09-07 02:03:13 +00:00
|
|
|
|
default:
|
2013-11-12 23:15:09 +00:00
|
|
|
|
throw Exception("Logical error: unknown limits mode.", ErrorCodes::LOGICAL_ERROR);
|
2013-09-01 04:55:41 +00:00
|
|
|
|
}
|
2011-08-27 22:43:31 +00:00
|
|
|
|
}
|
2012-05-17 19:15:53 +00:00
|
|
|
|
|
|
|
|
|
|
2014-10-25 18:33:52 +00:00
|
|
|
|
void IProfilingBlockInputStream::progressImpl(const Progress & value)
|
2012-05-17 19:15:53 +00:00
|
|
|
|
{
|
2015-02-15 06:08:31 +00:00
|
|
|
|
if (progress_callback)
|
|
|
|
|
progress_callback(value);
|
2013-11-03 05:32:42 +00:00
|
|
|
|
|
2015-02-15 06:08:31 +00:00
|
|
|
|
if (process_list_elem)
|
|
|
|
|
{
|
|
|
|
|
if (!process_list_elem->update(value))
|
|
|
|
|
cancel();
|
2013-11-03 05:32:42 +00:00
|
|
|
|
|
2015-02-15 06:08:31 +00:00
|
|
|
|
/// Общее количество данных, обработанных или предполагаемых к обработке во всех листовых источниках, возможно, на удалённых серверах.
|
2014-08-22 02:31:54 +00:00
|
|
|
|
|
2015-02-15 06:08:31 +00:00
|
|
|
|
size_t rows_processed = process_list_elem->progress.rows;
|
|
|
|
|
size_t bytes_processed = process_list_elem->progress.bytes;
|
2014-10-25 18:33:52 +00:00
|
|
|
|
|
2015-03-13 21:25:38 +00:00
|
|
|
|
size_t total_rows_estimate = std::max(rows_processed, process_list_elem->progress.total_rows);
|
2013-11-03 05:32:42 +00:00
|
|
|
|
|
2015-02-15 06:08:31 +00:00
|
|
|
|
/** Проверяем ограничения на объём данных для чтения, скорость выполнения запроса, квоту на объём данных для чтения.
|
|
|
|
|
* NOTE: Может быть, имеет смысл сделать, чтобы они проверялись прямо в ProcessList?
|
|
|
|
|
*/
|
2013-11-03 05:32:42 +00:00
|
|
|
|
|
2015-02-15 06:08:31 +00:00
|
|
|
|
if (limits.mode == LIMITS_TOTAL
|
|
|
|
|
&& ((limits.max_rows_to_read && total_rows_estimate > limits.max_rows_to_read)
|
|
|
|
|
|| (limits.max_bytes_to_read && bytes_processed > limits.max_bytes_to_read)))
|
|
|
|
|
{
|
|
|
|
|
if (limits.read_overflow_mode == OverflowMode::THROW)
|
2013-11-03 05:32:42 +00:00
|
|
|
|
{
|
2015-02-15 06:08:31 +00:00
|
|
|
|
if (limits.max_rows_to_read && total_rows_estimate > limits.max_rows_to_read)
|
|
|
|
|
throw Exception("Limit for rows to read exceeded: " + toString(total_rows_estimate)
|
|
|
|
|
+ " rows read (or to read), maximum: " + toString(limits.max_rows_to_read),
|
|
|
|
|
ErrorCodes::TOO_MUCH_ROWS);
|
2013-11-03 05:32:42 +00:00
|
|
|
|
else
|
2015-02-15 06:08:31 +00:00
|
|
|
|
throw Exception("Limit for (uncompressed) bytes to read exceeded: " + toString(bytes_processed)
|
|
|
|
|
+ " bytes read, maximum: " + toString(limits.max_bytes_to_read),
|
2016-01-11 21:46:36 +00:00
|
|
|
|
ErrorCodes::TOO_MUCH_BYTES);
|
2013-11-03 05:32:42 +00:00
|
|
|
|
}
|
2015-02-15 06:08:31 +00:00
|
|
|
|
else if (limits.read_overflow_mode == OverflowMode::BREAK)
|
2015-05-10 22:25:19 +00:00
|
|
|
|
{
|
|
|
|
|
/// Для break будем останавливаться только если действительно было прочитано столько строк, а не только предполагается к чтению.
|
|
|
|
|
if ((limits.max_rows_to_read && rows_processed > limits.max_rows_to_read)
|
|
|
|
|
|| (limits.max_bytes_to_read && bytes_processed > limits.max_bytes_to_read))
|
|
|
|
|
{
|
|
|
|
|
cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-15 06:08:31 +00:00
|
|
|
|
else
|
|
|
|
|
throw Exception("Logical error: unknown overflow mode", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
}
|
2013-11-03 05:32:42 +00:00
|
|
|
|
|
2015-03-14 01:48:05 +00:00
|
|
|
|
size_t total_rows = process_list_elem->progress.total_rows;
|
|
|
|
|
|
|
|
|
|
if (limits.min_execution_speed || (total_rows && limits.timeout_before_checking_execution_speed != 0))
|
2015-02-15 06:08:31 +00:00
|
|
|
|
{
|
|
|
|
|
double total_elapsed = info.total_stopwatch.elapsedSeconds();
|
2013-11-03 05:32:42 +00:00
|
|
|
|
|
2015-03-13 21:25:38 +00:00
|
|
|
|
if (total_elapsed > limits.timeout_before_checking_execution_speed.totalMicroseconds() / 1000000.0)
|
2013-11-03 05:32:42 +00:00
|
|
|
|
{
|
2015-03-14 01:48:05 +00:00
|
|
|
|
if (limits.min_execution_speed && rows_processed / total_elapsed < limits.min_execution_speed)
|
2015-03-13 21:25:38 +00:00
|
|
|
|
throw Exception("Query is executing too slow: " + toString(rows_processed / total_elapsed)
|
|
|
|
|
+ " rows/sec., minimum: " + toString(limits.min_execution_speed),
|
|
|
|
|
ErrorCodes::TOO_SLOW);
|
|
|
|
|
|
|
|
|
|
size_t total_rows = process_list_elem->progress.total_rows;
|
|
|
|
|
|
|
|
|
|
/// Если предсказанное время выполнения больше, чем max_execution_time.
|
|
|
|
|
if (limits.max_execution_time != 0 && total_rows)
|
|
|
|
|
{
|
|
|
|
|
double estimated_execution_time_seconds = total_elapsed * (static_cast<double>(total_rows) / rows_processed);
|
|
|
|
|
|
|
|
|
|
if (estimated_execution_time_seconds > limits.max_execution_time.totalSeconds())
|
2015-03-14 01:48:05 +00:00
|
|
|
|
throw Exception("Estimated query execution time (" + toString(estimated_execution_time_seconds) + " seconds)"
|
2015-03-13 21:25:38 +00:00
|
|
|
|
+ " is too long. Maximum: " + toString(limits.max_execution_time.totalSeconds())
|
|
|
|
|
+ ". Estimated rows to process: " + toString(total_rows),
|
|
|
|
|
ErrorCodes::TOO_SLOW);
|
|
|
|
|
}
|
2013-11-03 05:32:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-15 06:08:31 +00:00
|
|
|
|
|
|
|
|
|
if (quota != nullptr && limits.mode == LIMITS_TOTAL)
|
|
|
|
|
{
|
|
|
|
|
quota->checkAndAddReadRowsBytes(time(0), value.rows, value.bytes);
|
|
|
|
|
}
|
2013-11-03 05:32:42 +00:00
|
|
|
|
}
|
2012-05-17 19:15:53 +00:00
|
|
|
|
}
|
2014-08-22 02:31:54 +00:00
|
|
|
|
|
2011-08-27 22:43:31 +00:00
|
|
|
|
|
2012-10-17 19:55:56 +00:00
|
|
|
|
void IProfilingBlockInputStream::cancel()
|
|
|
|
|
{
|
2015-03-20 16:20:47 +00:00
|
|
|
|
bool old_val = false;
|
|
|
|
|
if (!is_cancelled.compare_exchange_strong(old_val, true, std::memory_order_seq_cst, std::memory_order_relaxed))
|
2012-11-10 05:13:46 +00:00
|
|
|
|
return;
|
2012-10-17 19:55:56 +00:00
|
|
|
|
|
2015-01-18 08:25:56 +00:00
|
|
|
|
for (auto & child : children)
|
|
|
|
|
if (IProfilingBlockInputStream * p_child = dynamic_cast<IProfilingBlockInputStream *>(&*child))
|
|
|
|
|
p_child->cancel();
|
2012-10-17 19:55:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-05-09 15:15:45 +00:00
|
|
|
|
void IProfilingBlockInputStream::setProgressCallback(ProgressCallback callback)
|
|
|
|
|
{
|
2012-05-17 19:15:53 +00:00
|
|
|
|
progress_callback = callback;
|
2014-08-22 02:31:54 +00:00
|
|
|
|
|
2015-01-18 08:25:56 +00:00
|
|
|
|
for (auto & child : children)
|
|
|
|
|
if (IProfilingBlockInputStream * p_child = dynamic_cast<IProfilingBlockInputStream *>(&*child))
|
|
|
|
|
p_child->setProgressCallback(callback);
|
2012-05-09 08:16:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-06-21 06:06:04 +00:00
|
|
|
|
void IProfilingBlockInputStream::setProcessListElement(ProcessListElement * elem)
|
2013-11-03 05:32:42 +00:00
|
|
|
|
{
|
|
|
|
|
process_list_elem = elem;
|
|
|
|
|
|
2015-01-18 08:25:56 +00:00
|
|
|
|
for (auto & child : children)
|
|
|
|
|
if (IProfilingBlockInputStream * p_child = dynamic_cast<IProfilingBlockInputStream *>(&*child))
|
|
|
|
|
p_child->setProcessListElement(elem);
|
2013-11-03 05:32:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-09-08 08:27:06 +00:00
|
|
|
|
const Block & IProfilingBlockInputStream::getTotals()
|
2013-09-01 04:55:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (totals)
|
|
|
|
|
return totals;
|
|
|
|
|
|
2015-01-18 08:25:56 +00:00
|
|
|
|
for (auto & child : children)
|
2013-09-01 04:55:41 +00:00
|
|
|
|
{
|
2015-01-18 08:25:56 +00:00
|
|
|
|
if (IProfilingBlockInputStream * p_child = dynamic_cast<IProfilingBlockInputStream *>(&*child))
|
2013-09-01 04:55:41 +00:00
|
|
|
|
{
|
2015-01-18 08:25:56 +00:00
|
|
|
|
const Block & res = p_child->getTotals();
|
2013-09-01 04:55:41 +00:00
|
|
|
|
if (res)
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return totals;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-07 02:03:13 +00:00
|
|
|
|
const Block & IProfilingBlockInputStream::getExtremes() const
|
|
|
|
|
{
|
|
|
|
|
if (extremes)
|
|
|
|
|
return extremes;
|
|
|
|
|
|
2015-01-18 08:25:56 +00:00
|
|
|
|
for (const auto & child : children)
|
2013-09-07 02:03:13 +00:00
|
|
|
|
{
|
2015-01-18 08:25:56 +00:00
|
|
|
|
if (const IProfilingBlockInputStream * p_child = dynamic_cast<const IProfilingBlockInputStream *>(&*child))
|
2013-09-07 02:03:13 +00:00
|
|
|
|
{
|
2015-01-18 08:25:56 +00:00
|
|
|
|
const Block & res = p_child->getExtremes();
|
2013-09-07 02:03:13 +00:00
|
|
|
|
if (res)
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return extremes;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-15 06:08:31 +00:00
|
|
|
|
void IProfilingBlockInputStream::collectTotalRowsApprox()
|
|
|
|
|
{
|
|
|
|
|
if (collected_total_rows_approx)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
collected_total_rows_approx = true;
|
|
|
|
|
|
|
|
|
|
for (auto & child : children)
|
|
|
|
|
{
|
|
|
|
|
if (IProfilingBlockInputStream * p_child = dynamic_cast<IProfilingBlockInputStream *>(&*child))
|
|
|
|
|
{
|
|
|
|
|
p_child->collectTotalRowsApprox();
|
|
|
|
|
total_rows_approx += p_child->total_rows_approx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IProfilingBlockInputStream::collectAndSendTotalRowsApprox()
|
|
|
|
|
{
|
|
|
|
|
if (collected_total_rows_approx)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
collectTotalRowsApprox();
|
|
|
|
|
progressImpl(Progress(0, 0, total_rows_approx));
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-01 04:55:41 +00:00
|
|
|
|
|
2011-08-27 22:43:31 +00:00
|
|
|
|
}
|