2015-01-18 08:25:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <DataStreams/IBlockStream_fwd.h>
|
|
|
|
#include <Common/Stopwatch.h>
|
|
|
|
|
|
|
|
#include <vector>
|
2015-01-18 08:25:56 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class Block;
|
|
|
|
class ReadBuffer;
|
|
|
|
class WriteBuffer;
|
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
/// Information for profiling. See IBlockInputStream.h
|
2015-01-18 08:25:56 +00:00
|
|
|
struct BlockStreamProfileInfo
|
|
|
|
{
|
2017-06-26 12:30:35 +00:00
|
|
|
/// Info about stream object this profile info refers to.
|
2019-01-23 14:48:50 +00:00
|
|
|
IBlockInputStream * parent = nullptr;
|
2017-06-26 12:30:35 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool started = false;
|
2017-05-13 22:19:04 +00:00
|
|
|
Stopwatch total_stopwatch {CLOCK_MONOTONIC_COARSE}; /// Time with waiting time
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t rows = 0;
|
|
|
|
size_t blocks = 0;
|
|
|
|
size_t bytes = 0;
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
using BlockStreamProfileInfos = std::vector<const BlockStreamProfileInfo *>;
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/// Collect BlockStreamProfileInfo for the nearest sources in the tree named `name`. Example; collect all info for PartialSorting streams.
|
2017-04-01 07:20:54 +00:00
|
|
|
void collectInfosForStreamsWithName(const char * name, BlockStreamProfileInfos & res) const;
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** Get the number of rows if there were no LIMIT.
|
|
|
|
* If there is no LIMIT, 0 is returned.
|
|
|
|
* If the query does not contain ORDER BY, the number can be underestimated - return the number of rows in blocks that were read before LIMIT reached.
|
|
|
|
* If the query contains an ORDER BY, then returns the exact number of rows as if LIMIT is removed from query.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
size_t getRowsBeforeLimit() const;
|
|
|
|
bool hasAppliedLimit() const;
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void update(Block & block);
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Binary serialization and deserialization of main fields.
|
|
|
|
/// Writes only main fields i.e. fields that required by internal transmission protocol.
|
|
|
|
void read(ReadBuffer & in);
|
|
|
|
void write(WriteBuffer & out) const;
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Sets main fields from other object (see methods above).
|
|
|
|
/// If skip_block_size_info if true, then rows, bytes and block fields are ignored.
|
|
|
|
void setFrom(const BlockStreamProfileInfo & rhs, bool skip_block_size_info);
|
2016-01-25 21:40:13 +00:00
|
|
|
|
2015-01-18 08:25:56 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
void calculateRowsBeforeLimit() const;
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/// For these fields we make accessors, because they must be calculated beforehand.
|
|
|
|
mutable bool applied_limit = false; /// Whether LIMIT was applied
|
2017-04-01 07:20:54 +00:00
|
|
|
mutable size_t rows_before_limit = 0;
|
2017-05-13 22:19:04 +00:00
|
|
|
mutable bool calculated_rows_before_limit = false; /// Whether the field rows_before_limit was calculated
|
2015-01-18 08:25:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|