1#ifndef SQL_ITERATORS_TIMING_ITERATOR_H_
2#define SQL_ITERATORS_TIMING_ITERATOR_H_
43 using duration = steady_clock::time_point::duration;
52 clock_gettime(CLOCK_MONOTONIC, &tp);
53 return steady_clock::time_point(
55 std::chrono::nanoseconds(tp.tv_nsec)));
57 return steady_clock::now();
106 return std::chrono::duration<double>(dur).count() * 1e3;
157template <
class RealIterator>
160 template <
class... Args>
220template <
class RealIterator,
class... Args>
229 new (
mem_root) RealIterator(thd, std::forward<Args>(args)...));
This class is used in implementing the 'EXPLAIN ANALYZE' command.
Definition: timing_iterator.h:39
uint64_t GetNumRows() const override
The number of rows fetched.
Definition: timing_iterator.h:69
static double DurationToMs(duration dur)
Definition: timing_iterator.h:105
std::chrono::steady_clock steady_clock
Definition: timing_iterator.h:42
uint64_t GetNumInitCalls() const override
The number of loops (i.e number of iterator->Init() calls.
Definition: timing_iterator.h:68
steady_clock::time_point TimeStamp
Definition: timing_iterator.h:44
void IncrementNumRows(uint64_t materialized_rows)
Update the number of rows read.
Definition: timing_iterator.h:83
duration m_elapsed_other_rows
Elapsed time in all calls to m_iterator.Read() for all but the first row.
Definition: timing_iterator.h:128
bool m_first_row
True if we are about to read the first row.
Definition: timing_iterator.h:116
steady_clock::time_point::duration duration
Definition: timing_iterator.h:43
void StopInit(TimeStamp start_time)
Mark the end of an iterator->Init() call.
Definition: timing_iterator.h:72
uint64_t m_num_init_calls
The number of loops.
Definition: timing_iterator.h:110
static TimeStamp Now()
Return current time.
Definition: timing_iterator.h:47
double GetFirstRowMs() const override
Time (in ms) spent fetching the first row.
Definition: timing_iterator.h:61
double GetLastRowMs() const override
Time (in ms) spent fetching the remaining rows.
Definition: timing_iterator.h:64
uint64_t m_num_rows
The number of rows fetched.
Definition: timing_iterator.h:113
duration m_elapsed_first_row
Elapsed time in all calls to m_iterator.Init() and Read() for the first row.
Definition: timing_iterator.h:122
void StopRead(TimeStamp start_time, bool read_ok)
Mark the end of an iterator->Read() call.
Definition: timing_iterator.h:92
Profiling data for an iterator, needed by 'EXPLAIN ANALYZE'.
Definition: row_iterator.h:40
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:81
THD * thd() const
Definition: row_iterator.h:227
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
LEX * lex
Definition: sql_class.h:990
An iterator template that wraps a RowIterator, such that all calls to Init() and Read() are timed (al...
Definition: timing_iterator.h:158
void SetOverrideProfiler(const IteratorProfiler *profiler) override
Definition: timing_iterator.h:189
RealIterator m_iterator
Definition: timing_iterator.h:210
int Read() override
Read a single row.
Definition: timing_iterator.h:172
RealIterator * real_iterator() override
If this iterator is wrapping a different iterator (e.g.
Definition: timing_iterator.h:197
bool Init() override
Initialize or reinitialize the iterator.
Definition: timing_iterator.h:164
IteratorProfilerImpl m_profiler
This maintains the profiling measurements.
Definition: timing_iterator.h:202
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: timing_iterator.h:185
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: timing_iterator.h:184
const IteratorProfiler * GetProfiler() const override
Get profiling data for this iterator (for 'EXPLAIN ANALYZE').
Definition: timing_iterator.h:193
void UnlockRow() override
Definition: timing_iterator.h:183
const IteratorProfiler * m_override_profiler
For iterators over materialized tables we must make profiling measurements in a different way.
Definition: timing_iterator.h:208
const RealIterator * real_iterator() const override
Definition: timing_iterator.h:198
void SetNullRowFlag(bool is_null_row) override
Mark the current row buffer as containing a NULL row or not, so that if you read from it and the flag...
Definition: timing_iterator.h:180
TimingIterator(THD *thd, Args &&... args)
Definition: timing_iterator.h:161
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:488
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:909
Definition: varlen_sort.h:183
bool is_explain_analyze
Definition: sql_lex.h:3743
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
double seconds()
Definition: task.cc:309
unique_ptr_destroy_only< RowIterator > NewIterator(THD *thd, MEM_ROOT *mem_root, Args &&... args)
Definition: timing_iterator.h:221