From affee140c6a8e1e9358be2aa0d0088ede218acaa Mon Sep 17 00:00:00 2001 From: ariel- Date: Wed, 1 Mar 2017 22:20:53 -0300 Subject: 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) --- src/server/database/Database/PreparedStatement.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/server/database/Database/PreparedStatement.h') diff --git a/src/server/database/Database/PreparedStatement.h b/src/server/database/Database/PreparedStatement.h index ddc731625fa..33ef04287cd 100644 --- a/src/server/database/Database/PreparedStatement.h +++ b/src/server/database/Database/PreparedStatement.h @@ -78,7 +78,7 @@ class TC_DATABASE_API PreparedStatement friend class MySQLConnection; public: - explicit PreparedStatement(uint32 index); + PreparedStatement(uint32 index, uint8 capacity); ~PreparedStatement(); void setBool(const uint8 index, const bool value); @@ -97,12 +97,14 @@ class TC_DATABASE_API PreparedStatement void setNull(const uint8 index); protected: - void BindParameters(); + void BindParameters(MySQLPreparedStatement* stmt); protected: MySQLPreparedStatement* m_stmt; uint32 m_index; - std::vector statement_data; //- Buffer of parameters, not tied to MySQL in any way yet + + //- Buffer of parameters, not tied to MySQL in any way yet + std::vector statement_data; PreparedStatement(PreparedStatement const& right) = delete; PreparedStatement& operator=(PreparedStatement const& right) = delete; @@ -117,7 +119,7 @@ class TC_DATABASE_API MySQLPreparedStatement friend class PreparedStatement; public: - MySQLPreparedStatement(MYSQL_STMT* stmt); + MySQLPreparedStatement(MYSQL_STMT* stmt, std::string queryString); ~MySQLPreparedStatement(); void setBool(const uint8 index, const bool value); @@ -134,13 +136,15 @@ class TC_DATABASE_API MySQLPreparedStatement void setBinary(const uint8 index, const std::vector& value, bool isString); void setNull(const uint8 index); + uint32 GetParameterCount() const { return m_paramCount; } + protected: MYSQL_STMT* GetSTMT() { return m_Mstmt; } MYSQL_BIND* GetBind() { return m_bind; } PreparedStatement* m_stmt; void ClearParameters(); - bool CheckValidIndex(uint8 index); - std::string getQueryString(std::string const& sqlPattern) const; + void AssertValidIndex(uint8 index); + std::string getQueryString() const; private: void setValue(MYSQL_BIND* param, enum_field_types type, const void* value, uint32 len, bool isUnsigned); @@ -150,6 +154,7 @@ class TC_DATABASE_API MySQLPreparedStatement uint32 m_paramCount; std::vector m_paramsSet; MYSQL_BIND* m_bind; + std::string const m_queryString; MySQLPreparedStatement(MySQLPreparedStatement const& right) = delete; MySQLPreparedStatement& operator=(MySQLPreparedStatement const& right) = delete; -- cgit v1.2.3