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
251278 while (true) {
251279 idx_t scan_count = 0;
251281
251282
251283 auto phase_to_be_performed = ExecutionPhase::NONE;
251284 {
251285
251290
251291 offset = l_state.batch_index * STANDARD_VECTOR_SIZE;
251293 scan_count = remaining <= STANDARD_VECTOR_SIZE ? remaining : STANDARD_VECTOR_SIZE;
251295 phase_to_be_performed = ExecutionPhase::STORAGE;
251296 } else if (!started_last_phase) {
251297
251298
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
251310 return;
251311 }
251312 case ExecutionPhase::STORAGE: {
251313
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);
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
251330 data_p.async_result = AsyncResultType::HAVE_MORE_OUTPUT;
251331 return;
251332 }
251333
251334
251335 continue;
251336 }
251337 return;
251338 }
251339 case ExecutionPhase::LOCAL_STORAGE: {
251340
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);
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