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::DuckIndexScanState Class Reference
Inheritance diagram for duckdb::DuckIndexScanState:
Collaboration diagram for duckdb::DuckIndexScanState:

Public Member Functions

 DuckIndexScanState (ClientContext &context, const FunctionData *bind_data_p)
unique_ptr< LocalTableFunctionState > InitLocalState (ExecutionContext &context, TableFunctionInitInput &input) override
void TableScanFunc (ClientContext &context, TableFunctionInput &data_p, DataChunk &output) override
double TableScanProgress (ClientContext &context, const FunctionData *bind_data_p) const override
OperatorPartitionData TableScanGetPartitionData (ClientContext &context, TableFunctionGetPartitionInput &input) override
idx_t TableScanRowsScanned (LocalTableFunctionState &state) override
Public Member Functions inherited from duckdb::TableScanGlobalState
 TableScanGlobalState (ClientContext &context, const FunctionData *bind_data_p)
idx_t MaxThreads () const override
bool CanRemoveFilterColumns () const
Public Member Functions inherited from duckdb::GlobalTableFunctionState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Public Attributes

atomic< idx_t > next_batch_index
 The batch index of the next Sink. Also determines the offset of the next chunk. I.e., offset = next_batch_index * STANDARD_VECTOR_SIZE.
ArenaAllocator arena
 The arena allocator containing the memory of the row IDs.
row_t * row_ids
 A pointer to the row IDs.
idx_t row_id_count
 The number of scanned row IDs.
vector< StorageIndex > column_ids
 The column IDs of the to-be-scanned columns.
bool finished_first_phase
 True, if no more row IDs must be scanned.
bool started_last_phase
mutex index_scan_lock
 Synchronize changes to the global index scan state.
unique_ptr< StorageLockKey > vacuum_lock
 Synchronize <ART version, SegmentTree<RowGroup>> when vacuum_rebuild_indexes is enabled (since ART indexes are rebuilt during vacuuming with this setting).
Public Attributes inherited from duckdb::TableScanGlobalState
idx_t max_threads
 The maximum number of threads for this table scan.
vector< idx_t > projection_ids
 The projected columns of this table scan.
vector< LogicalType > scanned_types
 The types of all scanned columns.

Additional Inherited Members

Static Public Attributes inherited from duckdb::GlobalTableFunctionState
static constexpr const int64_t MAX_THREADS = 999999999

Constructor & Destructor Documentation

◆ DuckIndexScanState()

duckdb::DuckIndexScanState::DuckIndexScanState ( ClientContext & context,
const FunctionData * bind_data_p )
inline
251221 : TableScanGlobalState(context, bind_data_p), next_batch_index(0), arena(Allocator::Get(context)),
251222 row_ids(nullptr), row_id_count(0), finished_first_phase(false), started_last_phase(false) {
251223 }
ArenaAllocator arena
The arena allocator containing the memory of the row IDs.
Definition duckdb.cpp:251229
row_t * row_ids
A pointer to the row IDs.
Definition duckdb.cpp:251231
bool finished_first_phase
True, if no more row IDs must be scanned.
Definition duckdb.cpp:251237
atomic< idx_t > next_batch_index
The batch index of the next Sink. Also determines the offset of the next chunk. I....
Definition duckdb.cpp:251227
idx_t row_id_count
The number of scanned row IDs.
Definition duckdb.cpp:251233

Member Function Documentation

◆ InitLocalState()

unique_ptr< LocalTableFunctionState > duckdb::DuckIndexScanState::InitLocalState ( ExecutionContext & context,
TableFunctionInitInput & input )
inlineoverridevirtual

Implements duckdb::TableScanGlobalState.

251247 {
251248 auto l_state = make_uniq<IndexScanLocalState>();
251249 if (input.CanRemoveFilterColumns()) {
251250 l_state->all_columns.Initialize(context.client, scanned_types);
251251 }
251252 l_state->scan_state.options.force_fetch_row = ClientConfig::GetConfig(context.client).force_fetch_row;
251253
251254 // Initialize the local storage scan.
251255 auto &bind_data = input.bind_data->Cast<TableScanBindData>();
251256 auto &duck_table = bind_data.table.Cast<DuckTableEntry>();
251257 auto &storage = duck_table.GetStorage();
251258 auto &local_storage = LocalStorage::Get(context.client, duck_table.catalog);
251259
251260 for (const auto &col_idx : input.column_indexes) {
251261 l_state->column_ids.push_back(bind_data.table.GetStorageIndex(col_idx));
251262 }
251263 l_state->scan_state.Initialize(l_state->column_ids, context.client, input.filters.get());
251264 local_storage.InitializeScan(storage, l_state->scan_state.local_state, input.filters);
251265 return std::move(l_state);
251266 }
vector< LogicalType > scanned_types
The types of all scanned columns.
Definition duckdb.cpp:251199

◆ TableScanFunc()

void duckdb::DuckIndexScanState::TableScanFunc ( ClientContext & context,
TableFunctionInput & data_p,
DataChunk & output )
inlineoverridevirtual

Implements duckdb::TableScanGlobalState.

