Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
Summary:
Changed to convert from UTF8 to UTF16 only once instead of two times.
Changed to clean internal buffers lazily instead of cleaning them each time.
**Design doc/spec**:
**Docs impact**: none
**Preliminary Reviewer(s)**:
**Final Reviewer**:

Test Plan: https://app.circleci.com/pipelines/github/memsql/singlestore-odbc-connector/2777

Reviewers: pmishchenko-ua

Reviewed By: pmishchenko-ua

Subscribers: engineering-list

JIRA Issues: PLAT-6356

Differential Revision: https://grizzly.internal.memcompute.com/D59687
  • Loading branch information
AdalbertMemSQL committed Nov 10, 2022
1 parent 580d888 commit 481421a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ version: 2.1
parameters:
driver-version:
type: string
default: "1.1.0"
default: "1.1.1"

commands:
setup-environment-linux:
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment ver

SET(MARIADB_ODBC_VERSION_MAJOR 1)
SET(MARIADB_ODBC_VERSION_MINOR 1)
SET(MARIADB_ODBC_VERSION_PATCH 0)
SET(MARIADB_ODBC_VERSION_PATCH 1)
SET(MARIADB_ODBC_VERSION_QUALITY "ga")

SET(MARIADB_ODBC_VERSION "01.01.0000")
SET(MARIADB_ODBC_VERSION "01.01.0001")

IF(UNICODE OR NOT ANSI)
MESSAGE(STATUS "Configuring to build Unicode driver")
Expand Down
1 change: 1 addition & 0 deletions ma_odbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ struct st_ma_odbc_stmt
MYSQL_BIND *result;
MYSQL_BIND *params;
int PutParam;
int LastSQLGetDataColumn;
my_bool RebindParams;
my_bool bind_done;
long long AffectedRows;
Expand Down
71 changes: 47 additions & 24 deletions ma_platform_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ int MADB_ConvertAnsi2Unicode(Client_Charset *cc, const char *AnsiString, SQLLEN
{
SQLLEN RequiredLength;
SQLWCHAR *Tmp= UnicodeString;
int rc= 0;

if (LengthIndicator)
*LengthIndicator= 0;
Expand All @@ -195,39 +194,63 @@ int MADB_ConvertAnsi2Unicode(Client_Charset *cc, const char *AnsiString, SQLLEN
if (AnsiLength == SQL_NTS || AnsiLength == -1)
IsNull= 1;

/* calculate required length */
RequiredLength= MultiByteToWideChar(cc->CodePage, 0, AnsiString, IsNull ? -1 : (int)AnsiLength, NULL, 0);

/* Set LengthIndicator */
if (LengthIndicator)
*LengthIndicator= RequiredLength - IsNull;
if (!UnicodeLength)
{
// Return buffer is empty
// Get WideChar length if needed and return
if (LengthIndicator) {
RequiredLength= MultiByteToWideChar(cc->CodePage, 0, AnsiString, IsNull ? -1 : (int)AnsiLength, NULL, 0);
if (RequiredLength < 1)
{
if (Error)
MADB_SetError(Error, MADB_ERR_HY000, "Ansi to Unicode conversion error occurred", GetLastError());
return 1;
}

// Set LengthIndicator
*LengthIndicator= RequiredLength - IsNull;
}
return 0;
}

RequiredLength= MultiByteToWideChar(cc->CodePage, 0, AnsiString, IsNull ? -1 : (int)AnsiLength, Tmp, (int)UnicodeLength);
if (RequiredLength < 1 && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
// Buffer is too small

RequiredLength= MultiByteToWideChar(cc->CodePage, 0, AnsiString, IsNull ? -1 : (int)AnsiLength, NULL, 0);

// Set LengthIndicator
if (LengthIndicator)
*LengthIndicator= RequiredLength - IsNull;

if (RequiredLength > UnicodeLength)
Tmp= (SQLWCHAR *)malloc(RequiredLength * sizeof(SQLWCHAR));

RequiredLength= MultiByteToWideChar(cc->CodePage, 0, AnsiString, IsNull ? -1 : (int)AnsiLength, Tmp, (int)RequiredLength);
if (RequiredLength < 1)
{
if (Error)
MADB_SetError(Error, MADB_ERR_HY000, "Ansi to Unicode conversion error occurred", GetLastError());
rc= 1;
goto end;
}

/* Truncation */
if (Tmp != UnicodeString)
{
RequiredLength= MultiByteToWideChar(cc->CodePage, 0, AnsiString, IsNull ? -1 : (int)AnsiLength, Tmp, (int)RequiredLength);
if (RequiredLength < 1)
{
if (Error)
MADB_SetError(Error, MADB_ERR_HY000, "Ansi to Unicode conversion error occurred", GetLastError());
free(Tmp);
return 1;
}

wcsncpy(UnicodeString, L"", 1);
wcsncat(UnicodeString, Tmp, UnicodeLength- 1);
free(Tmp);
if (Error)
MADB_SetError(Error, MADB_ERR_01004, NULL, 0);
} else if (RequiredLength < 1)
{
// Conversion error occurred
if (Error)
MADB_SetError(Error, MADB_ERR_HY000, "Ansi to Unicode conversion error occurred", GetLastError());
return 1;
} else {
// Successfully converted string
// Set LengthIndicator
if (LengthIndicator)
*LengthIndicator= RequiredLength - IsNull;
}
end:
if (Tmp != UnicodeString)
free(Tmp);
return rc;
}

/* Returns required length for result string with(if dest and dest length are provided)
Expand Down
17 changes: 7 additions & 10 deletions odbc_3_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ SQLRETURN SQL_API SQLGetData(SQLHSTMT StatementHandle,
SQLLEN *StrLen_or_IndPtr)
{
MADB_Stmt *Stmt= (MADB_Stmt*)StatementHandle;
unsigned int i;
MADB_DescRecord *IrdRec;

if (StatementHandle== SQL_NULL_HSTMT)
Expand Down Expand Up @@ -856,19 +855,17 @@ SQLRETURN SQL_API SQLGetData(SQLHSTMT StatementHandle,
return MADB_SetError(&Stmt->Error, MADB_ERR_HY090, NULL, 0);
}

/* reset offsets for other columns. Doing that here since "internal" calls should not do that */
for (i=0; i < mysql_stmt_field_count(Stmt->stmt); i++)
/* reset offsets for column. Doing that here since "internal" calls should not do that */
if (Stmt->LastSQLGetDataColumn != Col_or_Param_Num)
{
if (i != Col_or_Param_Num - 1)
IrdRec= MADB_DescGetInternalRecord(Stmt->Ird, Col_or_Param_Num - 1, MADB_DESC_READ);
if (IrdRec)
{
IrdRec= MADB_DescGetInternalRecord(Stmt->Ird, i, MADB_DESC_READ);
if (IrdRec)
{
MADB_FREE(IrdRec->InternalBuffer);
}
Stmt->CharOffset[i]= 0;
MADB_FREE(IrdRec->InternalBuffer);
}
Stmt->CharOffset[Col_or_Param_Num - 1]= 0;
}
Stmt->LastSQLGetDataColumn= Col_or_Param_Num;

return Stmt->Methods->GetData(StatementHandle, Col_or_Param_Num, TargetType, TargetValuePtr, BufferLength, StrLen_or_IndPtr, FALSE);
}
Expand Down

0 comments on commit 481421a

Please sign in to comment.