OmniSciDB  b24e664e58
 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 emptyLog () const
 
Id getId () const
 
std::string const & getQueryStr () const
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
getConstSessionInfo () const
 
boost::optional< SessionData >
const & 
getSessionData () const
 
bool isLogged () const
 
void logCallStack (std::stringstream &)
 
void setLogged (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 124 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:127
std::string const query_str_
Definition: QueryState.h:128
std::atomic< bool > logged_
Definition: QueryState.h:131
static std::atomic< Id > s_next_id
Definition: QueryState.h:125

+ 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 140 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().

140  {
141  // Trick to call std::make_shared with private constructors.
142  struct EnableMakeShared : public QueryState {
143  EnableMakeShared(ARGS&&... args) : QueryState(std::forward<ARGS>(args)...) {}
144  };
145  return std::make_shared<EnableMakeShared>(std::forward<ARGS>(args)...);
146  }
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:130

+ Here is the caller graph for this function:

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

Definition at line 150 of file QueryState.h.

References events_, and query_str_.

150 { return events_.empty() && query_str_.empty(); }
std::string const query_str_
Definition: QueryState.h:128
std::shared_ptr< Catalog_Namespace::SessionInfo const > query_state::QueryState::getConstSessionInfo ( ) const

Definition at line 75 of file QueryState.cpp.

References session_data_.

Referenced by MapDHandler::execute_rel_alg(), Parser::getResultSet(), Lock_Namespace::parse_to_ra(), MapDHandler::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().

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

+ Here is the caller graph for this function:

Id query_state::QueryState::getId ( ) const
inline

Definition at line 151 of file QueryState.h.

References id_.

151 { return id_; }
std::string const& query_state::QueryState::getQueryStr ( ) const
inline

Definition at line 152 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().

152 { return query_str_; }
std::string const query_str_
Definition: QueryState.h:128

+ Here is the caller graph for this function:

boost::optional<SessionData> const& query_state::QueryState::getSessionData ( ) const
inline

Definition at line 155 of file QueryState.h.

References session_data_.

155 { return session_data_; }
boost::optional< SessionData > session_data_
Definition: QueryState.h:127
bool query_state::QueryState::isLogged ( ) const
inline

Definition at line 156 of file QueryState.h.

References logged_.

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

Definition at line 89 of file QueryState.cpp.

References events_.

Referenced by logCallStack().

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

+ Here is the caller graph for this function:

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

Definition at line 106 of file QueryState.cpp.

References events_, events_mutex_, and logCallStack().

106  {
107  std::lock_guard<std::mutex> lock(events_mutex_);
108  logCallStack(ss, 1, events_.end());
109 }
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
Definition: QueryState.cpp:89
std::mutex events_mutex_
Definition: QueryState.h:130

+ Here is the call graph for this function:

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

Definition at line 158 of file QueryState.h.

References logged_.

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

Friends And Related Function Documentation

friend class QueryStates
friend

Definition at line 159 of file QueryState.h.

Member Data Documentation

Events query_state::QueryState::events_
private

Definition at line 129 of file QueryState.h.

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

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

Definition at line 130 of file QueryState.h.

Referenced by createTimer(), and logCallStack().

Id const query_state::QueryState::id_
private

Definition at line 126 of file QueryState.h.

Referenced by getId().

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

Definition at line 131 of file QueryState.h.

Referenced by isLogged(), and setLogged().

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

Definition at line 128 of file QueryState.h.

Referenced by emptyLog(), and getQueryStr().

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

Definition at line 125 of file QueryState.h.

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

Definition at line 127 of file QueryState.h.

Referenced by getConstSessionInfo(), and getSessionData().


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