Skip to content

Commit

Permalink
Use guard for GetNextTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-- committed Dec 20, 2024
1 parent 621f5c5 commit 899d84d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/pgduckdb/scan/postgres_table_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PostgresTableReader {
private:
MinimalTuple GetNextWorkerTuple();
void PostgresTableReaderCleanupUnsafe();
TupleTableSlot * GetNextTupleUnsafe();
int ParallelWorkerNumber(Cardinality cardinality);
const char * ExplainScanPlan(QueryDesc *query_desc);
bool CanTableScanRunInParallel(Plan *plan);
Expand Down
11 changes: 8 additions & 3 deletions src/scan/postgres_table_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,29 @@ PostgresTableReader::MarkPlanParallelAware(Plan *plan) {

TupleTableSlot *
PostgresTableReader::GetNextTuple() {
return PostgresMemberGuard(PostgresTableReader::GetNextTupleUnsafe);
}

TupleTableSlot *
PostgresTableReader::GetNextTupleUnsafe() {
if (nreaders > 0) {
MinimalTuple worker_minmal_tuple = GetNextWorkerTuple();
if (HeapTupleIsValid(worker_minmal_tuple)) {
PostgresFunctionGuard(ExecStoreMinimalTuple, worker_minmal_tuple, slot, false);
ExecStoreMinimalTuple(worker_minmal_tuple, slot, false);
return slot;
}
} else {
std::lock_guard<std::mutex> lock(GlobalProcessLock::GetLock());
PostgresScopedStackReset scoped_stack_reset;
table_scan_query_desc->estate->es_query_dsa = parallel_executor_info ? parallel_executor_info->area : NULL;
TupleTableSlot *thread_scan_slot = PostgresFunctionGuard(ExecProcNode, table_scan_planstate);
TupleTableSlot *thread_scan_slot = ExecProcNode(table_scan_planstate);
table_scan_query_desc->estate->es_query_dsa = NULL;
if (!TupIsNull(thread_scan_slot)) {
return thread_scan_slot;
}
}

return PostgresFunctionGuard(ExecClearTuple, slot);
return ExecClearTuple(slot);
}

MinimalTuple
Expand Down

0 comments on commit 899d84d

Please sign in to comment.