Skip to content

Commit

Permalink
More performance improvements.
Browse files Browse the repository at this point in the history
Removed use of unique_ptr for stored rs metadata object
Slightly opotimized MADB_DescGetInternalRecord
  • Loading branch information
lawrinn committed Nov 26, 2024
1 parent d517333 commit f6d1ebc
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 89 deletions.
37 changes: 20 additions & 17 deletions driver/ma_desc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ MADB_DescSetIrdMetadata(MADB_Stmt *Stmt, const MYSQL_FIELD *Fields, unsigned int
{
return 1;
}
Stmt->Ird->Header.Count= i + 1;
}
return 0;
}
Expand Down Expand Up @@ -638,32 +639,34 @@ void MADB_DescSetRecordDefaults(MADB_Desc *Desc, MADB_DescRecord *Record)
}
/* }}} */

/* {{{ MADB_DescGetInternalRecord */
MADB_DescRecord *MADB_DescGetInternalRecord(MADB_Desc *Desc, SQLSMALLINT RecordNumber, SQLSMALLINT Type)
/* {{{ MADB_DescGetInternalRecord
[in] ReorordNumber - 0 based record index */
MADB_DescRecord* MADB_DescGetInternalRecord(MADB_Desc *Desc, SQLSMALLINT RecordNumber, SQLSMALLINT Type)
{
MADB_DescRecord *DescRecord;

if (RecordNumber > (SQLINTEGER)Desc->Records.elements &&
Type == MADB_DESC_READ)
if (RecordNumber >= (SQLINTEGER)Desc->Records.elements)
{
MADB_SetError(&Desc->Error, MADB_ERR_07009, nullptr, 0);
return nullptr;
}

while (RecordNumber >= (SQLINTEGER)Desc->Records.elements)
{
if (!(DescRecord= (MADB_DescRecord *)MADB_AllocDynamic(&Desc->Records)))
if (Type == MADB_DESC_READ)
{
MADB_SetError(&Desc->Error, MADB_ERR_HY001, nullptr, 0);
MADB_SetError(&Desc->Error, MADB_ERR_07009, nullptr, 0);
return nullptr;
}

MADB_DescSetRecordDefaults(Desc, DescRecord);

do {
if (!(DescRecord= (MADB_DescRecord *)MADB_AllocDynamic(&Desc->Records)))
{
MADB_SetError(&Desc->Error, MADB_ERR_HY001, nullptr, 0);
return nullptr;
}

MADB_DescSetRecordDefaults(Desc, DescRecord);
} while (RecordNumber >= (SQLINTEGER)Desc->Records.elements);

if (RecordNumber + 1 > Desc->Header.Count)
Desc->Header.Count= (SQLSMALLINT)(RecordNumber + 1);
}

if (RecordNumber + 1 > Desc->Header.Count)
Desc->Header.Count= (SQLSMALLINT)(RecordNumber + 1);

DescRecord= ((MADB_DescRecord *)Desc->Records.buffer) + RecordNumber;

return DescRecord;
Expand Down
11 changes: 6 additions & 5 deletions driver/ma_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ MYSQL_RES *MADB_GetDefaultColumnValues(MADB_Stmt *Stmt, const MYSQL_FIELD *field

for (i= 0; i < Stmt->metadata->getColumnCount(); i++)
{
// TODO: Shouldn't it be really IRD here?
MADB_DescRecord* Rec= MADB_DescGetInternalRecord(Stmt->Ard, i, MADB_DESC_READ);

if (!Rec->inUse || MADB_ColumnIgnoredInAllRows(Stmt->Ard, Rec) == TRUE)
if (!Rec || !Rec->inUse || MADB_ColumnIgnoredInAllRows(Stmt->Ard, Rec) == TRUE)
{
continue;
}
Expand Down Expand Up @@ -864,7 +865,7 @@ void* GetBindOffset(MADB_Header& Header, void* Ptr, SQLULEN RowNumber, std::size
}

/* Checking if column ignored in all bound rows. Should hel*/
BOOL MADB_ColumnIgnoredInAllRows(MADB_Desc *Desc, MADB_DescRecord *Rec)
bool MADB_ColumnIgnoredInAllRows(MADB_Desc *Desc, MADB_DescRecord *Rec)
{
SQLULEN row;
SQLLEN *IndicatorPtr;
Expand All @@ -873,13 +874,13 @@ BOOL MADB_ColumnIgnoredInAllRows(MADB_Desc *Desc, MADB_DescRecord *Rec)
{
IndicatorPtr= (SQLLEN *)GetBindOffset(Desc->Header, Rec->IndicatorPtr, row, sizeof(SQLLEN));

if (IndicatorPtr == NULL || *IndicatorPtr != SQL_COLUMN_IGNORE)
if (IndicatorPtr == nullptr || *IndicatorPtr != SQL_COLUMN_IGNORE)
{
return FALSE;
return false;
}
}

return TRUE;
return true;
}


Expand Down
2 changes: 1 addition & 1 deletion driver/ma_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const char * MADB_GetTypeName(const MYSQL_FIELD *Field);
my_bool MADB_CheckPtrLength(SQLINTEGER MaxLength, char *Ptr, SQLINTEGER NameLen);
std::size_t getArrayStep(MADB_Header& header, std::size_t pointedSize);
void * GetBindOffset(MADB_Header& DescHeader, void *Ptr, SQLULEN RowNumber, size_t PtrSize);
BOOL MADB_ColumnIgnoredInAllRows(MADB_Desc *Desc, MADB_DescRecord *Rec);
bool MADB_ColumnIgnoredInAllRows(MADB_Desc *Desc, MADB_DescRecord *Rec);

SQLRETURN MADB_DaeStmt(MADB_Stmt *Stmt, SQLUSMALLINT Operation);
MYSQL_RES * MADB_GetDefaultColumnValues(MADB_Stmt *Stmt, const MYSQL_FIELD *fields);
Expand Down
2 changes: 1 addition & 1 deletion driver/ma_odbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ struct MADB_Stmt
struct st_ma_stmt_methods *Methods;
Unique::ResultSet rs;
Unique::PreparedStatement stmt;
Unique::ResultSetMetaData metadata;
mariadb::ResultSetMetaData* metadata= nullptr;
Unique::MYSQL_RES DefaultsResult;
MADB_DescRecord *PutDataRec= nullptr;
MADB_Stmt *DaeStmt= nullptr;
Expand Down
4 changes: 1 addition & 3 deletions driver/ma_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void MADB_QUERY::reset()
Original.assign("");
RefinedText.assign("");
Tokens.clear();
PoorManParsing= ReturnsResult= false;
PoorManParsing= false;
}

int MADB_ParseQuery(MADB_QUERY * Query)
Expand Down Expand Up @@ -397,8 +397,6 @@ int ParseQuery(MADB_QUERY *Query)
/* We are currently at 2nd token of statement, and getting previous token position from Tokens array*/
StmtType= MADB_GetQueryType(MADB_Token(Query, Query->Tokens.size() - 2), p);

Query->ReturnsResult= Query->ReturnsResult || !QUERY_DOESNT_RETURN_RESULT(StmtType);

/* If we on first statement, setting QueryType*/
if (Query->Tokens.size() == 2)
{
Expand Down
2 changes: 0 additions & 2 deletions driver/ma_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ typedef struct {
SQLString RefinedText;
enum enum_madb_query_type QueryType= MADB_QUERY_NO_RESULT;
bool MultiStatement= false;
/* Keeping it so far */
bool ReturnsResult= false;
bool PoorManParsing= false;

bool BatchAllowed= false;
Expand Down
6 changes: 5 additions & 1 deletion driver/ma_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ SQLRETURN MADB_StmtMoreResults(SQLHSTMT StatementHandle)
/* We can't have it in MADB_StmtResetResultStructures, as it breaks dyn_cursor functionality.
Thus we free-ing bind structs on move to new result only */
MADB_FREE(Stmt->result);
Stmt->metadata.reset();
if (Stmt->metadata)
{
delete Stmt->metadata;
Stmt->metadata= nullptr;
}
Stmt->rs.reset();

try {
Expand Down
Loading

0 comments on commit f6d1ebc

Please sign in to comment.