taco-db  0.1.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
taco::PlanExecState Class Referenceabstract

PlanExecState is an abstract interface for execution state of various query plan. More...

#include <execution/PlanExecState.h>

Inheritance diagram for taco::PlanExecState:
taco::TreeNode taco::AggregationState taco::CartesianProductState taco::IndexScanState taco::LimitState taco::ProjectionState taco::SelectionState taco::SortState taco::TableDeleteState taco::TableInsertState taco::TableScanState taco::TempTableState

Public Member Functions

template<class ... UniquePtrs>
 PlanExecState (NodeTag tag, UniquePtrs &&...input)
 Base constructor for all execution states. More...
 
virtual ~PlanExecState ()
 Deconstructor of PlanExecState. More...
 
virtual void init ()=0
 Initialize this plan execution state, set m_initialized to true and initialize all corresponding states (including its children) to get ready for query processing. More...
 
virtual bool next_tuple ()=0
 Moves the iterator of this execution state to the next output record. More...
 
virtual std::vector< NullableDatumRefget_record ()=0
 Return the deserialized output record to which this execution state currently points. More...
 
virtual void close ()=0
 Clear internal states, mark we have finish retrieving output records from this execution state, and mark the execution state no longer initialzied. More...
 
virtual Datum save_position () const
 Returns a saved position where this plan execution state is at. More...
 
virtual void rewind ()=0
 Rewind the execution state as if it has just been initialized. More...
 
virtual bool rewind (DatumRef saved_position)
 Rewinds the execution state to the same as the one that was previously saved and returns if the rewinded state is currently at a valid record. More...
 
virtual const PlanNodeget_plan () const =0
 Returns the corresponding plan. More...
 
- Public Member Functions inherited from taco::TreeNode
template<class ... UniquePtrs>
 TreeNode (NodeTag tag, UniquePtrs &&...input)
 
virtual ~TreeNode ()
 
 TreeNode (TreeNode &&)=default
 
TreeNodeoperator= (TreeNode &&)=default
 
 TreeNode (const TreeNode &)=delete
 
TreeNodeoperator= (const TreeNode &)=delete
 
constexpr NodeTag get_tag () const
 
TreeNodeget_input (size_t i) const
 
template<class Node >
Node * get_input_as (size_t i) const
 
std::string to_string () const
 
void node_to_string (std::string &buf, int indent) const
 Prints the node contents to a string buffer. More...
 
const char * node_name () const
 
virtual void node_properties_to_string (std::string &buf, int indent) const =0
 

Protected Member Functions

PlanExecStateget_child (size_t i) const
 Utility function to get the raw pointer of i-th child of this execution state. More...
 

Protected Attributes

bool m_initialized
 

Additional Inherited Members

- Static Public Member Functions inherited from taco::TreeNode
static void append_indent (std::string &buf, int indent)
 

Detailed Description

PlanExecState is an abstract interface for execution state of various query plan.

Each execution state should correspond to a query plan. It operates like as an iterator iterating through the records produced by a plan for a specific query instance.

Constructor & Destructor Documentation

◆ PlanExecState()

template<class ... UniquePtrs>
taco::PlanExecState::PlanExecState ( NodeTag  tag,
UniquePtrs &&...  input 
)
inline

Base constructor for all execution states.

It is marked with a node tag (see include/utils/tree/node_Tags.inc for more details) and unique pointers to all of its children execution states. When just constructed, the execution states are NOT initialized until init() is called.

The unique pointers to its children will be moved to TreeNode internal states after the construction so you don't have to remember it separately.

Note: You can use TAG(ClassName) to get the corresponding tag for a plan execution state. For example, TAG(SelectionState) will give you the tag of SelectionState.

◆ ~PlanExecState()

virtual taco::PlanExecState::~PlanExecState ( )
inlinevirtual

Deconstructor of PlanExecState.

When it is destroyed, you have to make sure this execution state is no longer initialized. Otherwise, its behavior is undefined.

Member Function Documentation

◆ close()

virtual void taco::PlanExecState::close ( )
pure virtual

Clear internal states, mark we have finish retrieving output records from this execution state, and mark the execution state no longer initialzied.

A closed operator may be reopened by calling init() again.

Implemented in taco::TempTableState, taco::TableScanState, taco::TableInsertState, taco::TableDeleteState, taco::SortState, taco::SelectionState, taco::ProjectionState, taco::LimitState, taco::IndexScanState, taco::CartesianProductState, and taco::AggregationState.

