OmniSciDB  2e3a973ef4
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< QueryStatecreate (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

◆ QueryState()

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

Definition at line 55 of file QueryState.cpp.

References none.

58  : id_(s_next_id++)
59  , session_data_(session_info ? boost::make_optional<SessionData>(session_info)
60  : boost::none)
61  , query_str_(std::move(query_str))
62  , 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

Member Function Documentation

◆ create()

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.

Referenced by 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:55
+ Here is the caller graph for this function:

◆ createQueryStateProxy() [1/2]

QueryStateProxy query_state::QueryState::createQueryStateProxy ( )

Definition at line 64 of file QueryState.cpp.

References events_.

64  {
65  return createQueryStateProxy(events_.end());
66 }
QueryStateProxy createQueryStateProxy()
Definition: QueryState.cpp:64

◆ createQueryStateProxy() [2/2]

QueryStateProxy query_state::QueryState::createQueryStateProxy ( Events::iterator  parent)

Definition at line 68 of file QueryState.cpp.

68  {
69  return QueryStateProxy(*this, parent);
70 }

◆ createTimer()

Timer query_state::QueryState::createTimer ( char const *  event_name,
Events::iterator  parent 
)

Definition at line 72 of file QueryState.cpp.

References events_, and events_mutex_.

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

◆ emptyLog()

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

Definition at line 150 of file QueryState.h.

150 { return events_.empty() && query_str_.empty(); }
std::string const query_str_
Definition: QueryState.h:128

◆ getConstSessionInfo()

std::shared_ptr< Catalog_Namespace::SessionInfo const > query_state::QueryState::getConstSessionInfo ( ) const

Definition at line 77 of file QueryState.cpp.

References session_data_.

Referenced by Calcite::checkAccessedObjectsPrivileges(), DBHandler::execute_rel_alg(), Parser::LocalConnector::getOuterFragmentCount(), Parser::getResultSet(), DBHandler::parse_to_ra(), Parser::InsertIntoTableAsSelectStmt::populateData(), Calcite::processImpl(), Parser::LocalConnector::query(), and DBHandler::sql_execute_impl().

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

◆ getId()

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

Definition at line 151 of file QueryState.h.

151 { return id_; }

◆ getQueryStr()

std::string const& query_state::QueryState::getQueryStr ( ) const
inline

Definition at line 152 of file QueryState.h.

Referenced by DBHandler::execute_rel_alg_with_filter_push_down(), and DBHandler::sql_execute_impl().

152 { return query_str_; }
std::string const query_str_
Definition: QueryState.h:128
+ Here is the caller graph for this function:

◆ getSessionData()

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

Definition at line 155 of file QueryState.h.

155 { return session_data_; }
boost::optional< SessionData > session_data_
Definition: QueryState.h:127

◆ isLogged()

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

Definition at line 156 of file QueryState.h.

156 { return logged_.load(); }
std::atomic< bool > logged_
Definition: QueryState.h:131

◆ logCallStack() [1/2]

void query_state::QueryState::logCallStack ( std::stringstream &  ss,
unsigned const  depth,
Events::iterator  parent 
)
private

Definition at line 91 of file QueryState.cpp.

References events_.

Referenced by logCallStack().

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

◆ logCallStack() [2/2]

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

Definition at line 108 of file QueryState.cpp.

References events_, events_mutex_, and logCallStack().

108  {
109  std::lock_guard<std::mutex> lock(events_mutex_);
110  logCallStack(ss, 1, events_.end());
111 }
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
Definition: QueryState.cpp:91
std::mutex events_mutex_
Definition: QueryState.h:130
+ Here is the call graph for this function:

◆ setLogged()

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

Definition at line 158 of file QueryState.h.

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

Friends And Related Function Documentation

◆ QueryStates

friend class QueryStates
friend

Definition at line 159 of file QueryState.h.

Member Data Documentation

◆ events_

Events query_state::QueryState::events_
private

Definition at line 129 of file QueryState.h.

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

◆ events_mutex_

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

Definition at line 130 of file QueryState.h.

Referenced by createTimer(), and logCallStack().

◆ id_

Id const query_state::QueryState::id_
private

Definition at line 126 of file QueryState.h.

◆ logged_

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

Definition at line 131 of file QueryState.h.

◆ query_str_

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

Definition at line 128 of file QueryState.h.

◆ s_next_id

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

Definition at line 125 of file QueryState.h.

Referenced by query_state::SessionData::SessionData().

◆ session_data_

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

Definition at line 127 of file QueryState.h.

Referenced by getConstSessionInfo().


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