Core/Database: Prepared statement parameter preallocation (#18999)

- Pass prepared statement size to the helper class to prevent runtime resizing.
- Rename CheckValidIndex -> AssertValidIndex
- Cached prepared size on the worker pool as it's shared among all connections
- Cached query data only for each connection, done lookup in map instead of possibly creating a new element
- Kill the prepared statement map, and store raw sql string on the MySQLPreparedStatement class
(This info is only used for logging, and there is no need of keeping a second container just for it)
This commit is contained in:
ariel- authored and Aokromes committed 2017-03-03 01:32:12 +01:00
1 parent 206fddf129
commit 22c4d86dfe
6 files changed
+174 -185

No files matched your search

@@ -94,6 +94,7 @@ template <class T>
bool DatabaseWorkerPool<T>::PrepareStatements()
{
for (auto& connections : _connections)
{
for (auto& connection : connections)
{
connection->LockIfReady();
@@ -105,7 +106,30 @@ bool DatabaseWorkerPool<T>::PrepareStatements()
}
else
connection->Unlock();
size_t const preparedSize = connection->m_stmts.size();
if (_preparedStatementSize.size() < preparedSize)
_preparedStatementSize.resize(preparedSize);
for (size_t i = 0; i < preparedSize; ++i)
{
// already set by another connection
// (each connection only has prepared statements of it's own type sync/async)
if (_preparedStatementSize[i] > 0)
continue;
if (MySQLPreparedStatement* stmt = connection->m_stmts[i].get())
{
uint32 const paramCount = stmt->GetParameterCount();
// TC only supports uint8 indices.
ASSERT(paramCount < std::numeric_limits<uint8>::max());
_preparedStatementSize[i] = static_cast<uint8>(paramCount);
}
}
}
}
return true;
}