◆ get_child()

PlanExecState* taco::PlanExecState::get_child ( size_t  i) const
inlineprotected

Utility function to get the raw pointer of i-th child of this execution state.

◆ get_plan()

virtual const PlanNode* taco::PlanExecState::get_plan ( ) const
pure virtual

◆ get_record()

virtual std::vector<NullableDatumRef> taco::PlanExecState::get_record ( )
pure virtual

Return the deserialized output record to which this execution state currently points.

The deserialized record represented by a vector of NullableDatumRef should be SAFE to access until the next_tuple() is called again on the same execution state.

It should return the first output record after the first next_tuple call. The behavior of calling get_record() before the first next_tuple() is undefined.

Implemented in taco::TempTableState, taco::TableScanState, taco::TableInsertState, taco::TableDeleteState, taco::SortState, taco::SelectionState, taco::ProjectionState, taco::LimitState, taco::IndexScanState, taco::CartesianProductState, and taco::AggregationState.

◆ init()

virtual void taco::PlanExecState::init ( )
pure virtual

Initialize this plan execution state, set m_initialized to true and initialize all corresponding states (including its children) to get ready for query processing.

Implemented in taco::TempTableState, taco::TableScanState, taco::TableInsertState, taco::TableDeleteState, taco::SortState, taco::SelectionState, taco::ProjectionState, taco::LimitState, taco::IndexScanState, taco::CartesianProductState, and taco::AggregationState.

◆ next_tuple()

virtual bool taco::PlanExecState::next_tuple ( )
pure virtual

Moves the iterator of this execution state to the next output record.

Returns true if there is such a record. The caller should be able to get the current deserialized record through get_record() before another next_tuple() is called or the plan execution state is implicitly or explicitly ended. You should make sure memory holding this record is safe (on pinned page or copied somewhere) until the next next_tuple() call.

Implemented in taco::TempTableState, taco::TableScanState, taco::TableInsertState, taco::TableDeleteState, taco::SortState, taco::SelectionState, taco::ProjectionState, taco::LimitState, taco::IndexScanState, taco::CartesianProductState, and taco::AggregationState.

◆ rewind() [1/2]

virtual void taco::PlanExecState::rewind ( )
pure virtual

Rewind the execution state as if it has just been initialized.

Thus, after this call, next_tuple() will trigger another round of scan from the very beginning. Calling rewind() should have the same effect as calling close() followed by another init(), but is usually a more efficient because it may avoid certain memory deallocation/allocation or recomputation.

Note that an operator must support this overload of rewind() even if it does not support rewinding to a saved position.

Implemented in taco::TempTableState, taco::TableScanState, taco::TableInsertState, taco::TableDeleteState, taco::SortState, taco::SelectionState, taco::ProjectionState, taco::LimitState, taco::IndexScanState, taco::CartesianProductState, and taco::AggregationState.

◆ rewind() [2/2]

virtual bool taco::PlanExecState::rewind ( DatumRef  saved_position)
inlinevirtual

Rewinds the execution state to the same as the one that was previously saved and returns if the rewinded state is currently at a valid record.

Calling get_record() on the rewinded object will return the same values for the same record at the time the the saved_position was returned by save_position().

It is undefined if this function is passed a saved_position that was not returned by this plan execution state object.

Reimplemented in taco::TempTableState, taco::TableScanState, taco::SortState, taco::SelectionState, taco::ProjectionState, taco::LimitState, taco::IndexScanState, taco::CartesianProductState, and taco::AggregationState.

◆ save_position()

virtual Datum taco::PlanExecState::save_position ( ) const
inlinevirtual

Returns a saved position where this plan execution state is at.

A call to rewind(DatumRef) with the saved position will rewind the execution state to the same as its current state. Calling get_record() on the rewinded object will return the same values for the same record at the time the save_position() is called. The returned saved position must not be null.

An operator that does not support rewinding to a saved position should never override this function.

Reimplemented in taco::TempTableState, taco::TableScanState, taco::SortState, taco::SelectionState, taco::ProjectionState, taco::LimitState, taco::IndexScanState, taco::CartesianProductState, and taco::AggregationState.

Member Data Documentation

◆ m_initialized

bool taco::PlanExecState::m_initialized
protected

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