Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 51 additions & 15 deletions mysqlse/ha_sphinx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <winsock2.h>
#endif
#else
#define sphinx_append append
#define sphinx_array Dynamic_array
#define sphinx_elements elements
#endif

#include <mysys_err.h>
#include <my_sys.h>
#include <mysql.h> // include client for INSERT table (sort of redoing federated..)

#ifndef __WIN__
// UNIX-specific
#include <my_net.h>
#if MYSQL_VERSION_ID>=50709
#include <arpa/inet.h>
#else
#include <my_net.h>
#endif
#include <netdb.h>
#include <sys/un.h>

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -602,10 +632,10 @@ struct CSphSEQuery
};
char * m_sName; ///< points to query buffer
int m_iType;
Dynamic_array<ulonglong> m_dIds;
Dynamic_array<Value_t> m_dValues;
sphinx_array<ulonglong> m_dIds;
sphinx_array<Value_t> m_dValues;
};
Dynamic_array<Override_t *> m_dOverrides;
sphinx_array<Override_t *> m_dOverrides;

public:
char m_sParseError[256];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1321,7 +1355,7 @@ CSphSEQuery::~CSphSEQuery ()
SafeDeleteArray ( m_sQueryBuffer );
SafeDeleteArray ( m_pWeights );
SafeDeleteArray ( m_pBuf );
for ( int i=0; i<m_dOverrides.elements(); i++ )
for ( int i=0; i<m_dOverrides.sphinx_elements(); i++ )
SafeDelete ( m_dOverrides.at(i) );
SPH_VOID_RET();
}
Expand Down Expand Up @@ -1789,7 +1823,7 @@ bool CSphSEQuery::ParseField ( char * sField )
pOverride = new CSphSEQuery::Override_t;
pOverride->m_sName = chop(sName);
pOverride->m_iType = iType;
m_dOverrides.append ( pOverride );
m_dOverrides.sphinx_append ( pOverride );
}

ulonglong uId = strtoull ( sId, NULL, 10 );
Expand All @@ -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 )
Expand Down Expand Up @@ -1906,11 +1940,11 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
iReqSize += 8 + strlen(m_sFieldWeight[i] );
// overrides
iReqSize += 4;
for ( int i=0; i<m_dOverrides.elements(); i++ )
for ( int i=0; i<m_dOverrides.sphinx_elements(); i++ )
{
CSphSEQuery::Override_t * pOverride = m_dOverrides.at(i);
const uint32 uSize = pOverride->m_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;
Expand Down Expand Up @@ -2012,14 +2046,14 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
SendString ( m_sComment );

// overrides
SendInt ( m_dOverrides.elements() );
for ( int i=0; i<m_dOverrides.elements(); i++ )
SendInt ( m_dOverrides.sphinx_elements() );
for ( int i=0; i<m_dOverrides.sphinx_elements(); i++ )
{
CSphSEQuery::Override_t * pOverride = m_dOverrides.at(i);
SendString ( pOverride->m_sName );
SendDword ( pOverride->m_iType );
SendInt ( pOverride->m_dIds.elements() );
for ( int j=0; j<pOverride->m_dIds.elements(); j++ )
SendInt ( pOverride->m_dIds.sphinx_elements() );
for ( int j=0; j<pOverride->m_dIds.sphinx_elements(); j++ )
{
SendUint64 ( pOverride->m_dIds.at(j) );
if ( pOverride->m_iType==SPH_ATTR_FLOAT )
Expand Down Expand Up @@ -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();
}

Expand Down
22 changes: 17 additions & 5 deletions mysqlse/snippets_udf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
#include <string.h>
#include <assert.h>

#ifndef __WIN__
#include <mysql_version.h>

#ifndef _WIN32
#if MYSQL_VERSION_ID>=50709
#include <arpa/inet.h>
#endif
#include <sys/un.h>
#include <netdb.h>
#endif

#include <mysql_version.h>

#if MYSQL_VERSION_ID>=50515
#include "sql_class.h"
#include "sql_array.h"
Expand All @@ -34,6 +37,13 @@
#include "../mysql_priv.h"
#endif

#ifdef _WIN32
#if MYSQL_VERSION_ID>=50709
#define in_addr_t uint32
#include <winsock2.h>
#endif
#endif

#include <mysys_err.h>
#include <my_sys.h>

Expand Down Expand Up @@ -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; }

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -426,7 +438,7 @@ int CSphUrl::Connect()
}
} else
{
#ifndef __WIN__
#ifndef _WIN32
iDomain = AF_UNIX;
iSockaddrSize = sizeof(saun);
pSockaddr = (struct sockaddr *) &saun;
Expand Down