Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::ExecuteFunctionState Struct Reference
Inheritance diagram for duckdb::ExecuteFunctionState:
Collaboration diagram for duckdb::ExecuteFunctionState:

Public Member Functions

 ExecuteFunctionState (const Expression &expr, ExpressionExecutorState &root)
bool TryExecuteDictionaryExpression (const BoundFunctionExpression &expr, DataChunk &args, ExpressionState &state, Vector &result)
void ResetDictionaryStates () override
 Reset any cached dictionary expression states in this expression state and its children.
Public Member Functions inherited from duckdb::ExpressionState
 ExpressionState (const Expression &expr, ExpressionExecutorState &root)
void AddChild (Expression &child_expr)
void Finalize ()
Allocator & GetAllocator ()
bool HasContext ()
DUCKDB_API ClientContext & GetContext ()
void Verify (ExpressionExecutorState &root)
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static optional_ptr< FunctionLocalState > GetFunctionState (ExpressionState &state)

Public Attributes

unique_ptr< FunctionLocalState > local_state
Public Attributes inherited from duckdb::ExpressionState
const Expression & expr
ExpressionExecutorState & root
vector< unique_ptr< ExpressionState > > child_states
vector< LogicalType > types
DataChunk intermediate_chunk
vector< bool > initialize

Private Attributes

optional_idx input_col_idx
buffer_ptr< VectorChildBuffer > output_dictionary
 Vector holding the expression executed on the entire dictionary.
string current_input_dictionary_id
 ID of the input dictionary Vector.

Constructor & Destructor Documentation

◆ ExecuteFunctionState()

duckdb::ExecuteFunctionState::ExecuteFunctionState ( const Expression & expr,
ExpressionExecutorState & root )
149014 : ExpressionState(expr, root) {
149015 // Check if the expression is eligible for dictionary optimization
149016 if (!expr.IsConsistent() || expr.IsVolatile() || expr.CanThrow()) {
149017 return; // Needs to be consistent, non-volatile, and non-throwing
149018 }
149019
149020 if (expr.return_type.InternalType() == PhysicalType::STRUCT) {
149021 return; // FIXME: get this working for STRUCT
149022 }
149023
149024 // Set input_col_idx accordingly, marking the expression as eligible for dictionary optimization
149025 switch (expr.GetExpressionClass()) {
149026 case ExpressionClass::BOUND_FUNCTION: {
149027 auto &bound_function = expr.Cast<BoundFunctionExpression>();
149028 auto &children = bound_function.children;
149029 for (idx_t child_idx = 0; child_idx < children.size(); child_idx++) {
149030 auto &child = *children[child_idx];
149031 if (child.IsFoldable()) {
149032 continue; // Constant
149033 }
149034 if (input_col_idx.IsValid()) {
149035 input_col_idx.SetInvalid(); // Found more than 1 non-constant
149036 break;
149037 }
149038 if (child.return_type.InternalType() == PhysicalType::STRUCT) {
149039 break; // FIXME
149040 }
149041 input_col_idx = child_idx;
149042 }
149043 break;
149044 }
149045 default:
149046 break;
149047 }
149048}
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
optional_idx input_col_idx
Definition duckdb.hpp:14095

◆ ~ExecuteFunctionState()

duckdb::ExecuteFunctionState::~ExecuteFunctionState ( )
override
149050 {
149051}

Member Function Documentation

◆ GetFunctionState()

optional_ptr< FunctionLocalState > duckdb::ExecuteFunctionState::GetFunctionState ( ExpressionState & state)
inlinestatic
14079 {
14080 return state.Cast<ExecuteFunctionState>().local_state.get();
14081 }

◆ TryExecuteDictionaryExpression()

