From d4273a352d22e8c5e924bc4fd094fc7d9f8e047f Mon Sep 17 00:00:00 2001 From: riden Date: Thu, 26 Nov 2015 03:51:40 +0200 Subject: [PATCH] MySQLSE MySQL 5.7 support --- mysqlse/ha_sphinx.cc | 66 ++++++++++++++++++++++++++++++++++++++----------- mysqlse/snippets_udf.cc | 22 +++++++++++++---- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/storage/sphinx/ha_sphinx.cc b/storage/sphinx/ha_sphinx.cc index 8eabe87..e6a49a8 100644 --- a/storage/sphinx/ha_sphinx.cc +++ b/storage/sphinx/ha_sphinx.cc @@ -34,13 +34,37 @@ #include "../mysql_priv.h" #endif +#if MYSQL_VERSION_ID>=50709 +#include "item_timefunc.h" +#define sphinx_append push_back +#define sphinx_array std::vector +#define sphinx_elements size +#if defined(_WIN32) +#define __WIN__ _WIN32 +#define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0) +#define pthread_mutex_lock(A) (EnterCriticalSection(A),0) +#define pthread_mutex_unlock(A) (LeaveCriticalSection(A), 0) +#define pthread_mutex_destroy(A) (DeleteCriticalSection(A), 0) +#define in_addr_t uint32 +#include +#endif +#else +#define sphinx_append append +#define sphinx_array Dynamic_array +#define sphinx_elements elements +#endif + #include #include #include // include client for INSERT table (sort of redoing federated..) #ifndef __WIN__ // UNIX-specific - #include + #if MYSQL_VERSION_ID>=50709 + #include + #else + #include + #endif #include #include @@ -286,6 +310,12 @@ inline void SPH_DEBUG ( const char *, ... ) {} #define SafeDelete(_arg) { if ( _arg ) delete ( _arg ); (_arg) = NULL; } #define SafeDeleteArray(_arg) { if ( _arg ) delete [] ( _arg ); (_arg) = NULL; } +#if MYSQL_VERSION_ID>=50709 +#ifdef __WIN__ +typedef native_mutex_t pthread_mutex_t; +#endif +#endif + ////////////////////////////////////////////////////////////////////////////// /// per-table structure that will be shared among all open Sphinx SE handlers @@ -602,10 +632,10 @@ struct CSphSEQuery }; char * m_sName; ///< points to query buffer int m_iType; - Dynamic_array m_dIds; - Dynamic_array m_dValues; + sphinx_array m_dIds; + sphinx_array m_dValues; }; - Dynamic_array m_dOverrides; + sphinx_array m_dOverrides; public: char m_sParseError[256]; @@ -733,9 +763,13 @@ static int sphinx_init_func ( void * p ) { sphinx_init = 1; void ( pthread_mutex_init ( &sphinx_mutex, MY_MUTEX_INIT_FAST ) ); + #if MYSQL_VERSION_ID >= 50709 + sphinx_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0, + sphinx_get_key, 0, 0, 0 ); + #else sphinx_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0, sphinx_get_key, 0, 0 ); - + #endif #if MYSQL_VERSION_ID > 50100 handlerton * hton = (handlerton*) p; hton->state = SHOW_OPTION_YES; @@ -1321,7 +1355,7 @@ CSphSEQuery::~CSphSEQuery () SafeDeleteArray ( m_sQueryBuffer ); SafeDeleteArray ( m_pWeights ); SafeDeleteArray ( m_pBuf ); - for ( int i=0; im_sName = chop(sName); pOverride->m_iType = iType; - m_dOverrides.append ( pOverride ); + m_dOverrides.sphinx_append ( pOverride ); } ulonglong uId = strtoull ( sId, NULL, 10 ); @@ -1801,8 +1835,8 @@ bool CSphSEQuery::ParseField ( char * sField ) else tValue.m_uValue = (uint32)strtoul ( sValue, NULL, 10 ); - pOverride->m_dIds.append ( uId ); - pOverride->m_dValues.append ( tValue ); + pOverride->m_dIds.sphinx_append ( uId ); + pOverride->m_dValues.sphinx_append ( tValue ); } if ( !pOverride ) @@ -1906,11 +1940,11 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer ) iReqSize += 8 + strlen(m_sFieldWeight[i] ); // overrides iReqSize += 4; - for ( int i=0; im_iType==SPH_ATTR_BIGINT ? 16 : 12; // id64 + value - iReqSize += strlen ( pOverride->m_sName ) + 12 + uSize*pOverride->m_dIds.elements(); + iReqSize += strlen ( pOverride->m_sName ) + 12 + uSize*pOverride->m_dIds.sphinx_elements(); } // select iReqSize += 4; @@ -2012,14 +2046,14 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer ) SendString ( m_sComment ); // overrides - SendInt ( m_dOverrides.elements() ); - for ( int i=0; im_sName ); SendDword ( pOverride->m_iType ); - SendInt ( pOverride->m_dIds.elements() ); - for ( int j=0; jm_dIds.elements(); j++ ) + SendInt ( pOverride->m_dIds.sphinx_elements() ); + for ( int j=0; jm_dIds.sphinx_elements(); j++ ) { SendUint64 ( pOverride->m_dIds.at(j) ); if ( pOverride->m_iType==SPH_ATTR_FLOAT ) @@ -2073,8 +2107,10 @@ ha_sphinx::ha_sphinx ( handlerton * hton, TABLE_ARG * table ) , m_dUnboundFields ( NULL ) { SPH_ENTER_METHOD(); + #if MYSQL_VERSION_ID < 50709 if ( current_thd ) current_thd->variables.engine_condition_pushdown = true; + #endif SPH_VOID_RET(); } diff --git a/storage/sphinx/snippets_udf.cc b/storage/sphinx/snippets_udf.cc index d0899e8..e9f7bc0 100644 --- a/storage/sphinx/snippets_udf.cc +++ b/storage/sphinx/snippets_udf.cc @@ -17,13 +17,16 @@ #include #include -#ifndef __WIN__ +#include + +#ifndef _WIN32 +#if MYSQL_VERSION_ID>=50709 +#include +#endif #include #include #endif -#include - #if MYSQL_VERSION_ID>=50515 #include "sql_class.h" #include "sql_array.h" @@ -34,6 +37,13 @@ #include "../mysql_priv.h" #endif +#ifdef _WIN32 +#if MYSQL_VERSION_ID>=50709 +#define in_addr_t uint32 +#include +#endif +#endif + #include #include @@ -90,7 +100,9 @@ void sphUnalignedWrite ( void * pPtr, const T & tVal ) #define Min(a,b) ((a)<(b)?(a):(b)) +#if !defined(_WIN32) typedef unsigned int DWORD; +#endif inline DWORD sphF2DW ( float f ) { union { float f; uint32 d; } u; u.f = f; return u.d; } @@ -359,7 +371,7 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen ) int CSphUrl::Connect() { struct sockaddr_in sin; -#ifndef __WIN__ +#ifndef _WIN32 struct sockaddr_un saun; #endif @@ -426,7 +438,7 @@ int CSphUrl::Connect() } } else { -#ifndef __WIN__ +#ifndef _WIN32 iDomain = AF_UNIX; iSockaddrSize = sizeof(saun); pSockaddr = (struct sockaddr *) &saun;