251268 {
251269 auto &bind_data = data_p.bind_data->Cast<TableScanBindData>();
251270 auto &duck_table = bind_data.table.Cast<DuckTableEntry>();
251271 auto &tx = DuckTransaction::Get(context, duck_table.catalog);
251272 auto &storage = duck_table.GetStorage();
251273 auto &l_state = data_p.local_state->Cast<IndexScanLocalState>();
251274
251275 enum class ExecutionPhase { NONE = 0, STORAGE = 1, LOCAL_STORAGE = 2 };
251276
251277 // We might need to loop back, so while (true)
251278 while (true) {
251279 idx_t scan_count = 0;
251280 idx_t offset = 0;
251281
251282 // Phase selection
251283 auto phase_to_be_performed = ExecutionPhase::NONE;
251284 {
251285 // Synchronize changes to the shared global state.
251286 lock_guard<mutex> l(index_scan_lock);
251287 if (!finished_first_phase) {
251288 l_state.batch_index = next_batch_index;
251290
251291 offset = l_state.batch_index * STANDARD_VECTOR_SIZE;
251292 auto remaining = row_id_count - offset;
251293 scan_count = remaining <= STANDARD_VECTOR_SIZE ? remaining : STANDARD_VECTOR_SIZE;
251294 finished_first_phase = remaining <= STANDARD_VECTOR_SIZE ? true : false;
251295 phase_to_be_performed = ExecutionPhase::STORAGE;
251296 } else if (!started_last_phase) {
251297 // First thread to get last phase, great, set l_state's in_charge_of_final_stretch, so same thread
251298 // will be on again
251299 started_last_phase = true;
251300 l_state.in_charge_of_final_stretch = true;
251301 phase_to_be_performed = ExecutionPhase::LOCAL_STORAGE;
251302 } else if (l_state.in_charge_of_final_stretch) {
251303 phase_to_be_performed = ExecutionPhase::LOCAL_STORAGE;
251304 }
251305 }
251306
251307 switch (phase_to_be_performed) {
251308 case ExecutionPhase::NONE: {
251309 // No work to be picked up
251310 return;
251311 }
251312 case ExecutionPhase::STORAGE: {
251313 // Scan (in parallel) storage
251314 auto row_id_data = reinterpret_cast<data_ptr_t>(row_ids + offset);
251315 Vector local_vector(LogicalType::ROW_TYPE, row_id_data);
251316
251317 if (CanRemoveFilterColumns()) {
251318 l_state.all_columns.Reset();
251319 storage.Fetch(tx, l_state.all_columns, column_ids, local_vector, scan_count, l_state.fetch_state);
251320 output.ReferenceColumns(l_state.all_columns, projection_ids);
251321 } else {
251322 storage.Fetch(tx, output, column_ids, local_vector, scan_count, l_state.fetch_state);
251323 }
251324
251325 l_state.rows_scanned += scan_count;
251326
251327 if (output.size() == 0) {
251328 if (data_p.results_execution_mode == AsyncResultsExecutionMode::TASK_EXECUTOR) {
251329 // We can avoid looping, and just return as appropriate
251330 data_p.async_result = AsyncResultType::HAVE_MORE_OUTPUT;
251331 return;
251332 }
251333
251334 // output is empty, loop back, since there might be results to be picked up from LOCAL_STORAGE phase
251335 continue;
251336 }
251337 return;
251338 }
251339 case ExecutionPhase::LOCAL_STORAGE: {
251340 // Scan (sequentially, always same logical thread) local_storage
251341 auto &local_storage = LocalStorage::Get(tx);
251342 {
251343 if (CanRemoveFilterColumns()) {
251344 l_state.all_columns.Reset();
251345 local_storage.Scan(l_state.scan_state.local_state, column_ids, l_state.all_columns);
251346 output.ReferenceColumns(l_state.all_columns, projection_ids);
251347 } else {
251348 local_storage.Scan(l_state.scan_state.local_state, column_ids, output);
251349 }
251350 l_state.rows_scanned += output.size();
251351 }
251352 return;
251353 }
251354 }
251355 }
251356 }
mutex index_scan_lock
Synchronize changes to the global index scan state.
Definition duckdb.cpp:251240
vector< StorageIndex > column_ids
The column IDs of the to-be-scanned columns.
Definition duckdb.cpp:251235
vector< idx_t > projection_ids
The projected columns of this table scan.
Definition duckdb.cpp:251197
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ TableScanProgress()

double duckdb::DuckIndexScanState::TableScanProgress ( ClientContext & context,
const FunctionData * bind_data_p ) const
inlineoverridevirtual

Implements duckdb::TableScanGlobalState.

251358 {
251359 if (row_id_count == 0) {
251360 return 100;
251361 }
251362 auto scanned_rows = next_batch_index * STANDARD_VECTOR_SIZE;
251363 auto percentage = 100 * (static_cast<double>(scanned_rows) / static_cast<double>(row_id_count));
251364 return percentage > 100 ? 100 : percentage;
251365 }

◆ TableScanGetPartitionData()

OperatorPartitionData duckdb::DuckIndexScanState::TableScanGetPartitionData ( ClientContext & context,
TableFunctionGetPartitionInput & input )
inlineoverridevirtual

Implements duckdb::TableScanGlobalState.

251368 {
251369 auto &l_state = input.local_state->Cast<IndexScanLocalState>();
251370 return OperatorPartitionData(l_state.batch_index);
251371 }

◆ TableScanRowsScanned()

idx_t duckdb::DuckIndexScanState::TableScanRowsScanned ( LocalTableFunctionState & state)
inlineoverridevirtual

Implements duckdb::TableScanGlobalState.

251373 {
251374 auto &l_state = state.Cast<IndexScanLocalState>();
251375 return l_state.rows_scanned;
251376 }

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