1#ifndef SQL_ITERATORS_TIMING_ITERATOR_H_
2#define SQL_ITERATORS_TIMING_ITERATOR_H_
44 using duration = steady_clock::time_point::duration;
53 clock_gettime(CLOCK_MONOTONIC, &tp);
54 return steady_clock::time_point(
56 std::chrono::nanoseconds(tp.tv_nsec)));
58 return steady_clock::now();
107 return std::chrono::duration<double>(dur).count() * 1e3;
158template <
class RealIterator>
161 template <
class... Args>
221template <
class RealIterator,
class... Args>
230 new (
mem_root) RealIterator(thd, std::forward<Args>(args)...));
This class is used in implementing the 'EXPLAIN ANALYZE' command.
Definition: timing_iterator.h:40
uint64_t GetNumRows() const override
The number of rows fetched.
Definition: timing_iterator.h:70
static double DurationToMs(duration dur)
Definition: timing_iterator.h:106
std::chrono::steady_clock steady_clock
Definition: timing_iterator.h:43
uint64_t GetNumInitCalls() const override
The number of loops (i.e number of iterator->Init() calls.
Definition: timing_iterator.h:69
steady_clock::time_point TimeStamp
Definition: timing_iterator.h:45
void IncrementNumRows(uint64_t materialized_rows)
Update the number of rows read.
Definition: timing_iterator.h:84
duration m_elapsed_other_rows
Elapsed time in all calls to m_iterator.Read() for all but the first row.
Definition: timing_iterator.h:129
bool m_first_row
True if we are about to read the first row.
Definition: timing_iterator.h:117
steady_clock::time_point::duration duration
Definition: timing_iterator.h:44
void StopInit(TimeStamp start_time)
Mark the end of an iterator->Init() call.
Definition: timing_iterator.h:73
uint64_t m_num_init_calls
The number of loops.
Definition: timing_iterator.h:111
static TimeStamp Now()
Return current time.
Definition: timing_iterator.h:48
double GetFirstRowMs() const override
Time (in ms) spent fetching the first row.
Definition: timing_iterator.h:62
double GetLastRowMs() const override
Time (in ms) spent fetching the remaining rows.
Definition: timing_iterator.h:65
uint64_t m_num_rows
The number of rows fetched.
Definition: timing_iterator.h:114
duration m_elapsed_first_row
Elapsed time in all calls to m_iterator.Init() and Read() for the first row.
Definition: timing_iterator.h:123
void StopRead(TimeStamp start_time, bool read_ok)
Mark the end of an iterator->Read() call.
Definition: timing_iterator.h:93
Profiling data for an iterator, needed by 'EXPLAIN ANALYZE'.
Definition: row_iterator.h:41
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:82
THD * thd() const
Definition: row_iterator.h:228
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
LEX * lex
Definition: sql_class.h:1001
An iterator template that wraps a RowIterator, such that all calls to Init() and Read() are timed (al...
Definition: timing_iterator.h:159
void SetOverrideProfiler(const IteratorProfiler *profiler) override
Definition: timing_iterator.h:190
RealIterator m_iterator
Definition: timing_iterator.h:211
int Read() override
Read a single row.
Definition: timing_iterator.h:173
RealIterator * real_iterator() override
If this iterator is wrapping a different iterator (e.g.
Definition: timing_iterator.h:198
bool Init() override
Initialize or reinitialize the iterator.
Definition: timing_iterator.h:165
IteratorProfilerImpl m_profiler
This maintains the profiling measurements.
Definition: timing_iterator.h:203
void EndPSIBatchModeIfStarted() override
Ends performance schema batch mode, if started.
Definition: timing_iterator.h:186
void StartPSIBatchMode() override
Start performance schema batch mode, if supported (otherwise ignored).
Definition: timing_iterator.h:185
const IteratorProfiler * GetProfiler() const override
Get profiling data for this iterator (for 'EXPLAIN ANALYZE').
Definition: timing_iterator.h:194
void UnlockRow() override
Definition: timing_iterator.h:184
const IteratorProfiler * m_override_profiler
For iterators over materialized tables we must make profiling measurements in a different way.
Definition: timing_iterator.h:209
const RealIterator * real_iterator() const override
Definition: timing_iterator.h:199
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:181
TimingIterator(THD *thd, Args &&... args)
Definition: timing_iterator.h:162
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
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:477
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:927
Definition: gcs_xcom_synode.h:64
bool is_explain_analyze
Definition: sql_lex.h:3869
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
double seconds()
Definition: task.cc:310
unique_ptr_destroy_only< RowIterator > NewIterator(THD *thd, MEM_ROOT *mem_root, Args &&... args)
Definition: timing_iterator.h:222