bool duckdb::ExecuteFunctionState::TryExecuteDictionaryExpression ( const BoundFunctionExpression & expr,
DataChunk & args,
ExpressionState & state,
Vector & result )
149054 {
149055 static constexpr idx_t MAX_DICTIONARY_SIZE_THRESHOLD = 20000;
149056 static constexpr double CHUNK_FILL_RATIO_THRESHOLD = 0.5;
149057
149058 if (!input_col_idx.IsValid()) {
149059 return false; // This expression is not eligible for dictionary optimization
149060 }
149061
149062 // Figure out if we can do the optimization
149063 const auto &unary_input = args.data[input_col_idx.GetIndex()];
149064 if (unary_input.GetVectorType() != VectorType::DICTIONARY_VECTOR) {
149065 return false; // Not a dictionary
149066 }
149067
149068 const auto input_dictionary_size_opt = DictionaryVector::DictionarySize(unary_input);
149069 const auto &input_dictionary_id = DictionaryVector::DictionaryId(unary_input);
149070 if (!input_dictionary_size_opt.IsValid() || input_dictionary_id.empty()) {
149071 return false; // Not a dictionary that comes from storage
149072 }
149073
149074 const auto input_dictionary_size = input_dictionary_size_opt.GetIndex();
149075 if (input_dictionary_size >= MAX_DICTIONARY_SIZE_THRESHOLD) {
149076 return false; // Dictionary is too large, bail
149077 }
149078
149079 if (!output_dictionary || current_input_dictionary_id != input_dictionary_id) {
149080 // We haven't seen this dictionary before
149081 const auto chunk_fill_ratio = static_cast<double>(args.size()) / STANDARD_VECTOR_SIZE;
149082 if (input_dictionary_size > STANDARD_VECTOR_SIZE && chunk_fill_ratio <= CHUNK_FILL_RATIO_THRESHOLD) {
149083 // If the dictionary size is <= STANDARD_VECTOR_SIZE, we always do the optimization
149084 // If it's greater, we only do the optimization if the chunk is more than 50% full
149085 // This protects the optimization against selective filters
149086 return false;
149087 }
149088
149089 // We can do dictionary optimization! Re-initialize
149090 output_dictionary = DictionaryVector::CreateReusableDictionary(result.GetType(), input_dictionary_size);
149091 current_input_dictionary_id = input_dictionary_id;
149092
149093 // Set up the input chunk
149094 DataChunk input_chunk;
149095 input_chunk.InitializeEmpty(args.GetTypes());
149096 for (idx_t col_idx = 0; col_idx < args.ColumnCount(); col_idx++) {
149097 if (col_idx != input_col_idx.GetIndex()) {
149098 input_chunk.data[col_idx].Reference(args.data[col_idx]);
149099 }
149100 }
149101
149102 // Loop over the dictionary, executing at most STANDARD_VECTOR_SIZE at a time
149103 for (idx_t offset = 0; offset < input_dictionary_size; offset += STANDARD_VECTOR_SIZE) {
149104 const auto count = MinValue<idx_t>(input_dictionary_size - offset, STANDARD_VECTOR_SIZE);
149105
149106 // Offset the input dictionary
149107 Vector offset_input(DictionaryVector::Child(unary_input), offset, offset + count);
149108 input_chunk.data[input_col_idx.GetIndex()].Reference(offset_input);
149109 input_chunk.SetCardinality(count);
149110
149111 // Execute, storing the result in an intermediate vector, and copying it to the output dictionary
149112 Vector output_intermediate(result.GetType());
149113 expr.function.GetFunctionCallback()(input_chunk, state, output_intermediate);
149114 VectorOperations::Copy(output_intermediate, output_dictionary->data, count, 0, offset);
149115 }
149116 }
149117
149118 // Result references the dictionary
149119 result.Dictionary(output_dictionary, DictionaryVector::SelVector(unary_input));
149120
149121 return true;
149122}
DUCKDB_API void InitializeEmpty(const vector< LogicalType > &types)
Initializes a DataChunk with the given types and without any vector data allocation.
Definition duckdb.cpp:116783
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
string current_input_dictionary_id
ID of the input dictionary Vector.
Definition duckdb.hpp:14099
buffer_ptr< VectorChildBuffer > output_dictionary
Vector holding the expression executed on the entire dictionary.
Definition duckdb.hpp:14097

◆ ResetDictionaryStates()

void duckdb::ExecuteFunctionState::ResetDictionaryStates ( )
overridevirtual

Reset any cached dictionary expression states in this expression state and its children.

Reimplemented from duckdb::ExpressionState.

149124 {
149125 // Clear the cached dictionary information
149127 output_dictionary.reset();
149128
149129 for (const auto &child_state : child_states) {
149130 child_state->ResetDictionaryStates();
149131 }
149132}
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ input_col_idx

optional_idx duckdb::ExecuteFunctionState::input_col_idx
private

The column index of the "unary" input column that may be a dictionary vector Only valid when the expression is eligible for the dictionary expression optimization This is the case when the input is "practically unary", i.e., only one non-const input column


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