OmniSciDB  49c0524acb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
query_state::QueryState Class Reference

#include <QueryState.h>

+ Inheritance diagram for query_state::QueryState:
+ Collaboration diagram for query_state::QueryState:

Public Member Functions

QueryStateProxy createQueryStateProxy ()
 
QueryStateProxy createQueryStateProxy (Events::iterator parent)
 
Timer createTimer (char const *event_name, Events::iterator parent)
 
bool empty_log () const
 
Id get_id () const
 
std::string const & get_query_str () const
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
getConstSessionInfo () const
 
SessionData const * get_session_data () const
 
bool is_logged () const
 
void logCallStack (std::stringstream &)
 
void set_logged (bool logged)
 

Static Public Member Functions

template<typename... ARGS>
static std::shared_ptr
< QueryState
create (ARGS &&...args)
 

Private Member Functions

void logCallStack (std::stringstream &, unsigned const depth, Events::iterator parent)
 
 QueryState (std::shared_ptr< Catalog_Namespace::SessionInfo const > const &, std::string query_str)
 

Private Attributes

Id const id_
 
boost::optional< SessionDatasession_data_
 
std::string const query_str_
 
Events events_
 
std::mutex events_mutex_
 
std::atomic< bool > logged_
 

Static Private Attributes

static std::atomic< Ids_next_id {0}
 

Friends

class QueryStates
 

Detailed Description

Definition at line 122 of file QueryState.h.

Constructor & Destructor Documentation

query_state::QueryState::QueryState ( std::shared_ptr< Catalog_Namespace::SessionInfo const > const &  session_info,
std::string  query_str 
)
private

Definition at line 53 of file QueryState.cpp.

Referenced by create().

56  : id_(s_next_id++)
57  , session_data_(session_info ? boost::make_optional<SessionData>(session_info)
58  : boost::none)
59  , query_str_(std::move(query_str))
60  , logged_(false) {}
boost::optional< SessionData > session_data_
Definition: QueryState.h:125
std::string const query_str_
Definition: QueryState.h:126
std::atomic< bool > logged_
Definition: QueryState.h:129
static std::atomic< Id > s_next_id
Definition: QueryState.h:123

+ Here is the caller graph for this function:

Member Function Documentation

template<typename... ARGS>
static std::shared_ptr<QueryState> query_state::QueryState::create ( ARGS &&...  args)
inlinestatic

Definition at line 138 of file QueryState.h.

References run-benchmark-import::args, and QueryState().

Referenced by query_state::QueryStates::create(), Parser::InsertIntoTableAsSelectStmt::execute(), Parser::CreateTableAsSelectStmt::execute(), Parser::ExportQueryStmt::execute(), and Parser::CreateViewStmt::execute().

138  {
139  // Trick to call std::make_shared with private constructors.
140  struct EnableMakeShared : public QueryState {
141  EnableMakeShared(ARGS&&... args) : QueryState(std::forward<ARGS>(args)...) {}
142  };
143  return std::make_shared<EnableMakeShared>(std::forward<ARGS>(args)...);
144  }
QueryState(std::shared_ptr< Catalog_Namespace::SessionInfo const > const &, std::string query_str)
Definition: QueryState.cpp:53

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QueryStateProxy query_state::QueryState::createQueryStateProxy ( )

Definition at line 62 of file QueryState.cpp.

References events_.

62  {
63  return createQueryStateProxy(events_.end());
64 }
QueryStateProxy createQueryStateProxy()
Definition: QueryState.cpp:62
QueryStateProxy query_state::QueryState::createQueryStateProxy ( Events::iterator  parent)

Definition at line 66 of file QueryState.cpp.

66  {
67  return QueryStateProxy(*this, parent);
68 }
Timer query_state::QueryState::createTimer ( char const *  event_name,
Events::iterator  parent 
)

Definition at line 70 of file QueryState.cpp.

References events_, and events_mutex_.

Referenced by query_state::QueryStateProxy::createTimer().

70  {
71  std::lock_guard<std::mutex> lock(events_mutex_);
72  return Timer(shared_from_this(), events_.emplace(events_.end(), event_name, parent));
73 }
std::mutex events_mutex_
Definition: QueryState.h:128

+ Here is the caller graph for this function:

bool query_state::QueryState::empty_log ( ) const
inline

Definition at line 148 of file QueryState.h.

References events_, and query_str_.

148 { return events_.empty() && query_str_.empty(); }
std::string const query_str_
Definition: QueryState.h:126
Id query_state::QueryState::get_id ( ) const
inline

Definition at line 149 of file QueryState.h.

References id_.

149 { return id_; }
std::string const& query_state::QueryState::get_query_str ( ) const
inline

Definition at line 150 of file QueryState.h.

References query_str_.

