Skip to content

Commit

Permalink
[ODBC-120] Fix of performance issue. We did redundant calls of
Browse files Browse the repository at this point in the history
mysql_stmt_data_seek. They are neede for different type of cursors,
positioned operation, array fetch etc. But in general forward_only
cursor it only significantly slows down execution.
  • Loading branch information
lawrinn committed Nov 23, 2017
1 parent c5659d5 commit d0523b2
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions ma_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -3916,15 +3916,23 @@ SQLRETURN MADB_RefreshDynamicCursor(MADB_Stmt *Stmt)
Stmt->LastRowFetched= LastRowFetched;
Stmt->AffectedRows= AffectedRows;

MADB_StmtDataSeek(Stmt, Stmt->Cursor.Position);
if (SQL_SUCCEEDED(ret))
{
/* We need to prevent that bound variables will be overwritten
by fetching data again: For subsequent GetData we need to update
bind->row_ptr */
Stmt->Methods->RefreshRowPtrs(Stmt);
if (Stmt->Cursor.Position > 0)
{
/* Looks likt this is not needed altogether. Leaving it commented out, so far */
/*MADB_StmtDataSeek(Stmt, Stmt->Cursor.Position);
if (SQL_SUCCEEDED(ret))
{*/
/* We need to prevent that bound variables will be overwritten
by fetching data again: For subsequent GetData we need to update
bind->row_ptr */
/*Stmt->Methods->RefreshRowPtrs(Stmt);
MADB_StmtDataSeek(Stmt, Stmt->Cursor.Position);
MADB_StmtDataSeek(Stmt, Stmt->Cursor.Position);
}*/
}
else
{
Stmt->Cursor.Position= 0;
}
return ret;
}
Expand Down Expand Up @@ -4294,7 +4302,7 @@ SQLRETURN MADB_StmtSetPos(MADB_Stmt *Stmt, SQLSETPOSIROW RowNumber, SQLUSMALLINT
SQLRETURN MADB_StmtFetchScroll(MADB_Stmt *Stmt, SQLSMALLINT FetchOrientation,
SQLLEN FetchOffset)
{
SQLRETURN ret;
SQLRETURN ret= SQL_SUCCESS;
SQLLEN Position;
SQLLEN RowsProcessed;

Expand Down Expand Up @@ -4389,10 +4397,20 @@ SQLRETURN MADB_StmtFetchScroll(MADB_Stmt *Stmt, SQLSMALLINT FetchOrientation,
}
if (Position < 0 || (my_ulonglong)Position > mysql_stmt_num_rows(Stmt->stmt) - 1)
{
/* We need to put cursor before RS start, not only return error */
if (Position < 0)
{
MADB_StmtDataSeek(Stmt, 0);
}
return SQL_NO_DATA;
}

if (FetchOrientation != SQL_FETCH_NEXT || RowsProcessed > 1 || Stmt->Options.CursorType == SQL_CURSOR_DYNAMIC)
{
ret= MADB_StmtDataSeek(Stmt, Stmt->Cursor.Position);
}

ret= MADB_StmtDataSeek(Stmt, Stmt->Cursor.Position);
/* Assuming, that ret before previous "if" was SQL_SUCCESS */
if (ret == SQL_SUCCESS)
{
ret= Stmt->Methods->Fetch(Stmt);
Expand Down

0 comments on commit d0523b2

Please sign in to comment.