Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/dpiStmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,17 +555,23 @@ static int dpiStmt__execute(dpiStmt *stmt, uint32_t numIters,
var->error = error;
}

// for queries, set the OCI prefetch to a fixed value; this prevents an
// for queries, set the OCI prefetch to a fixed max. value; this prevents an
// additional round trip for single row fetches while avoiding the overhead
// of copying from the OCI prefetch buffer to our own buffers for larger
// fetches
// of copying from the OCI prefetch buffer to our own buffers for larger fetches
// but allow the execute to prefetch only single row for example from pipelined
// table functions that yield rows slowly
if (stmt->statementType == DPI_STMT_TYPE_SELECT) {
prefetchSize = DPI_PREFETCH_ROWS_DEFAULT;
if (stmt->fetchArraySize >= DPI_PREFETCH_ROWS_DEFAULT)
prefetchSize = DPI_PREFETCH_ROWS_DEFAULT;
else
prefetchSize = stmt->fetchArraySize;
if (dpiOci__attrSet(stmt->handle, DPI_OCI_HTYPE_STMT, &prefetchSize,
sizeof(prefetchSize), DPI_OCI_ATTR_PREFETCH_ROWS,
"set prefetch rows", error) < 0)
return DPI_FAILURE;
}
} else
prefetchSize = 0;

// clear batch errors from any previous execution
dpiStmt__clearBatchErrors(stmt);
Expand All @@ -588,6 +594,19 @@ static int dpiStmt__execute(dpiStmt *stmt, uint32_t numIters,
return DPI_FAILURE;
}

// reset prefetch size to 0 to only take fetchArraySize into account
// for subsequent fetches to be able to request/fetch exactly fetchArraySize
// rows from server and to avoid the overhead of copying from the OCI prefetch
// buffer to our own buffer for each fetch
// small drawback of change: the small look-ahead for end-of-data is disabled
if (prefetchSize != 0) {
prefetchSize = 0;
if (dpiOci__attrSet(stmt->handle, DPI_OCI_HTYPE_STMT, &prefetchSize,
sizeof(prefetchSize), DPI_OCI_ATTR_PREFETCH_ROWS,
"reset prefetch rows", error) < 0)
return DPI_FAILURE;
}

// for all bound variables, transfer data from Oracle buffer structures to
// dpiData structures; OCI doesn't provide a way of knowing if a variable
// is an out variable so do this for all of them when this is a possibility
Expand Down