Referenced by MapDHandler::execute_rel_alg_with_filter_push_down(), MapDHandler::sql_execute_impl(), and MapDHandler::validate_rel_alg().

150 { return query_str_; }
std::string const query_str_
Definition: QueryState.h:126

+ Here is the caller graph for this function:

SessionData const * query_state::QueryState::get_session_data ( ) const

Definition at line 75 of file QueryState.cpp.

References session_data_.

75  {
76  return boost::get_pointer(session_data_);
77 }
boost::optional< SessionData > session_data_
Definition: QueryState.h:125
std::shared_ptr< Catalog_Namespace::SessionInfo const > query_state::QueryState::getConstSessionInfo ( ) const

Definition at line 79 of file QueryState.cpp.

References session_data_.

Referenced by MapDHandler::execute_rel_alg(), Parser::getResultSet(), Lock_Namespace::parse_to_ra(), Parser::InsertIntoTableAsSelectStmt::populateData(), Calcite::process(), Calcite::processImpl(), Parser::InsertIntoTableAsSelectStmt::LocalConnector::query(), QueryRunner::anonymous_namespace{QueryRunner.cpp}::run_select_query_with_filter_push_down(), MapDHandler::sql_execute_impl(), and MapDHandler::validate_rel_alg().

80  {
81  if (!session_data_) {
82  throw std::runtime_error("session_info_ was not set for this QueryState.");
83  }
84  if (auto retval = session_data_->session_info.lock()) {
85  return retval;
86  } else {
87  // This can happen for a query on a database that is simultaneously dropped.
88  throw std::runtime_error("session_info requested but has expired.");
89  }
90 }
boost::optional< SessionData > session_data_
Definition: QueryState.h:125

+ Here is the caller graph for this function:

bool query_state::QueryState::is_logged ( ) const
inline

Definition at line 154 of file QueryState.h.

References logged_.

154 { return logged_.load(); }
std::atomic< bool > logged_
Definition: QueryState.h:129
void query_state::QueryState::logCallStack ( std::stringstream &  ss,
unsigned const  depth,
Events::iterator  parent 
)
private

Definition at line 93 of file QueryState.cpp.

References events_.

Referenced by logCallStack().

95  {
96  auto it = parent == events_.end() ? events_.begin() : std::next(parent);
97  for (; it != events_.end(); ++it) {
98  if (it->parent == parent) {
99  auto duration = it->duration(); // std::optional, true if event completed
100  ss << '\n'
101  << std::setw(depth << 1) << ' ' << it->name << ' ' << it->thread_id
102  << " - total time " << (duration ? *duration : -1) << " ms";
103  logCallStack(ss, depth + 1, it);
104  // If events_ is expendable, then this can be put here to speed-up large lists.
105  // it = events_.erase(it); } else { ++it; } (and remove above ++it.)
106  }
107  }
108 }
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
Definition: QueryState.cpp:93

+ Here is the caller graph for this function:

void query_state::QueryState::logCallStack ( std::stringstream &  ss)

Definition at line 110 of file QueryState.cpp.

References events_, events_mutex_, and logCallStack().

110  {
111  std::lock_guard<std::mutex> lock(events_mutex_);
112  logCallStack(ss, 1, events_.end());
113 }
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
Definition: QueryState.cpp:93
std::mutex events_mutex_
Definition: QueryState.h:128

+ Here is the call graph for this function:

void query_state::QueryState::set_logged ( bool  logged)
inline

Definition at line 156 of file QueryState.h.

References logged_.

156 { logged_.store(logged); }
std::atomic< bool > logged_
Definition: QueryState.h:129

Friends And Related Function Documentation

friend class QueryStates
friend

Definition at line 157 of file QueryState.h.

Member Data Documentation

Events query_state::QueryState::events_
private

Definition at line 127 of file QueryState.h.

Referenced by createQueryStateProxy(), createTimer(), empty_log(), and logCallStack().

std::mutex query_state::QueryState::events_mutex_
mutableprivate

Definition at line 128 of file QueryState.h.

Referenced by createTimer(), and logCallStack().

Id const query_state::QueryState::id_
private

Definition at line 124 of file QueryState.h.

Referenced by get_id().

std::atomic<bool> query_state::QueryState::logged_
private

Definition at line 129 of file QueryState.h.

Referenced by is_logged(), and set_logged().

std::string const query_state::QueryState::query_str_
private

Definition at line 126 of file QueryState.h.

Referenced by empty_log(), and get_query_str().

std::atomic< query_state::Id > query_state::QueryState::s_next_id {0}
staticprivate

Definition at line 123 of file QueryState.h.

boost::optional<SessionData> query_state::QueryState::session_data_
private

Definition at line 125 of file QueryState.h.

Referenced by get_session_data(), and getConstSessionInfo().


The documentation for this class was generated from the following files: