[patch_done] Oracle Prefetch Rows
Posted: 11.03.2012, 09:38
When performing a "select *" query on an Oracle Table with a huge number of fields, I noticed that the query was really slow (several minutes). After contacting our DBA's, they told me to set the Prefetch Rows to a higher number. I could not find this option in ZeosLib (but I might be overlooking it of course), so I added it myself by changing the "PrepareOracleStatement" procedure in "zdbcoracleutils.pas". Simply add a call to "PlainDriver.AttrSet" with the OCI_ATTR_PREFETCH_ROWS option. Example code :
With this option set to 100, the execution time of my query dropped from several minutes to a few seconds. Our DBA's could not see a performance decrease on the server side, so for me this was the perfect solution.
Of course, it is a bad idea to hardcode this in the source, but it would be nice to have this option as it can dramatically improve Oracle performance.
Code: Select all
procedure PrepareOracleStatement(PlainDriver: IZOraclePlainDriver;
SQL: string; Handle: POCIStmt; ErrorHandle: POCIError);
var
Status: Integer;
PrefetchCount: ub4;
begin
PrefetchCount := 100;
PlainDriver.AttrSet(Handle, OCI_HTYPE_STMT, @PrefetchCount, SizeOf(ub4),
OCI_ATTR_PREFETCH_ROWS, ErrorHandle);
Status := PlainDriver.StmtPrepare(Handle, ErrorHandle, PAnsiChar(AnsiString(SQL)),
Length(AnsiString(SQL)), OCI_NTV_SYNTAX, OCI_DEFAULT);
CheckOracleError(PlainDriver, ErrorHandle, Status, lcExecute, SQL);
end;
Of course, it is a bad idea to hardcode this in the source, but it would be nice to have this option as it can dramatically improve Oracle performance.