2014-03-04 11:26:55 +00:00
|
|
|
|
#include <DB/DataStreams/CreatingSetsBlockInputStream.h>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Block CreatingSetsBlockInputStream::readImpl()
|
|
|
|
|
{
|
|
|
|
|
Block res;
|
|
|
|
|
|
|
|
|
|
if (!created)
|
|
|
|
|
{
|
2014-06-12 04:04:47 +00:00
|
|
|
|
for (auto & set : sets)
|
2014-03-04 11:26:55 +00:00
|
|
|
|
{
|
|
|
|
|
createSet(set);
|
|
|
|
|
if (isCancelled())
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2014-06-12 04:04:47 +00:00
|
|
|
|
|
|
|
|
|
for (auto & join : joins)
|
|
|
|
|
{
|
|
|
|
|
createJoin(join);
|
|
|
|
|
if (isCancelled())
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 11:26:55 +00:00
|
|
|
|
created = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isCancelled())
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
|
|
return children.back()->read();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-12 04:04:47 +00:00
|
|
|
|
void CreatingSetsBlockInputStream::createSet(SetPtr & set)
|
2014-03-04 11:26:55 +00:00
|
|
|
|
{
|
|
|
|
|
LOG_TRACE(log, "Creating set");
|
|
|
|
|
Stopwatch watch;
|
|
|
|
|
|
|
|
|
|
while (Block block = set->getSource()->read())
|
|
|
|
|
{
|
|
|
|
|
if (isCancelled())
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(log, "Query was cancelled during set creation");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!set->insertFromBlock(block))
|
|
|
|
|
{
|
|
|
|
|
if (IProfilingBlockInputStream * profiling_in = dynamic_cast<IProfilingBlockInputStream *>(&*set->getSource()))
|
|
|
|
|
profiling_in->cancel();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logProfileInfo(watch, *set->getSource(), set->size());
|
|
|
|
|
set->setSource(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-12 04:04:47 +00:00
|
|
|
|
void CreatingSetsBlockInputStream::createJoin(JoinPtr & join)
|
|
|
|
|
{
|
|
|
|
|
LOG_TRACE(log, "Creating join");
|
|
|
|
|
Stopwatch watch;
|
|
|
|
|
|
|
|
|
|
while (Block block = join->getSource()->read())
|
|
|
|
|
{
|
|
|
|
|
if (isCancelled())
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(log, "Query was cancelled during join creation");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!join->insertFromBlock(block))
|
|
|
|
|
{
|
|
|
|
|
if (IProfilingBlockInputStream * profiling_in = dynamic_cast<IProfilingBlockInputStream *>(&*join->getSource()))
|
|
|
|
|
profiling_in->cancel();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logProfileInfo(watch, *join->getSource(), join->size());
|
|
|
|
|
join->setSource(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 11:26:55 +00:00
|
|
|
|
|
|
|
|
|
void CreatingSetsBlockInputStream::logProfileInfo(Stopwatch & watch, IBlockInputStream & in, size_t entries)
|
|
|
|
|
{
|
|
|
|
|
/// Выведем информацию о том, сколько считано строк и байт.
|
|
|
|
|
size_t rows = 0;
|
|
|
|
|
size_t bytes = 0;
|
|
|
|
|
|
|
|
|
|
in.getLeafRowsBytes(rows, bytes);
|
|
|
|
|
|
|
|
|
|
size_t head_rows = 0;
|
|
|
|
|
if (IProfilingBlockInputStream * profiling_in = dynamic_cast<IProfilingBlockInputStream *>(&in))
|
|
|
|
|
head_rows = profiling_in->getInfo().rows;
|
|
|
|
|
|
|
|
|
|
if (rows != 0)
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG(log, std::fixed << std::setprecision(3)
|
2014-06-12 04:04:47 +00:00
|
|
|
|
<< "Created with " << entries << " entries from " << head_rows << " rows."
|
2014-03-04 11:26:55 +00:00
|
|
|
|
<< " Read " << rows << " rows, " << bytes / 1048576.0 << " MiB in " << watch.elapsedSeconds() << " sec., "
|
|
|
|
|
<< static_cast<size_t>(rows / watch.elapsedSeconds()) << " rows/sec., " << bytes / 1048576.0 / watch.elapsedSeconds() << " MiB/sec.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|