summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2012-03-07 17:38:47 +0200
committerMichael Widenius <monty@askmonty.org>2012-03-07 17:38:47 +0200
commitaba6d06c34201c672f083298650d96da666cb173 (patch)
treed27752de833bb2c26c18a148c6855dfbbdad7711 /storage
parent18c51eee3557ecc61d69778adb6c78c0fae4d496 (diff)
downloadmariadb-git-aba6d06c34201c672f083298650d96da666cb173.tar.gz
Upgraded sphinx to version 2.0.4
Fixed memory leaks and compiler warnings in ha_sphinx.cc Added HA_MUST_USE_TABLE_CONDITION_PUSHDOWN so that an engine can force index condition to be used mysql-test/suite/sphinx/sphinx.result: Added testing of pushdown conditions and sphinx status variables. mysql-test/suite/sphinx/sphinx.test: Added testing of pushdown conditions and sphinx status variables. mysql-test/suite/sphinx/suite.pm: Print version number if sphinx version is too old. sql/handler.h: Added HA_MUST_USE_TABLE_CONDITION_PUSHDOWN so that an engine can force index condition to be used sql/sql_base.cc: Added 'thd' argument to check_unused() to be able to set 'entry->in_use' if we call handler->extra(). This was needed as sphinx (and possible other storage engines) assumes that 'in_use' is set if handler functions are called. sql/sql_select.cc: Test if handler is forcing pushdown condition to be used. storage/sphinx/ha_sphinx.cc: Updated to version 2.0.4 Fixed memory leaks and compiler warnings. storage/sphinx/ha_sphinx.h: Updated to version 2.0.4 storage/sphinx/snippets_udf.cc: Updated to version 2.0.4
Diffstat (limited to 'storage')
-rw-r--r--storage/sphinx/ha_sphinx.cc1309
-rw-r--r--storage/sphinx/ha_sphinx.h42
-rw-r--r--storage/sphinx/snippets_udf.cc239
-rw-r--r--storage/sphinx/sphinx.5.0.22.diff284
-rw-r--r--storage/sphinx/sphinx.5.0.27.diff284
-rw-r--r--storage/sphinx/sphinx.5.0.37.diff338
6 files changed, 1074 insertions, 1422 deletions
diff --git a/storage/sphinx/ha_sphinx.cc b/storage/sphinx/ha_sphinx.cc
index 8abff2003be..0121d4335be 100644
--- a/storage/sphinx/ha_sphinx.cc
+++ b/storage/sphinx/ha_sphinx.cc
@@ -1,5 +1,16 @@
//
-// $Id: ha_sphinx.cc 2058 2009-11-07 04:01:57Z shodan $
+// $Id: ha_sphinx.cc 3133 2012-03-01 13:47:52Z shodan $
+//
+
+//
+// Copyright (c) 2001-2012, Andrew Aksyonoff
+// Copyright (c) 2008-2012, Sphinx Technologies Inc
+// All rights reserved
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License. You should have
+// received a copy of the GPL license along with this program; if you
+// did not, you can find it at http://www.gnu.org/
//
#ifdef USE_PRAGMA_IMPLEMENTATION
@@ -13,7 +24,11 @@
#include <mysql_version.h>
-#if MYSQL_VERSION_ID>50100
+#if MYSQL_VERSION_ID>=50515
+#include "sql_class.h"
+#include "sql_array.h"
+#elif MYSQL_VERSION_ID>50100
+#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "../mysql_priv.h"
@@ -21,15 +36,11 @@
#include <mysys_err.h>
#include <my_sys.h>
-#include "sql_array.h"
-#include "table.h"
-#include "field.h"
-#include "item.h"
-#include <mysqld_error.h>
-#include <my_net.h>
+#include <mysql.h> // include client for INSERT table (sort of redoing federated..)
#ifndef __WIN__
// UNIX-specific
+ #include <my_net.h>
#include <netdb.h>
#include <sys/un.h>
@@ -39,6 +50,8 @@
#else
// Windows-specific
#include <io.h>
+ #define strcasecmp stricmp
+ #define snprintf _snprintf
#define RECV_FLAGS 0
@@ -68,10 +81,6 @@
#define UNALIGNED_RAM_ACCESS 1
#endif
-#if MYSQL_VERSION_ID<50100
-#define thd_ha_data(X,Y) (X)->ha_data[sphinx_hton.slot]
-#define ha_thd() current_thd
-#endif // <50100
#if UNALIGNED_RAM_ACCESS
@@ -113,28 +122,48 @@ void sphUnalignedWrite ( void * pPtr, const T & tVal )
#endif
+#if MYSQL_VERSION_ID>=50515
+
+#define sphinx_hash_init my_hash_init
+#define sphinx_hash_free my_hash_free
+#define sphinx_hash_search my_hash_search
+#define sphinx_hash_delete my_hash_delete
+
+#else
+
+#define sphinx_hash_init hash_init
+#define sphinx_hash_free hash_free
+#define sphinx_hash_search hash_search
+#define sphinx_hash_delete hash_delete
+
+#endif
+
/////////////////////////////////////////////////////////////////////////////
// FIXME! make this all dynamic
#define SPHINXSE_MAX_FILTERS 32
-#define SPHINXSE_DEFAULT_HOST "127.0.0.1"
-#define SPHINXSE_DEFAULT_PORT 9312
-#define SPHINXSE_DEFAULT_INDEX "*"
+#define SPHINXAPI_DEFAULT_HOST "127.0.0.1"
+#define SPHINXAPI_DEFAULT_PORT 9312
+#define SPHINXAPI_DEFAULT_INDEX "*"
+
+#define SPHINXQL_DEFAULT_PORT 9306
#define SPHINXSE_SYSTEM_COLUMNS 3
#define SPHINXSE_MAX_ALLOC (16*1024*1024)
#define SPHINXSE_MAX_KEYWORDSTATS 4096
-// FIXME! all the following is cut-n-paste from sphinx.h and searchd.cpp
-#define SPHINX_VERSION "0.9.9"
+#define SPHINXSE_VERSION "2.0.4-release"
+
+// FIXME? the following is cut-n-paste from sphinx.h and searchd.cpp
+// cut-n-paste is somewhat simpler that adding dependencies however..
enum
{
SPHINX_SEARCHD_PROTO = 1,
SEARCHD_COMMAND_SEARCH = 0,
- VER_COMMAND_SEARCH = 0x116,
+ VER_COMMAND_SEARCH = 0x119,
};
/// search query sorting orders
@@ -174,6 +203,8 @@ enum ESphRankMode
SPH_RANK_PROXIMITY = 4, ///< phrase proximity
SPH_RANK_MATCHANY = 5, ///< emulate old match-any weighting
SPH_RANK_FIELDMASK = 6, ///< sets bits where there were matches
+ SPH_RANK_SPH04 = 7, ///< codename SPH04, phrase proximity + bm25 + head/exact boost
+ SPH_RANK_EXPR = 8, ///< expression based ranker
SPH_RANK_TOTAL,
SPH_RANK_DEFAULT = SPH_RANK_PROXIMITY_BM25
@@ -199,8 +230,10 @@ enum
SPH_ATTR_BOOL = 4, ///< this attr is a boolean bit field
SPH_ATTR_FLOAT = 5,
SPH_ATTR_BIGINT = 6,
+ SPH_ATTR_STRING = 7, ///< string (binary; in-memory)
- SPH_ATTR_MULTI = 0x40000000UL ///< this attr has multiple values (0 or more)
+ SPH_ATTR_UINT32SET = 0x40000001UL, ///< this attr is multiple int32 values (0 or more)
+ SPH_ATTR_UINT64SET = 0x40000002UL ///< this attr is multiple int64 values (0 or more)
};
/// known answers
@@ -250,23 +283,24 @@ inline void SPH_DEBUG ( const char *, ... ) {}
#endif
-#define SafeDelete(_arg) { if ( _arg ) delete ( _arg ); (_arg) = NULL; }
-#define SafeDeleteArray(_arg) { if ( _arg ) delete [] ( _arg ); (_arg) = NULL; }
+#define SafeDelete(_arg) { delete ( _arg ); (_arg) = NULL; }
+#define SafeDeleteArray(_arg) { if ( _arg ) { delete [] ( _arg ); (_arg) = NULL; } }
//////////////////////////////////////////////////////////////////////////////
-/// a structure that will be shared among all open Sphinx SE handlers
+/// per-table structure that will be shared among all open Sphinx SE handlers
struct CSphSEShare
{
pthread_mutex_t m_tMutex;
THR_LOCK m_tLock;
char * m_sTable;
- char * m_sScheme;
- char * m_sHost; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY
- char * m_sSocket; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY
- char * m_sIndex; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY
+ char * m_sScheme; ///< our connection string
+ char * m_sHost; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY
+ char * m_sSocket; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY
+ char * m_sIndex; ///< points into m_sScheme buffer, DO NOT FREE EXPLICITLY
ushort m_iPort;
+ bool m_bSphinxQL; ///< is this read-only SphinxAPI table, or write-only SphinxQL table?
uint m_iTableNameLen;
uint m_iUseCount;
CHARSET_INFO * m_pTableQueryCharset;
@@ -282,6 +316,7 @@ struct CSphSEShare
, m_sSocket ( NULL )
, m_sIndex ( NULL )
, m_iPort ( 0 )
+ , m_bSphinxQL ( false )
, m_iTableNameLen ( 0 )
, m_iUseCount ( 1 )
, m_pTableQueryCharset ( NULL )
@@ -375,14 +410,14 @@ public:
m_iMatchesFound = 0;
m_iQueryMsec = 0;
m_iWords = 0;
- SafeDeleteArray ( m_dWords );
m_bLastError = false;
m_sLastMessage[0] = '\0';
+ SafeDeleteArray ( m_dWords );
}
~CSphSEStats()
{
- Reset ();
+ SafeDeleteArray ( m_dWords );
}
};
@@ -399,10 +434,20 @@ struct CSphSEThreadData
CHARSET_INFO * m_pQueryCharset;
+ bool m_bReplace; ///< are we doing an INSERT or REPLACE
+
+ bool m_bCondId; ///< got a value from condition pushdown
+ longlong m_iCondId; ///< value acquired from id=value condition pushdown
+ bool m_bCondDone; ///< index_read() is now over
+
CSphSEThreadData ()
: m_bStats ( false )
, m_bQuery ( false )
, m_pQueryCharset ( NULL )
+ , m_bReplace ( false )
+ , m_bCondId ( false )
+ , m_iCondId ( 0 )
+ , m_bCondDone ( false )
{}
};
@@ -472,13 +517,14 @@ private:
int m_iLimit;
bool m_bQuery;
- char * m_sQuery;
+ const char * m_sQuery;
uint32 * m_pWeights;
int m_iWeights;
ESphMatchMode m_eMode;
ESphRankMode m_eRanker;
+ const char * m_sRankExpr;
ESphSortOrder m_eSort;
- char * m_sSortBy;
+ const char * m_sSortBy;
int m_iMaxMatches;
int m_iMaxQueryTime;
uint32 m_iMinID;
@@ -488,12 +534,12 @@ private:
CSphSEFilter m_dFilters[SPHINXSE_MAX_FILTERS];
ESphGroupBy m_eGroupFunc;
- char * m_sGroupBy;
- char * m_sGroupSortBy;
+ const char * m_sGroupBy;
+ const char * m_sGroupSortBy;
int m_iCutoff;
int m_iRetryCount;
int m_iRetryDelay;
- char * m_sGroupDistinct; ///< points to query buffer; do NOT delete
+ const char * m_sGroupDistinct; ///< points to query buffer; do NOT delete
int m_iIndexWeights;
char * m_sIndexWeight[SPHINXSE_MAX_FILTERS]; ///< points to query buffer; do NOT delete
int m_iIndexWeight[SPHINXSE_MAX_FILTERS];
@@ -502,12 +548,13 @@ private:
int m_iFieldWeight[SPHINXSE_MAX_FILTERS];
bool m_bGeoAnchor;
- char * m_sGeoLatAttr;
- char * m_sGeoLongAttr;
+ const char * m_sGeoLatAttr;
+ const char * m_sGeoLongAttr;
float m_fGeoLatitude;
float m_fGeoLongitude;
- char * m_sComment;
+ const char * m_sComment;
+ const char * m_sSelect;
struct Override_t
{
@@ -544,10 +591,10 @@ protected:
bool ParseField ( char * sField );
void SendBytes ( const void * pBytes, int iBytes );
- void SendWord ( short int v ) { v = ntohs(v); SendBytes ( &v, sizeof(short int) ); }
- void SendInt ( int v ) { v = ntohl(v); SendBytes ( &v, sizeof(int) ); }
- void SendDword ( uint v ) { v = ntohl(v) ;SendBytes ( &v, sizeof(uint) ); }
- void SendUint64 ( ulonglong v ) { SendDword ( uint(v>>32) ); SendDword ( uint(v&0xFFFFFFFFUL) ); }
+ void SendWord ( short int v ) { v = ntohs(v); SendBytes ( &v, sizeof(v) ); }
+ void SendInt ( int v ) { v = ntohl(v); SendBytes ( &v, sizeof(v) ); }
+ void SendDword ( uint v ) { v = ntohl(v) ;SendBytes ( &v, sizeof(v) ); }
+ void SendUint64 ( ulonglong v ) { SendDword ( (uint)(v>>32) ); SendDword ( (uint)(v&0xFFFFFFFFUL) ); }
void SendString ( const char * v ) { int iLen = strlen(v); SendDword(iLen); SendBytes ( v, iLen ); }
void SendFloat ( float v ) { SendDword ( sphF2DW(v) ); }
};
@@ -580,7 +627,7 @@ bool sphinx_show_status ( THD * thd );
//////////////////////////////////////////////////////////////////////////////
static const char sphinx_hton_name[] = "SPHINX";
-static const char sphinx_hton_comment[] = "Sphinx storage engine " SPHINX_VERSION;
+static const char sphinx_hton_comment[] = "Sphinx storage engine " SPHINXSE_VERSION;
#if MYSQL_VERSION_ID<50100
handlerton sphinx_hton =
@@ -649,20 +696,19 @@ static int sphinx_init_func ( void * p )
if ( !sphinx_init )
{
sphinx_init = 1;
- pthread_mutex_init ( &sphinx_mutex, MY_MUTEX_INIT_FAST );
- my_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0,
+ void ( pthread_mutex_init ( &sphinx_mutex, MY_MUTEX_INIT_FAST ) );
+ sphinx_hash_init ( &sphinx_open_tables, system_charset_info, 32, 0, 0,
sphinx_get_key, 0, 0 );
#if MYSQL_VERSION_ID > 50100
handlerton * hton = (handlerton*) p;
- hton->state = SHOW_OPTION_YES;
- hton->db_type = DB_TYPE_AUTOASSIGN;
- hton->create = sphinx_create_handler;
- hton->close_connection = sphinx_close_connection;
- hton->show_status = sphinx_show_status;
- hton->panic = sphinx_panic;
- hton->flags = HTON_CAN_RECREATE;
- sphinx_hton_ptr = hton;
+ hton->state = SHOW_OPTION_YES;
+ hton->db_type = DB_TYPE_FIRST_DYNAMIC;
+ hton->create = sphinx_create_handler;
+ hton->close_connection = sphinx_close_connection;
+ hton->show_status = sphinx_show_status;
+ hton->panic = sphinx_panic;
+ hton->flags = HTON_CAN_RECREATE;
#endif
}
SPH_RET(0);
@@ -695,17 +741,18 @@ static int sphinx_done_func ( void * )
{
SPH_ENTER_FUNC();
- int error = 0;
if ( sphinx_init )
{
sphinx_init = 0;
+#ifdef NOT_USED
if ( sphinx_open_tables.records )
error = 1;
- my_hash_free ( &sphinx_open_tables );
+#endif
+ sphinx_hash_free ( &sphinx_open_tables );
pthread_mutex_destroy ( &sphinx_mutex );
}
- SPH_RET(error);
+ SPH_RET(0);
}
@@ -749,15 +796,22 @@ bool sphinx_show_status ( THD * thd )
char buf1[IO_SIZE];
uint buf1len;
char buf2[IO_SIZE];
- uint buf2len= 0;
+ uint buf2len = 0;
String words;
buf1[0] = '\0';
buf2[0] = '\0';
+
#if MYSQL_VERSION_ID>50100
+ // 5.1.x style stats
CSphSEThreadData * pTls = (CSphSEThreadData*) ( *thd_ha_data ( thd, hton ) );
+
+#define LOC_STATS(_key,_keylen,_val,_vallen) \
+ stat_print ( thd, sphinx_hton_name, strlen(sphinx_hton_name), _key, _keylen, _val, _vallen );
+
#else
+ // 5.0.x style stats
if ( have_sphinx_db!=SHOW_OPTION_YES )
{
my_message ( ER_NOT_SUPPORTED_YET,
@@ -766,32 +820,33 @@ bool sphinx_show_status ( THD * thd )
SPH_RET(TRUE);
}
CSphSEThreadData * pTls = (CSphSEThreadData*) thd->ha_data[sphinx_hton.slot];
+
+ field_list.push_back ( new Item_empty_string ( "Type", 10 ) );
+ field_list.push_back ( new Item_empty_string ( "Name", FN_REFLEN ) );
+ field_list.push_back ( new Item_empty_string ( "Status", 10 ) );
+ if ( protocol->send_fields ( &field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF ) )
+ SPH_RET(TRUE);
+
+#define LOC_STATS(_key,_keylen,_val,_vallen) \
+ protocol->prepare_for_resend (); \
+ protocol->store ( "SPHINX", 6, system_charset_info ); \
+ protocol->store ( _key, _keylen, system_charset_info ); \
+ protocol->store ( _val, _vallen, system_charset_info ); \
+ if ( protocol->write() ) \
+ SPH_RET(TRUE);
+
#endif
+
+ // show query stats
if ( pTls && pTls->m_bStats )
{
const CSphSEStats * pStats = &pTls->m_tStats;
buf1len = my_snprintf ( buf1, sizeof(buf1),
- "total: %d, total found: %d, time: %d, words: %d",
+ "total: %d, total found: %d, time: %d, words: %d",
pStats->m_iMatchesTotal, pStats->m_iMatchesFound, pStats->m_iQueryMsec, pStats->m_iWords );
-#if MYSQL_VERSION_ID>50100
- stat_print ( thd, sphinx_hton_name, strlen(sphinx_hton_name),
- STRING_WITH_LEN("stats"), buf1, buf1len );
-#else
- field_list.push_back ( new Item_empty_string ( "Type",10 ) );
- field_list.push_back ( new Item_empty_string ( "Name",FN_REFLEN ) );
- field_list.push_back ( new Item_empty_string ( "Status",10 ) );
- if ( protocol->send_fields ( &field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF ) )
- SPH_RET(TRUE);
-
- protocol->prepare_for_resend ();
- protocol->store ( STRING_WITH_LEN("SPHINX"), system_charset_info );
- protocol->store ( STRING_WITH_LEN("stats"), system_charset_info );
- protocol->store ( buf1, buf1len, system_charset_info );
- if ( protocol->write() )
- SPH_RET(TRUE);
-#endif
+ LOC_STATS ( "stats", 5, buf1, buf1len );
if ( pStats->m_iWords )
{
@@ -815,58 +870,30 @@ bool sphinx_show_status ( THD * thd )
iWord = sBuf3.length();
}
-#if MYSQL_VERSION_ID>50100
- stat_print ( thd, sphinx_hton_name, strlen(sphinx_hton_name),
- STRING_WITH_LEN("words"), sWord, iWord );
-#else
- protocol->prepare_for_resend ();
- protocol->store ( STRING_WITH_LEN("SPHINX"), system_charset_info );
- protocol->store ( STRING_WITH_LEN("words"), system_charset_info );
- protocol->store ( sWord, iWord, system_charset_info );
- if ( protocol->write() )
- SPH_RET(TRUE);
-#endif
+ LOC_STATS ( "words", 5, sWord, iWord );
}
+ }
- // send last error or warning
- if ( pStats->m_sLastMessage && pStats->m_sLastMessage[0] )
- {
- const char * sMessageType = pStats->m_bLastError ? "error" : "warning";
+ // show last error or warning (either in addition to stats, or on their own)
+ if ( pTls && pTls->m_tStats.m_sLastMessage && pTls->m_tStats.m_sLastMessage[0] )
+ {
+ const char * sMessageType = pTls->m_tStats.m_bLastError ? "error" : "warning";
-#if MYSQL_VERSION_ID>50100
- stat_print ( thd, sphinx_hton_name, strlen(sphinx_hton_name),
- sMessageType, strlen(sMessageType), pStats->m_sLastMessage, strlen(pStats->m_sLastMessage) );
-#else
- protocol->prepare_for_resend ();
- protocol->store ( STRING_WITH_LEN("SPHINX"), system_charset_info );
- protocol->store ( sMessageType, strlen(sMessageType), system_charset_info );
- protocol->store ( pStats->m_sLastMessage, strlen(pStats->m_sLastMessage), system_charset_info );
- if ( protocol->write() )
- SPH_RET(TRUE);
-#endif
- }
+ LOC_STATS (
+ sMessageType, strlen ( sMessageType ),
+ pTls->m_tStats.m_sLastMessage, strlen ( pTls->m_tStats.m_sLastMessage ) );
} else
{
- #if MYSQL_VERSION_ID < 50100
- field_list.push_back ( new Item_empty_string ( "Type", 10 ) );
- field_list.push_back ( new Item_empty_string ( "Name", FN_REFLEN ) );
- field_list.push_back ( new Item_empty_string ( "Status", 10 ) );
- if ( protocol->send_fields ( &field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF ) )
- SPH_RET(TRUE);
-
- protocol->prepare_for_resend ();
- protocol->store ( STRING_WITH_LEN("SPHINX"), system_charset_info );
- protocol->store ( STRING_WITH_LEN("stats"), system_charset_info );
- protocol->store ( STRING_WITH_LEN("no query has been executed yet"), system_charset_info );
- if ( protocol->write() )
- SPH_RET(TRUE);
- #endif
+ // well, nothing to show just yet
+#if MYSQL_VERSION_ID < 50100
+ LOC_STATS ( "stats", 5, "no query has been executed yet", sizeof("no query has been executed yet")-1 );
+#endif
}
- #if MYSQL_VERSION_ID < 50100
+#if MYSQL_VERSION_ID < 50100
send_eof(thd);
- #endif
+#endif
SPH_RET(FALSE);
}
@@ -933,10 +960,9 @@ static void sphLogError ( const char * sFmt, ... )
// the following scheme variants are recognized
//
-// sphinx://host/index
-// sphinx://host:port/index
-// unix://unix/domain/socket:index
-// unix://unix/domain/socket
+// sphinx://host[:port]/index
+// sphinxql://host[:port]/index
+// unix://unix/domain/socket[:index]
static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
{
SPH_ENTER_FUNC();
@@ -946,12 +972,12 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
// check incoming stuff
if ( !table )
{
- sphLogError ( "table==NULL in ParseUrl()" );
+ sphLogError ( "table==NULL in ParseUrl()" );
return false;
}
if ( !table->s )
{
- sphLogError ( "(table->s)==NULL in ParseUrl()" );
+ sphLogError ( "(table->s)==NULL in ParseUrl()" );
return false;
}
@@ -973,69 +999,121 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
}
}
+ // defaults
+ bool bOk = true;
+ bool bQL = false;
char * sScheme = NULL;
- char * sHost = (char*) SPHINXSE_DEFAULT_HOST;
- char * sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
- int iPort = SPHINXSE_DEFAULT_PORT;
+ char * sHost = (char*) SPHINXAPI_DEFAULT_HOST;
+ char * sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
+ int iPort = SPHINXAPI_DEFAULT_PORT;
- bool bOk = true;
+ // parse connection string, if any
while ( table->s->connect_string.length!=0 )
{
- bOk = false;
sScheme = sphDup ( table->s->connect_string.str, table->s->connect_string.length );
sHost = strstr ( sScheme, "://" );
if ( !sHost )
+ {
+ bOk = false;
break;
+ }
sHost[0] = '\0';
- sHost += 2;
+ sHost += 3;
+
+ /////////////////////////////
+ // sphinxapi via unix socket
+ /////////////////////////////
if ( !strcmp ( sScheme, "unix" ) )
{
- // unix-domain socket
+ sHost--; // reuse last slash
iPort = 0;
if (!( sIndex = strrchr ( sHost, ':' ) ))
- sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
+ sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
else
{
*sIndex++ = '\0';
if ( !*sIndex )
- sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
+ sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
}
bOk = true;
break;
}
- if( strcmp ( sScheme, "sphinx" )!=0 && strcmp ( sScheme, "inet" )!=0 )
- break;
- // tcp
- sHost++;
- char * sPort = strchr ( sHost, ':' );
- if ( sPort )
+ /////////////////////
+ // sphinxapi via tcp
+ /////////////////////
+
+ if ( !strcmp ( sScheme, "sphinx" ) )
{
- *sPort++ = '\0';
- if ( *sPort )
+ char * sPort = strchr ( sHost, ':' );
+ if ( sPort )
+ {
+ *sPort++ = '\0';
+ if ( *sPort )
+ {
+ sIndex = strchr ( sPort, '/' );
+ if ( sIndex )
+ *sIndex++ = '\0';
+ else
+ sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
+
+ iPort = atoi(sPort);
+ if ( !iPort )
+ iPort = SPHINXAPI_DEFAULT_PORT;
+ }
+ } else
{
- sIndex = strchr ( sPort, '/' );
+ sIndex = strchr ( sHost, '/' );
if ( sIndex )
- *sIndex++ = '\0';
+ *sIndex++ = '\0';
else
- sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
+ sIndex = (char*) SPHINXAPI_DEFAULT_INDEX;
+ }
+ bOk = true;
+ break;
+ }
+
+ ////////////
+ // sphinxql
+ ////////////
+
+ if ( !strcmp ( sScheme, "sphinxql" ) )
+ {
+ bQL = true;
+ iPort = SPHINXQL_DEFAULT_PORT;
+
+ // handle port
+ char * sPort = strchr ( sHost, ':' );
+ sIndex = sHost; // starting point for index name search
+
+ if ( sPort )
+ {
+ *sPort++ = '\0';
+ sIndex = sPort;
iPort = atoi(sPort);
if ( !iPort )
- iPort = SPHINXSE_DEFAULT_PORT;
+ {
+ bOk = false; // invalid port; can report ER_FOREIGN_DATA_STRING_INVALID
+ break;
+ }
}
- } else
- {
- sIndex = strchr ( sHost, '/' );
+
+ // find index
+ sIndex = strchr ( sIndex, '/' );
if ( sIndex )
*sIndex++ = '\0';
- else
- sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
+
+ // final checks
+ // host and index names are required
+ bOk = ( sHost && *sHost && sIndex && *sIndex );
+ break;
}
- bOk = true;
+ // unknown case
+ bOk = false;
break;
}
@@ -1052,6 +1130,7 @@ static bool ParseUrl ( CSphSEShare * share, TABLE * table, bool bCreate )
share->m_sHost = sHost;
share->m_sIndex = sIndex;
share->m_iPort = (ushort)iPort;
+ share->m_bSphinxQL = bQL;
}
}
if ( !bOk && !share )
@@ -1074,12 +1153,12 @@ static CSphSEShare * get_share ( const char * table_name, TABLE * table )
{
// check if we already have this share
#if MYSQL_VERSION_ID>=50120
- pShare = (CSphSEShare*) my_hash_search ( &sphinx_open_tables, (const uchar *) table_name, strlen(table_name) );
+ pShare = (CSphSEShare*) sphinx_hash_search ( &sphinx_open_tables, (const uchar *) table_name, strlen(table_name) );
#else
#ifdef __WIN__
- pShare = (CSphSEShare*) my_hash_search ( &sphinx_open_tables, (const byte *) table_name, strlen(table_name) );
+ pShare = (CSphSEShare*) sphinx_hash_search ( &sphinx_open_tables, (const byte *) table_name, strlen(table_name) );
#else
- pShare = (CSphSEShare*) my_hash_search ( &sphinx_open_tables, table_name, strlen(table_name) );
+ pShare = (CSphSEShare*) sphinx_hash_search ( &sphinx_open_tables, table_name, strlen(table_name) );
#endif // win
#endif // pre-5.1.20
@@ -1095,13 +1174,15 @@ static CSphSEShare * get_share ( const char * table_name, TABLE * table )
break;
// try to setup it
- pShare->m_pTableQueryCharset = table->field[2]->charset();
if ( !ParseUrl ( pShare, table, false ) )
{
SafeDelete ( pShare );
break;
}
+ if ( !pShare->m_bSphinxQL )
+ pShare->m_pTableQueryCharset = table->field[2]->charset();
+
// try to hash it
pShare->m_iTableNameLen = strlen(table_name);
pShare->m_sTable = sphDup ( table_name );
@@ -1129,7 +1210,7 @@ static int free_share ( CSphSEShare * pShare )
if ( !--pShare->m_iUseCount )
{
- my_hash_delete ( &sphinx_open_tables, (byte *)pShare );
+ sphinx_hash_delete ( &sphinx_open_tables, (byte *)pShare );
SafeDelete ( pShare );
}
@@ -1141,6 +1222,7 @@ static int free_share ( CSphSEShare * pShare )
#if MYSQL_VERSION_ID>50100
static handler * sphinx_create_handler ( handlerton * hton, TABLE_SHARE * table, MEM_ROOT * mem_root )
{
+ sphinx_hton_ptr = hton;
return new ( mem_root ) ha_sphinx ( hton, table );
}
#endif
@@ -1152,37 +1234,39 @@ static handler * sphinx_create_handler ( handlerton * hton, TABLE_SHARE * table,
CSphSEQuery::CSphSEQuery ( const char * sQuery, int iLength, const char * sIndex )
: m_sHost ( "" )
, m_iPort ( 0 )
- , m_sIndex ( sIndex ? sIndex : (char*) "*" )
+ , m_sIndex ( sIndex ? sIndex : "*" )
, m_iOffset ( 0 )
, m_iLimit ( 20 )
, m_bQuery ( false )
- , m_sQuery ( (char*) "" )
+ , m_sQuery ( "" )
, m_pWeights ( NULL )
, m_iWeights ( 0 )
, m_eMode ( SPH_MATCH_ALL )
, m_eRanker ( SPH_RANK_PROXIMITY_BM25 )
+ , m_sRankExpr ( NULL )
, m_eSort ( SPH_SORT_RELEVANCE )
- , m_sSortBy ( (char*) "" )
+ , m_sSortBy ( "" )
, m_iMaxMatches ( 1000 )
, m_iMaxQueryTime ( 0 )
, m_iMinID ( 0 )
, m_iMaxID ( 0 )
, m_iFilters ( 0 )
, m_eGroupFunc ( SPH_GROUPBY_DAY )
- , m_sGroupBy ( (char*) "" )
- , m_sGroupSortBy ( (char*) "@group desc" )
+ , m_sGroupBy ( "" )
+ , m_sGroupSortBy ( "@group desc" )
, m_iCutoff ( 0 )
, m_iRetryCount ( 0 )
, m_iRetryDelay ( 0 )
- , m_sGroupDistinct ( (char*) "" )
+ , m_sGroupDistinct ( "" )
, m_iIndexWeights ( 0 )
, m_iFieldWeights ( 0 )
, m_bGeoAnchor ( false )
- , m_sGeoLatAttr ( (char*) "" )
- , m_sGeoLongAttr ( (char*) "" )
+ , m_sGeoLatAttr ( "" )
+ , m_sGeoLongAttr ( "" )
, m_fGeoLatitude ( 0.0f )
, m_fGeoLongitude ( 0.0f )
- , m_sComment ( (char*) "" )
+ , m_sComment ( "" )
+ , m_sSelect ( "" )
, m_pBuf ( NULL )
, m_pCur ( NULL )
@@ -1191,8 +1275,8 @@ CSphSEQuery::CSphSEQuery ( const char * sQuery, int iLength, const char * sIndex
{
m_sQueryBuffer = new char [ iLength+2 ];
memcpy ( m_sQueryBuffer, sQuery, iLength );
- m_sQueryBuffer[iLength]= ';';
- m_sQueryBuffer[iLength+1]= '\0';
+ m_sQueryBuffer[iLength] = ';';
+ m_sQueryBuffer[iLength+1] = '\0';
}
@@ -1248,22 +1332,20 @@ int CSphSEQuery::ParseArray ( T ** ppValues, const char * sValue )
if ( !bPrevDigit )
uValue = 0;
uValue = uValue*10 + ( (*pValue)-'0' );
- }
- else if ( bPrevDigit )
+ } else if ( bPrevDigit )
{
assert ( iIndex<iValues );
pValues [ iIndex++ ] = uValue * iSign;
iSign = 1;
- }
- else if ( *pValue=='-' )
+ } else if ( *pValue=='-' )
iSign = -1;
- bPrevDigit = bDigit;
+ bPrevDigit = bDigit;
if ( !*pValue )
break;
}
- SPH_RET(iValues);
+ SPH_RET ( iValues );
}
@@ -1273,7 +1355,7 @@ static char * chop ( char * s )
s++;
char * p = s + strlen(s);
- while ( p>s && isspace(p[-1]) )
+ while ( p>s && isspace ( p[-1] ) )
p--;
*p = '\0';
@@ -1311,11 +1393,13 @@ bool CSphSEQuery::ParseField ( char * sField )
m_sQuery = sField;
m_bQuery = true;
- // unescape
+ // unescape only 1st one
char *s = sField, *d = sField;
+ int iSlashes = 0;
while ( *s )
{
- if ( *s!='\\' ) *d++ = *s;
+ iSlashes = ( *s=='\\' ) ? iSlashes+1 : 0;
+ if ( ( iSlashes%2 )==0 ) *d++ = *s;
s++;
}
*d = '\0';
@@ -1347,20 +1431,20 @@ bool CSphSEQuery::ParseField ( char * sField )
else if ( !strcmp ( sName, "distinct" ) ) m_sGroupDistinct = sValue;
else if ( !strcmp ( sName, "cutoff" ) ) m_iCutoff = iValue;
else if ( !strcmp ( sName, "comment" ) ) m_sComment = sValue;
+ else if ( !strcmp ( sName, "select" ) ) m_sSelect = sValue;
else if ( !strcmp ( sName, "mode" ) )
{
-
m_eMode = SPH_MATCH_ALL;
- if ( !strcmp ( sValue, "any") ) m_eMode = SPH_MATCH_ANY;
+ if ( !strcmp ( sValue, "any" ) ) m_eMode = SPH_MATCH_ANY;
else if ( !strcmp ( sValue, "phrase" ) ) m_eMode = SPH_MATCH_PHRASE;
- else if ( !strcmp ( sValue, "boolean") ) m_eMode = SPH_MATCH_BOOLEAN;
- else if ( !strcmp ( sValue, "ext") ) m_eMode = SPH_MATCH_EXTENDED;
- else if ( !strcmp ( sValue, "extended") ) m_eMode = SPH_MATCH_EXTENDED;
- else if ( !strcmp ( sValue, "ext2") ) m_eMode = SPH_MATCH_EXTENDED2;
- else if ( !strcmp ( sValue, "extended2") ) m_eMode = SPH_MATCH_EXTENDED2;
- else if ( !strcmp ( sValue, "all") ) m_eMode = SPH_MATCH_ALL;
- else if ( !strcmp ( sValue, "fullscan") ) m_eMode = SPH_MATCH_FULLSCAN;
+ else if ( !strcmp ( sValue, "boolean" ) ) m_eMode = SPH_MATCH_BOOLEAN;
+ else if ( !strcmp ( sValue, "ext" ) ) m_eMode = SPH_MATCH_EXTENDED;
+ else if ( !strcmp ( sValue, "extended" ) ) m_eMode = SPH_MATCH_EXTENDED;
+ else if ( !strcmp ( sValue, "ext2" ) ) m_eMode = SPH_MATCH_EXTENDED2;
+ else if ( !strcmp ( sValue, "extended2" ) ) m_eMode = SPH_MATCH_EXTENDED2;
+ else if ( !strcmp ( sValue, "all" ) ) m_eMode = SPH_MATCH_ALL;
+ else if ( !strcmp ( sValue, "fullscan" ) ) m_eMode = SPH_MATCH_FULLSCAN;
else
{
snprintf ( m_sParseError, sizeof(m_sParseError), "unknown matching mode '%s'", sValue );
@@ -1368,27 +1452,31 @@ bool CSphSEQuery::ParseField ( char * sField )
}
} else if ( !strcmp ( sName, "ranker" ) )
{
-
m_eRanker = SPH_RANK_PROXIMITY_BM25;
- if ( !strcmp ( sValue, "proximity_bm25") ) m_eRanker = SPH_RANK_PROXIMITY_BM25;
+ if ( !strcmp ( sValue, "proximity_bm25" ) ) m_eRanker = SPH_RANK_PROXIMITY_BM25;
else if ( !strcmp ( sValue, "bm25" ) ) m_eRanker = SPH_RANK_BM25;
else if ( !strcmp ( sValue, "none" ) ) m_eRanker = SPH_RANK_NONE;
else if ( !strcmp ( sValue, "wordcount" ) ) m_eRanker = SPH_RANK_WORDCOUNT;
else if ( !strcmp ( sValue, "proximity" ) ) m_eRanker = SPH_RANK_PROXIMITY;
else if ( !strcmp ( sValue, "matchany" ) ) m_eRanker = SPH_RANK_MATCHANY;
else if ( !strcmp ( sValue, "fieldmask" ) ) m_eRanker = SPH_RANK_FIELDMASK;
- else
+ else if ( !strcmp ( sValue, "sph04" ) ) m_eRanker = SPH_RANK_SPH04;
+ else if ( !strncmp ( sValue, "expr:", 5 ) )
+ {
+ m_eRanker = SPH_RANK_EXPR;
+ m_sRankExpr = sValue+5;
+ } else
{
snprintf ( m_sParseError, sizeof(m_sParseError), "unknown ranking mode '%s'", sValue );
SPH_RET(false);
}
} else if ( !strcmp ( sName, "sort" ) )
{
- static const struct
+ static const struct
{
const char * m_sName;
ESphSortOrder m_eSort;
- } dSortModes[] =
+ } dSortModes[] =
{
{ "relevance", SPH_SORT_RELEVANCE },
{ "attr_desc:", SPH_SORT_ATTR_DESC },
@@ -1401,10 +1489,10 @@ bool CSphSEQuery::ParseField ( char * sField )
int i;
const int nModes = sizeof(dSortModes)/sizeof(dSortModes[0]);
for ( i=0; i<nModes; i++ )
- if ( !strncmp ( sValue, dSortModes[i].m_sName, strlen(dSortModes[i].m_sName) ) )
+ if ( !strncmp ( sValue, dSortModes[i].m_sName, strlen ( dSortModes[i].m_sName ) ) )
{
m_eSort = dSortModes[i].m_eSort;
- m_sSortBy = sValue + strlen(dSortModes[i].m_sName);
+ m_sSortBy = sValue + strlen ( dSortModes[i].m_sName );
break;
}
if ( i==nModes )
@@ -1415,11 +1503,11 @@ bool CSphSEQuery::ParseField ( char * sField )
} else if ( !strcmp ( sName, "groupby" ) )
{
- static const struct
+ static const struct
{
const char * m_sName;
ESphGroupBy m_eFunc;
- } dGroupModes[] =
+ } dGroupModes[] =
{
{ "day:", SPH_GROUPBY_DAY },
{ "week:", SPH_GROUPBY_WEEK },
@@ -1431,10 +1519,10 @@ bool CSphSEQuery::ParseField ( char * sField )
int i;
const int nModes = sizeof(dGroupModes)/sizeof(dGroupModes[0]);
for ( i=0; i<nModes; i++ )
- if ( !strncmp ( sValue, dGroupModes[i].m_sName, strlen(dGroupModes[i].m_sName) ) )
+ if ( !strncmp ( sValue, dGroupModes[i].m_sName, strlen ( dGroupModes[i].m_sName ) ) )
{
m_eGroupFunc = dGroupModes[i].m_eFunc;
- m_sGroupBy = sValue + strlen(dGroupModes[i].m_sName);
+ m_sGroupBy = sValue + strlen ( dGroupModes[i].m_sName );
break;
}
if ( i==nModes )
@@ -1486,7 +1574,7 @@ bool CSphSEQuery::ParseField ( char * sField )
{
CSphSEFilter & tFilter = m_dFilters [ m_iFilters ];
tFilter.m_eType = SPH_FILTER_VALUES;
- tFilter.m_bExclude = ( strcmp ( sName, "!filter")==0 );
+ tFilter.m_bExclude = ( strcmp ( sName, "!filter" )==0 );
// get the attr name
while ( (*sValue) && !myisattr(*sValue) )
@@ -1554,7 +1642,8 @@ bool CSphSEQuery::ParseField ( char * sField )
pWeights[*pCount] = atoi(sVal);
(*pCount)++;
- if ( !*p ) break;
+ if ( !*p )
+ break;
if ( *p!=',' )
{
snprintf ( m_sParseError, sizeof(m_sParseError), "%s: comma expected near '%s'", sName, p );
@@ -1582,8 +1671,8 @@ bool CSphSEQuery::ParseField ( char * sField )
m_sGeoLatAttr = chop(sLat);
m_sGeoLongAttr = chop(sLong);
- m_fGeoLatitude = (float)atof(sLatVal);
- m_fGeoLongitude = (float)atof(sLongVal);
+ m_fGeoLatitude = (float)atof ( sLatVal );
+ m_fGeoLongitude = (float)atof ( sLongVal );
m_bGeoAnchor = true;
break;
}
@@ -1592,8 +1681,7 @@ bool CSphSEQuery::ParseField ( char * sField )
snprintf ( m_sParseError, sizeof(m_sParseError), "geoanchor: parse error, not enough comma-separated arguments" );
SPH_RET(false);
}
- }
- else if ( !strcmp ( sName, "override" ) ) // name,type,id:value,id:value,...
+ } else if ( !strcmp ( sName, "override" ) ) // name,type,id:value,id:value,...
{
char * sName = NULL;
int iType = 0;
@@ -1606,11 +1694,13 @@ bool CSphSEQuery::ParseField ( char * sField )
sName = sRest;
if ( !*sName )
break;
-
- if (!( sRest = strchr ( sRest, ',' ) )) break; *sRest++ = '\0';
+ if (!( sRest = strchr ( sRest, ',' ) ))
+ break;
+ *sRest++ = '\0';
char * sType = sRest;
- if (!( sRest = strchr ( sRest, ',' ) )) break;
-
+ if (!( sRest = strchr ( sRest, ',' ) ))
+ break;
+
static const struct
{
const char * m_sName;
@@ -1625,7 +1715,7 @@ bool CSphSEQuery::ParseField ( char * sField )
{ "bigint", SPH_ATTR_BIGINT }
};
for ( uint i=0; i<sizeof(dAttrTypes)/sizeof(*dAttrTypes); i++ )
- if ( !strncmp( sType, dAttrTypes[i].m_sName, sRest - sType ) )
+ if ( !strncmp ( sType, dAttrTypes[i].m_sName, sRest - sType ) )
{
iType = dAttrTypes[i].m_iType;
break;
@@ -1634,7 +1724,7 @@ bool CSphSEQuery::ParseField ( char * sField )
}
// fail
- if ( !sName || !*sName || !iType )
+ if ( !sName || !*sName || !iType )
{
snprintf ( m_sParseError, sizeof(m_sParseError), "override: malformed query" );
SPH_RET(false);
@@ -1649,7 +1739,8 @@ bool CSphSEQuery::ParseField ( char * sField )
if (!( sRest - sId )) break;
char * sValue = sRest;
- if (( sRest = strchr ( sRest, ',' ) )) *sRest++ = '\0';
+ if ( ( sRest = strchr ( sRest, ',' ) )!=NULL )
+ *sRest++ = '\0';
if ( !*sValue )
break;
@@ -1658,18 +1749,18 @@ 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.append ( pOverride );
}
ulonglong uId = strtoull ( sId, NULL, 10 );
CSphSEQuery::Override_t::Value_t tValue;
- if ( iType == SPH_ATTR_FLOAT )
+ if ( iType==SPH_ATTR_FLOAT )
tValue.m_fValue = (float)atof(sValue);
- else if ( iType == SPH_ATTR_BIGINT )
+ else if ( iType==SPH_ATTR_BIGINT )
tValue.m_iValue64 = strtoll ( sValue, NULL, 10 );
else
tValue.m_uValue = (uint32)strtoul ( sValue, NULL, 10 );
-
+
pOverride->m_dIds.append ( uId );
pOverride->m_dValues.append ( tValue );
}
@@ -1680,8 +1771,7 @@ bool CSphSEQuery::ParseField ( char * sField )
SPH_RET(false);
}
SPH_RET(true);
- }
- else
+ } else
{
snprintf ( m_sParseError, sizeof(m_sParseError), "unknown parameter '%s'", sName );
SPH_RET(false);
@@ -1702,7 +1792,7 @@ bool CSphSEQuery::Parse ()
char * pCur = m_sQueryBuffer;
char * pNext = pCur;
- while (( pNext = strchr ( pNext, ';' ) ))
+ while ( ( pNext = strchr ( pNext, ';' ) )!=NULL )
{
// handle escaped semicolons
if ( pNext>m_sQueryBuffer && pNext[-1]=='\\' && pNext[1]!='\0' )
@@ -1718,6 +1808,8 @@ bool CSphSEQuery::Parse ()
pCur = pNext;
}
+ SPH_DEBUG ( "q [[ %s ]]", m_sQuery );
+
SPH_RET(true);
}
@@ -1744,14 +1836,17 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
SPH_ENTER_METHOD();
// calc request length
- int iReqSize = 124 + 4*m_iWeights
+ int iReqSize = 128 + 4*m_iWeights
+ strlen ( m_sSortBy )
+ strlen ( m_sQuery )
+ strlen ( m_sIndex )
+ strlen ( m_sGroupBy )
+ strlen ( m_sGroupSortBy )
+ strlen ( m_sGroupDistinct )
- + strlen ( m_sComment );
+ + strlen ( m_sComment )
+ + strlen ( m_sSelect );
+ if ( m_eRanker==SPH_RANK_EXPR )
+ iReqSize += 4 + strlen(m_sRankExpr);
for ( int i=0; i<m_iFilters; i++ )
{
const CSphSEFilter & tFilter = m_dFilters[i];
@@ -1764,7 +1859,7 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
}
}
if ( m_bGeoAnchor ) // 1.14+
- iReqSize += 16 + strlen ( m_sGeoLatAttr ) + strlen ( m_sGeoLongAttr );
+ iReqSize += 16 + strlen ( m_sGeoLatAttr ) + strlen ( m_sGeoLongAttr );
for ( int i=0; i<m_iIndexWeights; i++ ) // 1.15+
iReqSize += 8 + strlen(m_sIndexWeight[i] );
for ( int i=0; i<m_iFieldWeights; i++ ) // 1.18+
@@ -1774,12 +1869,12 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
for ( int i=0; i<m_dOverrides.elements(); i++ )
{
CSphSEQuery::Override_t * pOverride = m_dOverrides.at(i);
- const uint32 uSize = pOverride->m_iType == SPH_ATTR_BIGINT ? 16 : 12; // id64 + value
+ const uint32 uSize = pOverride->m_iType==SPH_ATTR_BIGINT ? 16 : 12; // id64 + value
iReqSize += strlen ( pOverride->m_sName ) + 12 + uSize*pOverride->m_dIds.elements();
}
// select
iReqSize += 4;
-
+
m_iBufLeft = 0;
SafeDeleteArray ( m_pBuf );
@@ -1796,12 +1891,15 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
SendWord ( SEARCHD_COMMAND_SEARCH ); // command id
SendWord ( VER_COMMAND_SEARCH ); // command version
SendInt ( iReqSize-8 ); // packet body length
+ SendInt ( 0 ); // its a client
SendInt ( 1 ); // number of queries
SendInt ( m_iOffset );
SendInt ( m_iLimit );
SendInt ( m_eMode );
SendInt ( m_eRanker ); // 1.16+
+ if ( m_eRanker==SPH_RANK_EXPR )
+ SendString ( m_sRankExpr );
SendInt ( m_eSort );
SendString ( m_sSortBy ); // sort attr
SendString ( m_sQuery ); // query
@@ -1884,9 +1982,9 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
for ( int j=0; j<pOverride->m_dIds.elements(); j++ )
{
SendUint64 ( pOverride->m_dIds.at(j) );
- if ( pOverride->m_iType == SPH_ATTR_FLOAT )
+ if ( pOverride->m_iType==SPH_ATTR_FLOAT )
SendFloat ( pOverride->m_dValues.at(j).m_fValue );
- else if ( pOverride->m_iType == SPH_ATTR_BIGINT )
+ else if ( pOverride->m_iType==SPH_ATTR_BIGINT )
SendUint64 ( pOverride->m_dValues.at(j).m_iValue64 );
else
SendDword ( pOverride->m_dValues.at(j).m_uValue );
@@ -1894,14 +1992,14 @@ int CSphSEQuery::BuildRequest ( char ** ppBuffer )
}
// select
- SendString ( "" );
+ SendString ( m_sSelect );
// detect buffer overruns and underruns, and report internal error
if ( m_bBufOverrun || m_iBufLeft!=0 || m_pCur-m_pBuf!=iReqSize )
SPH_RET(-1);
// all fine
- SPH_RET(iReqSize);
+ SPH_RET ( iReqSize );
}
//////////////////////////////////////////////////////////////////////////////
@@ -1938,6 +2036,18 @@ ha_sphinx::ha_sphinx ( handlerton * hton, TABLE_ARG * table )
SPH_VOID_RET();
}
+ha_sphinx::~ha_sphinx()
+{
+ SafeDeleteArray ( m_dAttrs );
+ SafeDeleteArray ( m_dUnboundFields );
+ if ( m_dFields )
+ {
+ for (uint32 i=0; i< m_iFields; i++ )
+ SafeDeleteArray ( m_dFields[i] );
+ delete [] m_dFields;
+ }
+}
+
// If frm_error() is called then we will use this to to find out what file extentions
// exist for the storage engine. This is also used by the default rename_table and
@@ -1964,16 +2074,24 @@ int ha_sphinx::open ( const char * name, int, uint )
thr_lock_data_init ( &m_pShare->m_tLock, &m_tLock, NULL );
- *thd_ha_data ( table->in_use, ht ) = NULL;
+ #if MYSQL_VERSION_ID>50100
+ void **tmp= thd_ha_data(table->in_use, ht);
+ if (*tmp)
+ {
+ CSphSEThreadData* pTls = (CSphSEThreadData*) *tmp;
+ SafeDelete(pTls);
+ *tmp= NULL;
+ }
+ #else
+ table->in_use->ha_data [ sphinx_hton.slot ] = NULL;
+ #endif
SPH_RET(0);
}
-int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
+int ha_sphinx::Connect ( const char * sHost, ushort uPort )
{
- SPH_ENTER_METHOD();
-
struct sockaddr_in sin;
#ifndef __WIN__
struct sockaddr_un saun;
@@ -1984,13 +2102,8 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
struct sockaddr * pSockaddr = NULL;
in_addr_t ip_addr;
- int version;
- uint uClientVersion = htonl ( SPHINX_SEARCHD_PROTO );
- const char * sHost = ( sQueryHost && *sQueryHost ) ? sQueryHost : m_pShare->m_sHost;
- ushort iPort = iQueryPort ? (ushort)iQueryPort : m_pShare->m_iPort;
-
- if ( iPort )
+ if ( uPort )
{
iDomain = AF_INET;
iSockaddrSize = sizeof(sin);
@@ -1998,39 +2111,53 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
memset ( &sin, 0, sizeof(sin) );
sin.sin_family = AF_INET;
- sin.sin_port = htons(iPort);
-
+ sin.sin_port = htons(uPort);
+
// prepare host address
- if ( (int)( ip_addr=inet_addr(sHost) ) != (int)INADDR_NONE )
- {
+ if ( (int)( ip_addr = inet_addr(sHost) )!=(int)INADDR_NONE )
+ {
memcpy ( &sin.sin_addr, &ip_addr, sizeof(ip_addr) );
} else
{
- int err_code;
- struct addrinfo hints;
- struct addrinfo *addr_info_list;
+ int tmp_errno;
+ bool bError = false;
- memset(&hints, 0, sizeof (struct addrinfo));
- hints.ai_flags= AI_PASSIVE;
- hints.ai_socktype= SOCK_STREAM;
- hints.ai_family= AF_UNSPEC;
-
- err_code= getaddrinfo(sHost, NULL, &hints,
- &addr_info_list);
+#if MYSQL_VERSION_ID>=50515
+ struct addrinfo *hp = NULL;
+ tmp_errno = getaddrinfo ( sHost, NULL, NULL, &hp );
+ if ( !tmp_errno || !hp || !hp->ai_addr )
+ {
+ bError = true;
+ if ( hp )
+ freeaddrinfo ( hp );
+ }
+#else
+ struct hostent tmp_hostent, *hp;
+ char buff2 [ GETHOSTBYNAME_BUFF_SIZE ];
+ hp = my_gethostbyname_r ( sHost, &tmp_hostent, buff2, sizeof(buff2), &tmp_errno );
+ if ( !hp )
+ {
+ my_gethostbyname_r_free();
+ bError = true;
+ }
+#endif
- if ( err_code )
- {
+ if ( bError )
+ {
char sError[256];
my_snprintf ( sError, sizeof(sError), "failed to resolve searchd host (name=%s)", sHost );
-
+
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
SPH_RET(-1);
}
- memcpy ( &sin.sin_addr, addr_info_list->ai_addr,
- Min ( sizeof(sin.sin_addr), (size_t)addr_info_list->ai_addrlen ) );
-
- freeaddrinfo(addr_info_list);
+#if MYSQL_VERSION_ID>=50515
+ memcpy ( &sin.sin_addr, hp->ai_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->ai_addrlen ) );
+ freeaddrinfo ( hp );
+#else
+ memcpy ( &sin.sin_addr, hp->h_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->h_length ) );
+ my_gethostbyname_r_free();
+#endif
}
} else
{
@@ -2061,30 +2188,49 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
{
sphSockClose ( iSocket );
my_snprintf ( sError, sizeof(sError), "failed to connect to searchd (host=%s, errno=%d, port=%d)",
- sHost, errno, iPort );
+ sHost, errno, (int)uPort );
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
SPH_RET(-1);
}
+ return iSocket;
+}
+
+
+int ha_sphinx::ConnectAPI ( const char * sQueryHost, int iQueryPort )
+{
+ SPH_ENTER_METHOD();
+
+ const char * sHost = ( sQueryHost && *sQueryHost ) ? sQueryHost : m_pShare->m_sHost;
+ ushort uPort = iQueryPort ? (ushort)iQueryPort : m_pShare->m_iPort;
+
+ int iSocket = Connect ( sHost, uPort );
+ if ( iSocket<0 )
+ SPH_RET ( iSocket );
+
+ char sError[512];
+
+ int version;
if ( ::recv ( iSocket, (char *)&version, sizeof(version), 0 )!=sizeof(version) )
{
sphSockClose ( iSocket );
my_snprintf ( sError, sizeof(sError), "failed to receive searchd version (host=%s, port=%d)",
- sHost, iPort );
+ sHost, (int)uPort );
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
SPH_RET(-1);
}
+ uint uClientVersion = htonl ( SPHINX_SEARCHD_PROTO );
if ( ::send ( iSocket, (char*)&uClientVersion, sizeof(uClientVersion), 0 )!=sizeof(uClientVersion) )
{
sphSockClose ( iSocket );
my_snprintf ( sError, sizeof(sError), "failed to send client version (host=%s, port=%d)",
- sHost, iPort );
+ sHost, (int)uPort );
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
SPH_RET(-1);
}
- SPH_RET(iSocket);
+ SPH_RET ( iSocket );
}
@@ -2099,25 +2245,182 @@ int ha_sphinx::ConnectToSearchd ( const char * sQueryHost, int iQueryPort )
int ha_sphinx::close()
{
SPH_ENTER_METHOD();
- SPH_RET ( free_share(m_pShare) );
+ SPH_RET ( free_share ( m_pShare ) );
+}
+
+
+int ha_sphinx::HandleMysqlError ( MYSQL * pConn, int iErrCode )
+{
+ CSphSEThreadData * pTls = GetTls ();
+ if ( pTls )
+ {
+ strncpy ( pTls->m_tStats.m_sLastMessage, mysql_error ( pConn ), sizeof ( pTls->m_tStats.m_sLastMessage ) );
+ pTls->m_tStats.m_bLastError = true;
+ }
+
+ mysql_close ( pConn );
+
+ my_error ( iErrCode, MYF(0), pTls->m_tStats.m_sLastMessage );
+ return -1;
}
-int ha_sphinx::write_row ( uchar * )
+int ha_sphinx::extra ( enum ha_extra_function op )
+{
+ CSphSEThreadData * pTls = GetTls();
+ if ( pTls )
+ {
+ if ( op==HA_EXTRA_WRITE_CAN_REPLACE )
+ pTls->m_bReplace = true;
+ else if ( op==HA_EXTRA_WRITE_CANNOT_REPLACE )
+ pTls->m_bReplace = false;
+ }
+ return 0;
+}
+
+
+int ha_sphinx::write_row ( byte * )
{
SPH_ENTER_METHOD();
- SPH_RET ( HA_ERR_WRONG_COMMAND );
+ if ( !m_pShare || !m_pShare->m_bSphinxQL )
+ SPH_RET ( HA_ERR_WRONG_COMMAND );
+
+ // SphinxQL inserts only, pretty much similar to abandoned federated
+ char sQueryBuf[1024];
+ char sValueBuf[1024];
+
+ String sQuery ( sQueryBuf, sizeof(sQueryBuf), &my_charset_bin );
+ String sValue ( sValueBuf, sizeof(sQueryBuf), &my_charset_bin );
+ sQuery.length ( 0 );
+ sValue.length ( 0 );
+
+ CSphSEThreadData * pTls = GetTls ();
+ sQuery.append ( pTls && pTls->m_bReplace ? "REPLACE INTO " : "INSERT INTO " );
+ sQuery.append ( m_pShare->m_sIndex );
+ sQuery.append ( " (" );
+
+ for ( Field ** ppField = table->field; *ppField; ppField++ )
+ {
+ sQuery.append ( (*ppField)->field_name );
+ if ( ppField[1] )
+ sQuery.append ( ", " );
+ }
+ sQuery.append ( ") VALUES (" );
+
+ for ( Field ** ppField = table->field; *ppField; ppField++ )
+ {
+ if ( (*ppField)->is_null() )
+ {
+ sQuery.append ( "''" );
+
+ } else
+ {
+ if ( (*ppField)->type()==MYSQL_TYPE_TIMESTAMP )
+ {
+ Item_field * pWrap = new Item_field ( *ppField ); // autofreed by query arena, I assume
+ Item_func_unix_timestamp * pConv = new Item_func_unix_timestamp ( pWrap );
+ pConv->quick_fix_field();
+ unsigned int uTs = (unsigned int) pConv->val_int();
+
+ snprintf ( sValueBuf, sizeof(sValueBuf), "'%u'", uTs );
+ sQuery.append ( sValueBuf );
+
+ } else
+ {
+ (*ppField)->val_str ( &sValue );
+ sQuery.append ( "'" );
+ sValue.print ( &sQuery );
+ sQuery.append ( "'" );
+ sValue.length(0);
+ }
+ }
+
+ if ( ppField[1] )
+ sQuery.append ( ", " );
+ }
+ sQuery.append ( ")" );
+
+ // FIXME? pretty inefficient to reconnect every time under high load,
+ // but this was intentionally written for a low load scenario..
+ MYSQL * pConn = mysql_init ( NULL );
+ if ( !pConn )
+ SPH_RET ( ER_OUT_OF_RESOURCES );
+
+ unsigned int uTimeout = 1;
+ mysql_options ( pConn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&uTimeout );
+
+ if ( !mysql_real_connect ( pConn, m_pShare->m_sHost, "root", "", "", m_pShare->m_iPort, m_pShare->m_sSocket, 0 ) )
+ SPH_RET ( HandleMysqlError ( pConn, ER_CONNECT_TO_FOREIGN_DATA_SOURCE ) );
+
+ if ( mysql_real_query ( pConn, sQuery.ptr(), sQuery.length() ) )
+ SPH_RET ( HandleMysqlError ( pConn, ER_QUERY_ON_FOREIGN_DATA_SOURCE ) );
+
+ // all ok!
+ mysql_close ( pConn );
+ SPH_RET(0);
+}
+
+
+static inline bool IsIntegerFieldType ( enum_field_types eType )
+{
+ return eType==MYSQL_TYPE_LONG || eType==MYSQL_TYPE_LONGLONG;
}
-int ha_sphinx::update_row ( const uchar *, uchar * )
+static inline bool IsIDField ( Field * pField )
+{
+ enum_field_types eType = pField->type();
+
+ if ( eType==MYSQL_TYPE_LONGLONG )
+ return true;
+
+ if ( eType==MYSQL_TYPE_LONG && ((Field_num*)pField)->unsigned_flag )
+ return true;
+
+ return false;
+}
+
+
+int ha_sphinx::delete_row ( const byte * )
{
SPH_ENTER_METHOD();
- SPH_RET ( HA_ERR_WRONG_COMMAND );
+ if ( !m_pShare || !m_pShare->m_bSphinxQL )
+ SPH_RET ( HA_ERR_WRONG_COMMAND );
+
+ char sQueryBuf[1024];
+ String sQuery ( sQueryBuf, sizeof(sQueryBuf), &my_charset_bin );
+ sQuery.length ( 0 );
+
+ sQuery.append ( "DELETE FROM " );
+ sQuery.append ( m_pShare->m_sIndex );
+ sQuery.append ( " WHERE id=" );
+
+ char sValue[32];
+ snprintf ( sValue, sizeof(sValue), "%lld", table->field[0]->val_int() );
+ sQuery.append ( sValue );
+
+ // FIXME? pretty inefficient to reconnect every time under high load,
+ // but this was intentionally written for a low load scenario..
+ MYSQL * pConn = mysql_init ( NULL );
+ if ( !pConn )
+ SPH_RET ( ER_OUT_OF_RESOURCES );
+
+ unsigned int uTimeout = 1;
+ mysql_options ( pConn, MYSQL_OPT_CONNECT_TIMEOUT, (const char*)&uTimeout );
+
+ if ( !mysql_real_connect ( pConn, m_pShare->m_sHost, "root", "", "", m_pShare->m_iPort, m_pShare->m_sSocket, 0 ) )
+ SPH_RET ( HandleMysqlError ( pConn, ER_CONNECT_TO_FOREIGN_DATA_SOURCE ) );
+
+ if ( mysql_real_query ( pConn, sQuery.ptr(), sQuery.length() ) )
+ SPH_RET ( HandleMysqlError ( pConn, ER_QUERY_ON_FOREIGN_DATA_SOURCE ) );
+
+ // all ok!
+ mysql_close ( pConn );
+ SPH_RET(0);
}
-int ha_sphinx::delete_row ( const uchar * )
+int ha_sphinx::update_row ( const byte *, byte * )
{
SPH_ENTER_METHOD();
SPH_RET ( HA_ERR_WRONG_COMMAND );
@@ -2130,6 +2433,11 @@ int ha_sphinx::index_init ( uint keynr, bool )
{
SPH_ENTER_METHOD();
active_index = keynr;
+
+ CSphSEThreadData * pTls = GetTls();
+ if ( pTls )
+ pTls->m_bCondDone = false;
+
SPH_RET(0);
}
@@ -2141,17 +2449,28 @@ int ha_sphinx::index_end()
}
-uint32 ha_sphinx::UnpackDword ()
+bool ha_sphinx::CheckResponcePtr ( int iLen )
{
- if ( m_pCur+sizeof(uint32)>m_pResponseEnd )
+ if ( m_pCur+iLen>m_pResponseEnd )
{
m_pCur = m_pResponseEnd;
m_bUnpackError = true;
+ return false;
+ }
+
+ return true;
+}
+
+
+uint32 ha_sphinx::UnpackDword ()
+{
+ if ( !CheckResponcePtr ( sizeof(uint32) ) ) // NOLINT
+ {
return 0;
}
uint32 uRes = ntohl ( sphUnalignedRead ( *(uint32*)m_pCur ) );
- m_pCur += sizeof(uint32);
+ m_pCur += sizeof(uint32); // NOLINT
return uRes;
}
@@ -2162,10 +2481,8 @@ char * ha_sphinx::UnpackString ()
if ( !iLen )
return NULL;
- if ( m_pCur+iLen>m_pResponseEnd )
+ if ( !CheckResponcePtr ( iLen ) )
{
- m_pCur = m_pResponseEnd;
- m_bUnpackError = true;
return NULL;
}
@@ -2275,7 +2592,7 @@ bool ha_sphinx::UnpackSchema ()
m_iMatchesTotal = UnpackDword ();
m_bId64 = UnpackDword ();
- if ( m_bId64 && m_pShare->m_eTableFieldType[0] != MYSQL_TYPE_LONGLONG )
+ if ( m_bId64 && m_pShare->m_eTableFieldType[0]!=MYSQL_TYPE_LONGLONG )
{
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: 1st column must be bigint to accept 64-bit DOCIDs" );
SPH_RET(false);
@@ -2304,7 +2621,7 @@ bool ha_sphinx::UnpackSchema ()
if ( m_bUnpackError )
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: UnpackSchema() failed (unpack error)" );
- SPH_RET(!m_bUnpackError);
+ SPH_RET ( !m_bUnpackError );
}
@@ -2313,22 +2630,25 @@ bool ha_sphinx::UnpackStats ( CSphSEStats * pStats )
assert ( pStats );
char * pCurSave = m_pCur;
- for ( uint i=0; i<m_iMatchesTotal && m_pCur<m_pResponseEnd-sizeof(uint32); i++ )
+ for ( uint i=0; i<m_iMatchesTotal && m_pCur<m_pResponseEnd-sizeof(uint32); i++ ) // NOLINT
{
m_pCur += m_bId64 ? 12 : 8; // skip id+weight
- for ( uint32 i=0; i<m_iAttrs && m_pCur<m_pResponseEnd-sizeof(uint32); i++ )
+ for ( uint32 i=0; i<m_iAttrs && m_pCur<m_pResponseEnd-sizeof(uint32); i++ ) // NOLINT
{
- if ( m_dAttrs[i].m_uType & SPH_ATTR_MULTI )
+ if ( m_dAttrs[i].m_uType==SPH_ATTR_UINT32SET || m_dAttrs[i].m_uType==SPH_ATTR_UINT64SET )
{
// skip MVA list
uint32 uCount = UnpackDword ();
m_pCur += uCount*4;
- }
- else // skip normal value
- m_pCur += m_dAttrs[i].m_uType == SPH_ATTR_BIGINT ? 8 : 4;
+ } else if ( m_dAttrs[i].m_uType==SPH_ATTR_STRING )
+ {
+ uint32 iLen = UnpackDword();
+ m_pCur += iLen;
+ } else // skip normal value
+ m_pCur += m_dAttrs[i].m_uType==SPH_ATTR_BIGINT ? 8 : 4;
}
}
-
+
pStats->m_iMatchesTotal = UnpackDword ();
pStats->m_iMatchesFound = UnpackDword ();
pStats->m_iQueryMsec = UnpackDword ();
@@ -2337,9 +2657,10 @@ bool ha_sphinx::UnpackStats ( CSphSEStats * pStats )
if ( m_bUnpackError )
return false;
- SafeDeleteArray ( pStats->m_dWords );
if ( pStats->m_iWords<0 || pStats->m_iWords>=SPHINXSE_MAX_KEYWORDSTATS )
return false;
+
+ SafeDeleteArray ( pStats->m_dWords );
pStats->m_dWords = new CSphSEWordStats [ pStats->m_iWords ];
if ( !pStats->m_dWords )
return false;
@@ -2373,25 +2694,45 @@ const COND * ha_sphinx::cond_push ( const COND * cond )
if ( condf->functype()!=Item_func::EQ_FUNC || condf->argument_count()!=2 )
break;
- Item ** args = condf->arguments();
- if ( args[0]->type()!=COND::FIELD_ITEM || args[1]->type()!=COND::STRING_ITEM )
- break;
-
- Item_field * pField = (Item_field *) args[0];
- if ( pField->field->field_index!=2 ) // FIXME! magic key index
- break;
-
// get my tls
CSphSEThreadData * pTls = GetTls ();
if ( !pTls )
break;
- // copy the query, and let know that we intercepted this condition
- Item_string * pString = (Item_string *) args[1];
- pTls->m_bQuery = true;
- strncpy ( pTls->m_sQuery, pString->str_value.c_ptr(), sizeof(pTls->m_sQuery) );
- pTls->m_sQuery[sizeof(pTls->m_sQuery)-1] = '\0';
- pTls->m_pQueryCharset = pString->str_value.charset();
+ Item ** args = condf->arguments();
+ if ( !m_pShare->m_bSphinxQL )
+ {
+ // on non-QL tables, intercept query=value condition for SELECT
+ if (!( args[0]->type()==COND::FIELD_ITEM && args[1]->type()==COND::STRING_ITEM ))
+ break;
+
+ Item_field * pField = (Item_field *) args[0];
+ if ( pField->field->field_index!=2 ) // FIXME! magic key index
+ break;
+
+ // copy the query, and let know that we intercepted this condition
+ Item_string * pString = (Item_string *) args[1];
+ pTls->m_bQuery = true;
+ strncpy ( pTls->m_sQuery, pString->str_value.c_ptr(), sizeof(pTls->m_sQuery) );
+ pTls->m_sQuery[sizeof(pTls->m_sQuery)-1] = '\0';
+ pTls->m_pQueryCharset = pString->str_value.charset();
+
+ } else
+ {
+ if (!( args[0]->type()==COND::FIELD_ITEM && args[1]->type()==COND::INT_ITEM ))
+ break;
+
+ // on QL tables, intercept id=value condition for DELETE
+ Item_field * pField = (Item_field *) args[0];
+ if ( pField->field->field_index!=0 ) // FIXME! magic key index
+ break;
+
+ Item_int * pVal = (Item_int *) args[1];
+ pTls->m_iCondId = pVal->val_int();
+ pTls->m_bCondId = true;
+ }
+
+ // we intercepted this condition
return NULL;
}
@@ -2404,9 +2745,8 @@ const COND * ha_sphinx::cond_push ( const COND * cond )
void ha_sphinx::cond_pop ()
{
CSphSEThreadData * pTls = GetTls ();
- if ( pTls && pTls->m_bQuery )
+ if ( pTls )
pTls->m_bQuery = false;
- return;
}
@@ -2415,7 +2755,11 @@ CSphSEThreadData * ha_sphinx::GetTls()
{
// where do we store that pointer in today's version?
CSphSEThreadData ** ppTls;
- ppTls = (CSphSEThreadData**) thd_ha_data ( ha_thd(), ht );
+#if MYSQL_VERSION_ID>50100
+ ppTls = (CSphSEThreadData**) thd_ha_data ( table->in_use, ht );
+#else
+ ppTls = (CSphSEThreadData**) &current_thd->ha_data[sphinx_hton.slot];
+#endif // >50100
// allocate if needed
if ( !*ppTls )
@@ -2443,6 +2787,38 @@ int ha_sphinx::index_read ( byte * buf, const byte * key, uint key_len, enum ha_
}
pTls->m_tStats.Reset ();
+ // sphinxql table, just return the key once
+ if ( m_pShare->m_bSphinxQL )
+ {
+ // over and out
+ if ( pTls->m_bCondDone )
+ SPH_RET ( HA_ERR_END_OF_FILE );
+
+ // return a value from pushdown, if any
+ if ( pTls->m_bCondId )
+ {
+ table->field[0]->store ( pTls->m_iCondId, 1 );
+ pTls->m_bCondDone = true;
+ SPH_RET(0);
+ }
+
+ // return a value from key
+ longlong iRef = 0;
+ if ( key_len==4 )
+ iRef = uint4korr ( key );
+ else if ( key_len==8 )
+ iRef = uint8korr ( key );
+ else
+ {
+ my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: unexpected key length" );
+ SPH_RET ( HA_ERR_END_OF_FILE );
+ }
+
+ table->field[0]->store ( iRef, 1 );
+ pTls->m_bCondDone = true;
+ SPH_RET(0);
+ }
+
// parse query
if ( pTls->m_bQuery )
{
@@ -2465,7 +2841,7 @@ int ha_sphinx::index_read ( byte * buf, const byte * key, uint key_len, enum ha_
}
// do connect
- int iSocket = ConnectToSearchd ( q.m_sHost, q.m_iPort );
+ int iSocket = ConnectAPI ( q.m_sHost, q.m_iPort );
if ( iSocket<0 )
SPH_RET ( HA_ERR_END_OF_FILE );
@@ -2603,7 +2979,7 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
if ( m_iCurrentPos>=m_iMatchesTotal )
{
SafeDeleteArray ( m_pResponse );
- SPH_RET ( HA_ERR_END_OF_FILE );
+ SPH_RET ( HA_ERR_END_OF_FILE );
}
#if MYSQL_VERSION_ID>50100
@@ -2623,16 +2999,21 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
for ( uint32 i=0; i<m_iAttrs; i++ )
{
- longlong iValue64= 0;
+ longlong iValue64 = 0;
uint32 uValue = UnpackDword ();
- if ( m_dAttrs[i].m_uType == SPH_ATTR_BIGINT )
+ if ( m_dAttrs[i].m_uType==SPH_ATTR_BIGINT )
iValue64 = ( (longlong)uValue<<32 ) | UnpackDword();
if ( m_dAttrs[i].m_iField<0 )
{
- // skip MVA
- if ( m_dAttrs[i].m_uType & SPH_ATTR_MULTI )
+ // skip MVA or String
+ if ( m_dAttrs[i].m_uType==SPH_ATTR_UINT32SET || m_dAttrs[i].m_uType==SPH_ATTR_UINT64SET )
+ {
for ( ; uValue>0 && !m_bUnpackError; uValue-- )
UnpackDword();
+ } else if ( m_dAttrs[i].m_uType==SPH_ATTR_STRING && CheckResponcePtr ( uValue ) )
+ {
+ m_pCur += uValue;
+ }
continue;
}
@@ -2660,7 +3041,18 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
af->store ( iValue64, 0 );
break;
- case ( SPH_ATTR_MULTI | SPH_ATTR_INTEGER ):
+ case SPH_ATTR_STRING:
+ if ( !uValue )
+ af->store ( "", 0, &my_charset_bin );
+ else if ( CheckResponcePtr ( uValue ) )
+ {
+ af->store ( m_pCur, uValue, &my_charset_bin );
+ m_pCur += uValue;
+ }
+ break;
+
+ case SPH_ATTR_UINT64SET:
+ case SPH_ATTR_UINT32SET :
if ( uValue<=0 )
{
// shortcut, empty MVA set
@@ -2672,15 +3064,32 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
char sBuf[1024]; // FIXME! magic size
char * pCur = sBuf;
- for ( ; uValue>0 && !m_bUnpackError; uValue-- )
+ if ( m_dAttrs[i].m_uType==SPH_ATTR_UINT32SET )
+ {
+ for ( ; uValue>0 && !m_bUnpackError; uValue-- )
+ {
+ uint32 uEntry = UnpackDword ();
+ if ( pCur < sBuf+sizeof(sBuf)-16 ) // 10 chars per 32bit value plus some safety bytes
+ {
+ snprintf ( pCur, sBuf+sizeof(sBuf)-pCur, "%u", uEntry );
+ while ( *pCur ) pCur++;
+ if ( uValue>1 )
+ *pCur++ = ','; // non-trailing commas
+ }
+ }
+ } else
{
- uint32 uEntry = UnpackDword ();
- if ( pCur < sBuf+sizeof(sBuf)-16 ) // 10 chars per 32bit value plus some safety bytes
+ for ( ; uValue>0 && !m_bUnpackError; uValue-=2 )
{
- sprintf ( pCur, "%u", uEntry );
- while ( *pCur ) pCur++;
- if ( uValue>1 )
- *pCur++ = ','; // non-trailing commas
+ uint32 uEntryLo = UnpackDword ();
+ uint32 uEntryHi = UnpackDword();
+ if ( pCur < sBuf+sizeof(sBuf)-24 ) // 20 chars per 64bit value plus some safety bytes
+ {
+ snprintf ( pCur, sBuf+sizeof(sBuf)-pCur, "%u%u", uEntryHi, uEntryLo );
+ while ( *pCur ) pCur++;
+ if ( uValue>2 )
+ *pCur++ = ','; // non-trailing commas
+ }
}
}
@@ -2691,7 +3100,7 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
default:
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: unhandled attr type" );
SafeDeleteArray ( m_pResponse );
- SPH_RET ( HA_ERR_END_OF_FILE );
+ SPH_RET ( HA_ERR_END_OF_FILE );
}
}
@@ -2699,7 +3108,7 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
{
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: response unpacker failed" );
SafeDeleteArray ( m_pResponse );
- SPH_RET ( HA_ERR_END_OF_FILE );
+ SPH_RET ( HA_ERR_END_OF_FILE );
}
// zero out unmapped fields
@@ -2720,7 +3129,7 @@ int ha_sphinx::get_rec ( byte * buf, const byte *, uint )
m_iCurrentPos++;
#if MYSQL_VERSION_ID > 50100
- dbug_tmp_restore_column_map(table->write_set, org_bitmap);
+ dbug_tmp_restore_column_map ( table->write_set, org_bitmap );
#endif
SPH_RET(0);
@@ -2860,7 +3269,7 @@ THR_LOCK_DATA ** ha_sphinx::store_lock ( THD *, THR_LOCK_DATA ** to,
SPH_ENTER_METHOD();
if ( lock_type!=TL_IGNORE && m_tLock.type==TL_UNLOCK )
- m_tLock.type=lock_type;
+ m_tLock.type = lock_type;
*to++ = &m_tLock;
SPH_RET(to);
@@ -2900,12 +3309,6 @@ ha_rows ha_sphinx::records_in_range ( uint, key_range *, key_range * )
}
-static inline bool IsIntegerFieldType ( enum_field_types eType )
-{
- return eType==MYSQL_TYPE_LONG || eType==MYSQL_TYPE_LONGLONG;
-}
-
-
// create() is called to create a database. The variable name will have the name
// of the table. When create() is called you do not need to worry about opening
// the table. Also, the FRM file will have already been created so adjusting
@@ -2919,10 +3322,12 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * )
SPH_ENTER_METHOD();
char sError[256];
- if ( !ParseUrl ( NULL, table, true ) )
+ CSphSEShare tInfo;
+ if ( !ParseUrl ( &tInfo, table, true ) )
SPH_RET(-1);
- for ( ;; )
+ // check SphinxAPI table
+ for ( ; !tInfo.m_bSphinxQL; )
{
// check system fields (count and types)
if ( table->s->fields<SPHINXSE_SYSTEM_COLUMNS )
@@ -2932,7 +3337,7 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * )
break;
}
- if ( !IsIntegerFieldType ( table->field[0]->type() ) || !((Field_num *)table->field[0])->unsigned_flag )
+ if ( !IsIDField ( table->field[0] ) )
{
my_snprintf ( sError, sizeof(sError), "%s: 1st column (docid) MUST be unsigned integer or bigint", name );
break;
@@ -2983,6 +3388,54 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * )
sError[0] = '\0';
break;
}
+
+ // check SphinxQL table
+ for ( ; tInfo.m_bSphinxQL; )
+ {
+ sError[0] = '\0';
+
+ // check that 1st column is id, is of int type, and has an index
+ if ( strcmp ( table->field[0]->field_name, "id" ) )
+ {
+ my_snprintf ( sError, sizeof(sError), "%s: 1st column must be called 'id'", name );
+ break;
+ }
+
+ if ( !IsIDField ( table->field[0] ) )
+ {
+ my_snprintf ( sError, sizeof(sError), "%s: 'id' column must be INT UNSIGNED or BIGINT", name );
+ break;
+ }
+
+ // check index
+ if (
+ table->s->keys!=1 ||
+ table->key_info[0].key_parts!=1 ||
+ strcasecmp ( table->key_info[0].key_part[0].field->field_name, "id" ) )
+ {
+ my_snprintf ( sError, sizeof(sError), "%s: 'id' column must be indexed", name );
+ break;
+ }
+
+ // check column types
+ for ( int i=1; i<(int)table->s->fields; i++ )
+ {
+ enum_field_types eType = table->field[i]->type();
+ if ( eType!=MYSQL_TYPE_TIMESTAMP && !IsIntegerFieldType(eType) && eType!=MYSQL_TYPE_VARCHAR && eType!=MYSQL_TYPE_FLOAT )
+ {
+ my_snprintf ( sError, sizeof(sError), "%s: column %d(%s) is of unsupported type (use int/bigint/timestamp/varchar/float)",
+ name, i+1, table->field[i]->field_name );
+ break;
+ }
+ }
+ if ( sError[0] )
+ break;
+
+ // all good
+ break;
+ }
+
+ // report and bail
if ( sError[0] )
{
my_error ( ER_CANT_CREATE_TABLE, MYF(0), sError, -1 );
@@ -2992,76 +3445,142 @@ int ha_sphinx::create ( const char * name, TABLE * table, HA_CREATE_INFO * )
SPH_RET(0);
}
-//// show functions
+// show functions
-#if MYSQL_VERSION_ID<50100
+#if MYSQL_VERSION_ID<50100
#define SHOW_VAR_FUNC_BUFF_SIZE 1024
#endif
-static int sphinx_showfunc ( THD * thd, SHOW_VAR * out, char * sBuffer )
-{
- CSphSEThreadData *pTls = (CSphSEThreadData *) *thd_ha_data ( thd, sphinx_hton_ptr );
- CSphSEStats * pStats = ( pTls && pTls->m_bStats ) ? &pTls->m_tStats : 0;
- SHOW_VAR *array = (SHOW_VAR*)thd_alloc(thd, sizeof(SHOW_VAR)*7);
- out->type = SHOW_ARRAY;
- out->value = (char*)array;
- if (pStats)
- {
- array[0].name = "total";
- array[0].type = SHOW_INT;
- array[0].value = (char *) &pStats->m_iMatchesTotal;
- array[1].name = "total_found";
- array[1].type = SHOW_INT;
- array[1].value = (char *) &pStats->m_iMatchesFound;
- array[2].name = "time";
- array[2].type = SHOW_INT;
- array[2].value = (char *) &pStats->m_iQueryMsec;
- array[3].name = "word_count";
- array[3].type = SHOW_INT;
- array[3].value = (char *) &pStats->m_iWords;
- array[4].name = "error";
- array[4].type = SHOW_CHAR;
- array[4].value = (char *) &pStats->m_sLastMessage;
- array[5].name = "words";
- array[5].type = SHOW_CHAR;
- array[5].value = sBuffer;
- sBuffer[0] = 0;
-
- if ( pStats->m_iWords )
- {
- uint uBuffLen = 0;
-
- // the following is partially based on code in sphinx_show_status()
- for ( int i=0; i<pStats->m_iWords; i++ )
- {
- CSphSEWordStats & tWord = pStats->m_dWords[i];
- uBuffLen = my_snprintf ( sBuffer, SHOW_VAR_FUNC_BUFF_SIZE, "%s%s:%d:%d ", sBuffer,
- tWord.m_sWord, tWord.m_iDocs, tWord.m_iHits );
- }
-
- if ( uBuffLen > 0 )
- {
- // trim last space
- sBuffer [ --uBuffLen ] = 0;
-
- if ( pTls->m_pQueryCharset )
- {
- // String::c_ptr() will nul-terminate the buffer.
- //
- // NOTE: It's not entirely clear whether this conversion is necessary at all.
-
- String sConvert;
- uint iErrors;
- sConvert.copy ( sBuffer, uBuffLen, pTls->m_pQueryCharset, system_charset_info, &iErrors );
- memcpy ( sBuffer, sConvert.c_ptr(), sConvert.length() + 1 );
- }
- }
- }
-
- array[6].name = 0; // terminate the array
- }
- else
- array[0].name = 0;
+CSphSEStats * sphinx_get_stats ( THD * thd, SHOW_VAR * out )
+{
+#if MYSQL_VERSION_ID>50100
+ if ( sphinx_hton_ptr )
+ {
+ CSphSEThreadData *pTls = (CSphSEThreadData *) *thd_ha_data ( thd, sphinx_hton_ptr );
+
+ if ( pTls && pTls->m_bStats )
+ return &pTls->m_tStats;
+ }
+#else
+ CSphSEThreadData *pTls = (CSphSEThreadData *) thd->ha_data[sphinx_hton.slot];
+ if ( pTls && pTls->m_bStats )
+ return &pTls->m_tStats;
+#endif
+
+ out->type = SHOW_CHAR;
+ out->value = (char*) "";
+ return 0;
+}
+
+int sphinx_showfunc_total ( THD * thd, SHOW_VAR * out, char * )
+{
+ CSphSEStats * pStats = sphinx_get_stats ( thd, out );
+ if ( pStats )
+ {
+ out->type = SHOW_INT;
+ out->value = (char *) &pStats->m_iMatchesTotal;
+ }
+ return 0;
+}
+
+int sphinx_showfunc_total_found ( THD * thd, SHOW_VAR * out, char * )
+{
+ CSphSEStats * pStats = sphinx_get_stats ( thd, out );
+ if ( pStats )
+ {
+ out->type = SHOW_INT;
+ out->value = (char *) &pStats->m_iMatchesFound;
+ }
+ return 0;
+}
+
+int sphinx_showfunc_time ( THD * thd, SHOW_VAR * out, char * )
+{
+ CSphSEStats * pStats = sphinx_get_stats ( thd, out );
+ if ( pStats )
+ {
+ out->type = SHOW_INT;
+ out->value = (char *) &pStats->m_iQueryMsec;
+ }
+ return 0;
+}
+
+int sphinx_showfunc_word_count ( THD * thd, SHOW_VAR * out, char * )
+{
+ CSphSEStats * pStats = sphinx_get_stats ( thd, out );
+ if ( pStats )
+ {
+ out->type = SHOW_INT;
+ out->value = (char *) &pStats->m_iWords;
+ }
+ return 0;
+}
+
+int sphinx_showfunc_words ( THD * thd, SHOW_VAR * out, char * sBuffer )
+{
+#if MYSQL_VERSION_ID>50100
+ if ( sphinx_hton_ptr )
+ {
+ CSphSEThreadData * pTls = (CSphSEThreadData *) *thd_ha_data ( thd, sphinx_hton_ptr );
+#else
+ {
+ CSphSEThreadData * pTls = (CSphSEThreadData *) thd->ha_data[sphinx_hton.slot];
+#endif
+ if ( pTls && pTls->m_bStats )
+ {
+ CSphSEStats * pStats = &pTls->m_tStats;
+ if ( pStats && pStats->m_iWords )
+ {
+ uint uBuffLen = 0;
+
+ out->type = SHOW_CHAR;
+ out->value = sBuffer;
+
+ // the following is partially based on code in sphinx_show_status()
+ sBuffer[0] = 0;
+ for ( int i=0; i<pStats->m_iWords; i++ )
+ {
+ CSphSEWordStats & tWord = pStats->m_dWords[i];
+ uBuffLen = my_snprintf ( sBuffer, SHOW_VAR_FUNC_BUFF_SIZE, "%s%s:%d:%d ", sBuffer,
+ tWord.m_sWord, tWord.m_iDocs, tWord.m_iHits );
+ }
+
+ if ( uBuffLen > 0 )
+ {
+ // trim last space
+ sBuffer [ --uBuffLen ] = 0;
+
+ if ( pTls->m_pQueryCharset )
+ {
+ // String::c_ptr() will nul-terminate the buffer.
+ //
+ // NOTE: It's not entirely clear whether this conversion is necessary at all.
+
+ String sConvert;
+ uint iErrors;
+ sConvert.copy ( sBuffer, uBuffLen, pTls->m_pQueryCharset, system_charset_info, &iErrors );
+ memcpy ( sBuffer, sConvert.c_ptr(), sConvert.length() + 1 );
+ }
+ }
+
+ return 0;
+ }
+ }
+ }
+
+ out->type = SHOW_CHAR;
+ out->value = (char*) "";
+ return 0;
+}
+
+int sphinx_showfunc_error ( THD * thd, SHOW_VAR * out, char * )
+{
+ CSphSEStats * pStats = sphinx_get_stats ( thd, out );
+ if ( pStats && pStats->m_bLastError )
+ {
+ out->type = SHOW_CHAR;
+ out->value = pStats->m_sLastMessage;
+ }
return 0;
}
@@ -3073,10 +3592,16 @@ struct st_mysql_storage_engine sphinx_storage_engine =
struct st_mysql_show_var sphinx_status_vars[] =
{
- {"sphinx", (char *)sphinx_showfunc, SHOW_FUNC},
+ {"sphinx_total", (char *)sphinx_showfunc_total, SHOW_FUNC},
+ {"sphinx_total_found", (char *)sphinx_showfunc_total_found, SHOW_FUNC},
+ {"sphinx_time", (char *)sphinx_showfunc_time, SHOW_FUNC},
+ {"sphinx_word_count", (char *)sphinx_showfunc_word_count, SHOW_FUNC},
+ {"sphinx_words", (char *)sphinx_showfunc_words, SHOW_FUNC},
+ {"sphinx_error", (char *)sphinx_showfunc_error, SHOW_FUNC},
{0, 0, (enum_mysql_show_type)0}
};
+
maria_declare_plugin(sphinx)
{
MYSQL_STORAGE_ENGINE_PLUGIN,
@@ -3098,5 +3623,5 @@ maria_declare_plugin_end;
#endif // >50100
//
-// $Id: ha_sphinx.cc 2058 2009-11-07 04:01:57Z shodan $
+// $Id: ha_sphinx.cc 3133 2012-03-01 13:47:52Z shodan $
//
diff --git a/storage/sphinx/ha_sphinx.h b/storage/sphinx/ha_sphinx.h
index 4435eb4724e..f2aa726791b 100644
--- a/storage/sphinx/ha_sphinx.h
+++ b/storage/sphinx/ha_sphinx.h
@@ -1,5 +1,5 @@
//
-// $Id: ha_sphinx.h 1428 2008-09-05 18:06:30Z xale $
+// $Id: ha_sphinx.h 2921 2011-08-21 21:35:02Z tomat $
//
#ifdef USE_PRAGMA_INTERFACE
@@ -7,8 +7,10 @@
#endif
-#if MYSQL_VERSION_ID>50100
+#if MYSQL_VERSION_ID>=50515
#define TABLE_ARG TABLE_SHARE
+#elif MYSQL_VERSION_ID>50100
+#define TABLE_ARG st_table_share
#else
#define TABLE_ARG st_table
#endif
@@ -18,7 +20,6 @@
typedef uchar byte;
#endif
-#include "handler.h"
/// forward decls
class THD;
@@ -48,18 +49,19 @@ protected:
public:
#if MYSQL_VERSION_ID<50100
- ha_sphinx ( TABLE_ARG * table_arg );
+ ha_sphinx ( TABLE_ARG * table_arg ); // NOLINT
#else
ha_sphinx ( handlerton * hton, TABLE_ARG * table_arg );
#endif
- ~ha_sphinx () {}
+ ~ha_sphinx ();
const char * table_type () const { return "SPHINX"; } ///< SE name for display purposes
const char * index_type ( uint ) { return "HASH"; } ///< index type name for display purposes
const char ** bas_ext () const; ///< my file extensions
#if MYSQL_VERSION_ID>50100
- ulonglong table_flags () const { return HA_CAN_INDEX_BLOBS; } ///< bitmap of implemented flags (see handler.h for more info)
+ ulonglong table_flags () const { return HA_CAN_INDEX_BLOBS |
+ HA_MUST_USE_TABLE_CONDITION_PUSHDOWN; } ///< bitmap of implemented flags (see handler.h for more info)
#else
ulong table_flags () const { return HA_CAN_INDEX_BLOBS; } ///< bitmap of implemented flags (see handler.h for more info)
#endif
@@ -77,21 +79,22 @@ public:
virtual double scan_time () { return (double)( records+deleted )/20.0 + 10; } ///< called in test_quick_select to determine if indexes should be used
#endif
- virtual double read_time(uint index, uint ranges, ha_rows rows)
- { return (double)rows/20.0 + 1; } ///< index read time estimate
+ virtual double read_time(uint index, uint ranges, ha_rows rows)
+ { return ranges + (double)rows/20.0 + 1; } ///< index read time estimate
public:
int open ( const char * name, int mode, uint test_if_locked );
int close ();
- int write_row ( uchar * buf );
- int update_row ( const uchar * old_data, uchar * new_data );
- int delete_row ( const uchar * buf );
+ int write_row ( byte * buf );
+ int update_row ( const byte * old_data, byte * new_data );
+ int delete_row ( const byte * buf );
+ int extra ( enum ha_extra_function op );
int index_init ( uint keynr, bool sorted ); // 5.1.x
int index_init ( uint keynr ) { return index_init ( keynr, false ); } // 5.0.x
- int index_end ();
+ int index_end ();
int index_read ( byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag );
int index_read_idx ( byte * buf, uint idx, const byte * key, uint key_len, enum ha_rkey_function find_flag );
int index_next ( byte * buf );
@@ -123,7 +126,7 @@ public:
int rename_table ( const char * from, const char * to );
int create ( const char * name, TABLE * form, HA_CREATE_INFO * create_info );
- THR_LOCK_DATA **store_lock ( THD * thd, THR_LOCK_DATA ** to, enum thr_lock_type lock_type );
+ THR_LOCK_DATA ** store_lock ( THD * thd, THR_LOCK_DATA ** to, enum thr_lock_type lock_type );
public:
virtual const COND * cond_push ( const COND *cond );
@@ -140,12 +143,15 @@ private:
int * m_dUnboundFields;
private:
- int ConnectToSearchd ( const char * sQueryHost, int iQueryPort );
+ int Connect ( const char * sQueryHost, ushort uPort );
+ int ConnectAPI ( const char * sQueryHost, int iQueryPort );
+ int HandleMysqlError ( struct st_mysql * pConn, int iErrCode );
uint32 UnpackDword ();
char * UnpackString ();
bool UnpackSchema ();
bool UnpackStats ( CSphSEStats * pStats );
+ bool CheckResponcePtr ( int iLen );
CSphSEThreadData * GetTls ();
};
@@ -155,6 +161,12 @@ private:
bool sphinx_show_status ( THD * thd );
#endif
+int sphinx_showfunc_total_found ( THD *, SHOW_VAR *, char * );
+int sphinx_showfunc_total ( THD *, SHOW_VAR *, char * );
+int sphinx_showfunc_time ( THD *, SHOW_VAR *, char * );
+int sphinx_showfunc_word_count ( THD *, SHOW_VAR *, char * );
+int sphinx_showfunc_words ( THD *, SHOW_VAR *, char * );
+
//
-// $Id: ha_sphinx.h 1428 2008-09-05 18:06:30Z xale $
+// $Id: ha_sphinx.h 2921 2011-08-21 21:35:02Z tomat $
//
diff --git a/storage/sphinx/snippets_udf.cc b/storage/sphinx/snippets_udf.cc
index c25873bce28..85fb66ab793 100644
--- a/storage/sphinx/snippets_udf.cc
+++ b/storage/sphinx/snippets_udf.cc
@@ -1,9 +1,11 @@
//
-// $Id: snippets_udf.cc 2058 2009-11-07 04:01:57Z shodan $
+// $Id: snippets_udf.cc 3087 2012-01-30 23:07:35Z shodan $
//
//
-// Copyright (c) 2001-2008, Andrew Aksyonoff. All rights reserved.
+// Copyright (c) 2001-2012, Andrew Aksyonoff
+// Copyright (c) 2008-2012, Sphinx Technologies Inc
+// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
@@ -11,29 +13,25 @@
// did not, you can find it at http://www.gnu.org/
//
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <sys/un.h>
+#include <netdb.h>
+
#include <mysql_version.h>
#if MYSQL_VERSION_ID>50100
+#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "../mysql_priv.h"
#endif
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include <sys/un.h>
-#include <netdb.h>
-
#include <mysys_err.h>
#include <my_sys.h>
-#include <mysqld_error.h>
-
-#include <my_net.h>
-#include <mysql_com.h>
-
#if MYSQL_VERSION_ID>=50120
typedef uchar byte;
#endif
@@ -120,7 +118,7 @@ static bool sphSend ( int iFd, const char * pBuffer, int iSize, bool bReportErro
assert ( iSize > 0 );
const int iResult = send ( iFd, pBuffer, iSize, 0 );
- if ( iResult != iSize )
+ if ( iResult!=iSize )
{
if ( bReportErrors ) sphShowErrno("send");
return false;
@@ -132,7 +130,7 @@ static bool sphRecv ( int iFd, char * pBuffer, int iSize, bool bReportErrors = f
{
assert ( pBuffer );
assert ( iSize > 0 );
-
+
while ( iSize )
{
const int iResult = recv ( iFd, pBuffer, iSize, 0 );
@@ -140,14 +138,12 @@ static bool sphRecv ( int iFd, char * pBuffer, int iSize, bool bReportErrors = f
{
iSize -= iResult;
pBuffer += iSize;
- }
- else if ( iResult == 0 )
+ } else if ( iResult==0 )
{
if ( bReportErrors )
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), "recv() failed: disconnected" );
return false;
- }
- else
+ } else
{
if ( bReportErrors ) sphShowErrno("recv");
return false;
@@ -160,11 +156,9 @@ enum
{
SPHINX_SEARCHD_PROTO = 1,
- SEARCHD_COMMAND_SEARCH = 0,
SEARCHD_COMMAND_EXCERPT = 1,
- VER_COMMAND_SEARCH = 0x116,
- VER_COMMAND_EXCERPT = 0x100,
+ VER_COMMAND_EXCERPT = 0x103,
};
/// known answers
@@ -191,7 +185,7 @@ private:
char * m_pCurrent;
public:
- CSphBuffer ( const int iSize )
+ explicit CSphBuffer ( const int iSize )
: m_bOverrun ( false )
, m_iSize ( iSize )
, m_iLeft ( iSize )
@@ -203,22 +197,22 @@ public:
~CSphBuffer ()
{
- SafeDelete ( m_pBuffer );
+ SafeDeleteArray ( m_pBuffer );
}
const char * Ptr() const { return m_pBuffer; }
bool Finalize()
{
- return !( m_bOverrun || m_iLeft != 0 || m_pCurrent - m_pBuffer != m_iSize );
+ return !( m_bOverrun || m_iLeft!=0 || ( m_pCurrent - m_pBuffer )!=m_iSize );
}
-
+
void SendBytes ( const void * pBytes, int iBytes );
-
- void SendWord ( short int v ) { v = ntohs(v); SendBytes ( &v, sizeof(v) ); }
+
+ void SendWord ( short int v ) { v = ntohs(v); SendBytes ( &v, sizeof(v) ); } // NOLINT
void SendInt ( int v ) { v = ntohl(v); SendBytes ( &v, sizeof(v) ); }
void SendDword ( DWORD v ) { v = ntohl(v) ;SendBytes ( &v, sizeof(v) ); }
- void SendUint64 ( ulonglong v ) { SendDword ( uint(v>>32) ); SendDword ( uint(v&0xFFFFFFFFUL) ); }
+ void SendUint64 ( ulonglong v ) { SendDword ( uint ( v>>32 ) ); SendDword ( uint ( v&0xFFFFFFFFUL ) ); }
void SendString ( const char * v ) { SendString ( v, strlen(v) ); }
void SendString ( const char * v, int iLen ) { SendDword(iLen); SendBytes ( v, iLen ); }
void SendFloat ( float v ) { SendDword ( sphF2DW(v) ); }
@@ -242,28 +236,28 @@ struct CSphUrl
{
char * m_sBuffer;
char * m_sFormatted;
-
+
char * m_sScheme;
char * m_sHost;
char * m_sIndex;
-
+
int m_iPort;
-
+
CSphUrl()
: m_sBuffer ( NULL )
, m_sFormatted ( NULL )
- , m_sScheme ( (char*) SPHINXSE_DEFAULT_SCHEME )
- , m_sHost ( (char*) SPHINXSE_DEFAULT_HOST )
- , m_sIndex ( (char*) SPHINXSE_DEFAULT_INDEX )
+ , m_sScheme ( SPHINXSE_DEFAULT_SCHEME )
+ , m_sHost ( SPHINXSE_DEFAULT_HOST )
+ , m_sIndex ( SPHINXSE_DEFAULT_INDEX )
, m_iPort ( SPHINXSE_DEFAULT_PORT )
{}
-
+
~CSphUrl()
{
SafeDeleteArray ( m_sFormatted );
SafeDeleteArray ( m_sBuffer );
}
-
+
bool Parse ( const char * sUrl, int iLen );
int Connect();
const char * Format();
@@ -295,32 +289,32 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen )
while ( iLen )
{
bOk = false;
-
+
m_sBuffer = sphDup ( sUrl, iLen );
m_sScheme = m_sBuffer;
-
+
m_sHost = strstr ( m_sBuffer, "://" );
if ( !m_sHost )
break;
m_sHost[0] = '\0';
m_sHost += 2;
-
+
if ( !strcmp ( m_sScheme, "unix" ) )
{
// unix-domain socket
m_iPort = 0;
if (!( m_sIndex = strrchr ( m_sHost, ':' ) ))
- m_sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
+ m_sIndex = SPHINXSE_DEFAULT_INDEX;
else
{
*m_sIndex++ = '\0';
if ( !*m_sIndex )
- m_sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
+ m_sIndex = SPHINXSE_DEFAULT_INDEX;
}
bOk = true;
break;
}
- if( strcmp ( m_sScheme, "sphinx" ) != 0 && strcmp ( m_sScheme, "inet" ) != 0 )
+ if ( strcmp ( m_sScheme, "sphinx" )!=0 && strcmp ( m_sScheme, "inet" )!=0 )
break;
// inet
@@ -333,10 +327,10 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen )
{
m_sIndex = strchr ( sPort, '/' );
if ( m_sIndex )
- *m_sIndex++ = '\0';
+ *m_sIndex++ = '\0';
else
- m_sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
-
+ m_sIndex = SPHINXSE_DEFAULT_INDEX;
+
m_iPort = atoi(sPort);
if ( !m_iPort )
m_iPort = SPHINXSE_DEFAULT_PORT;
@@ -347,13 +341,13 @@ bool CSphUrl::Parse ( const char * sUrl, int iLen )
if ( m_sIndex )
*m_sIndex++ = '\0';
else
- m_sIndex = (char*) SPHINXSE_DEFAULT_INDEX;
+ m_sIndex = SPHINXSE_DEFAULT_INDEX;
}
bOk = true;
break;
}
-
+
return bOk;
}
@@ -378,35 +372,33 @@ int CSphUrl::Connect()
memset ( &sin, 0, sizeof(sin) );
sin.sin_family = AF_INET;
- sin.sin_port = htons(m_iPort);
-
+ sin.sin_port = htons ( m_iPort );
+
// resolve address
- if ( (int)( ip_addr=inet_addr(m_sHost) ) != (int)INADDR_NONE )
+ if ( (int)( ip_addr = inet_addr ( m_sHost ) )!=(int)INADDR_NONE )
memcpy ( &sin.sin_addr, &ip_addr, sizeof(ip_addr) );
else
{
int tmp_errno;
struct hostent tmp_hostent, *hp;
char buff2 [ GETHOSTBYNAME_BUFF_SIZE ];
-
- hp = my_gethostbyname_r ( m_sHost, &tmp_hostent,
- buff2, sizeof(buff2), &tmp_errno );
+
+ hp = my_gethostbyname_r ( m_sHost, &tmp_hostent, buff2, sizeof(buff2), &tmp_errno );
if ( !hp )
- {
+ {
my_gethostbyname_r_free();
-
+
char sError[256];
snprintf ( sError, sizeof(sError), "failed to resolve searchd host (name=%s)", m_sHost );
-
+
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
return -1;
}
-
+
memcpy ( &sin.sin_addr, hp->h_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->h_length ) );
my_gethostbyname_r_free();
}
- }
- else
+ } else
{
#ifndef __WIN__
iDomain = AF_UNIX;
@@ -426,17 +418,17 @@ int CSphUrl::Connect()
uint uServerVersion;
uint uClientVersion = htonl ( SPHINX_SEARCHD_PROTO );
int iSocket = -1;
- const char * pError = NULL;
+ char * pError = NULL;
do
{
iSocket = socket ( iDomain, SOCK_STREAM, 0 );
- if ( iSocket == -1 )
+ if ( iSocket==-1 )
{
pError = "Failed to create client socket";
break;
}
-
- if ( connect ( iSocket, pSockaddr, iSockaddrSize ) == -1)
+
+ if ( connect ( iSocket, pSockaddr, iSockaddrSize )==-1 )
{
pError = "Failed to connect to searchd";
break;
@@ -447,7 +439,7 @@ int CSphUrl::Connect()
pError = "Failed to receive searchd version";
break;
}
-
+
if ( !sphSend ( iSocket, (char *)&uClientVersion, sizeof(uClientVersion) ) )
{
pError = "Failed to send client version";
@@ -464,9 +456,9 @@ int CSphUrl::Connect()
snprintf ( sError, sizeof(sError), "%s [%d] %s", Format(), errno, strerror(errno) );
my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError );
- if ( iSocket != -1 )
+ if ( iSocket!=-1 )
close ( iSocket );
-
+
return -1;
}
@@ -483,7 +475,7 @@ struct CSphResponse
, m_pBody ( NULL )
{}
- CSphResponse ( DWORD uSize )
+ explicit CSphResponse ( DWORD uSize )
: m_pBody ( NULL )
{
m_pBuffer = new char[uSize];
@@ -493,7 +485,7 @@ struct CSphResponse
{
SafeDeleteArray ( m_pBuffer );
}
-
+
static CSphResponse * Read ( int iSocket, int iClientVersion );
};
@@ -504,14 +496,14 @@ CSphResponse::Read ( int iSocket, int iClientVersion )
if ( !sphRecv ( iSocket, sHeader, sizeof(sHeader) ) )
return NULL;
- int iStatus = ntohs ( sphUnalignedRead ( *(short int *) &sHeader[0] ) );
- int iVersion = ntohs ( sphUnalignedRead ( *(short int *) &sHeader[2] ) );
- DWORD uLength = ntohl ( sphUnalignedRead ( *(DWORD *) &sHeader[4] ) );
+ int iStatus = ntohs ( sphUnalignedRead ( *(short int *) &sHeader[0] ) );
+ int iVersion = ntohs ( sphUnalignedRead ( *(short int *) &sHeader[2] ) );
+ DWORD uLength = ntohl ( sphUnalignedRead ( *(DWORD *) &sHeader[4] ) );
- if ( iVersion < iClientVersion ) // fixme: warn
- {}
+ if ( iVersion<iClientVersion )
+ return NULL;
- if ( uLength <= SPHINXSE_MAX_ALLOC )
+ if ( uLength<=SPHINXSE_MAX_ALLOC )
{
CSphResponse * pResponse = new CSphResponse ( uLength );
if ( !sphRecv ( iSocket, pResponse->m_pBuffer, uLength ) )
@@ -521,16 +513,17 @@ CSphResponse::Read ( int iSocket, int iClientVersion )
}
pResponse->m_pBody = pResponse->m_pBuffer;
- if ( iStatus != SEARCHD_OK )
+ if ( iStatus!=SEARCHD_OK )
{
DWORD uSize = ntohl ( *(DWORD *)pResponse->m_pBuffer );
- if ( iStatus == SEARCHD_WARNING )
+ if ( iStatus==SEARCHD_WARNING )
+ {
pResponse->m_pBody += uSize; // fixme: report the warning somehow
- else
+ } else
{
char * sMessage = sphDup ( pResponse->m_pBuffer + sizeof(DWORD), uSize );
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), sMessage );
- SafeDelete ( sMessage );
+ SafeDeleteArray ( sMessage );
SafeDelete ( pResponse );
return NULL;
}
@@ -560,8 +553,13 @@ struct CSphSnippets
int m_iBeforeMatch;
int m_iAfterMatch;
int m_iChunkSeparator;
+ int m_iStripMode;
+ int m_iPassageBoundary;
int m_iLimit;
+ int m_iLimitWords;
+ int m_iLimitPassages;
int m_iAround;
+ int m_iPassageId;
int m_iFlags;
CSphSnippets()
@@ -569,9 +567,14 @@ struct CSphSnippets
, m_iBeforeMatch(0)
, m_iAfterMatch(0)
, m_iChunkSeparator(0)
- // defaults
+ , m_iStripMode(0)
+ , m_iPassageBoundary(0)
+ // defaults
, m_iLimit(256)
+ , m_iLimitWords(0)
+ , m_iLimitPassages(0)
, m_iAround(5)
+ , m_iPassageId(1)
, m_iFlags(1)
{
}
@@ -582,24 +585,24 @@ struct CSphSnippets
}
};
-#define KEYWORD(NAME) else if ( strncmp ( NAME, pArgs->attributes[i], pArgs->attribute_lengths[i] ) == 0 )
+#define KEYWORD(NAME) else if ( strncmp ( NAME, pArgs->attributes[i], pArgs->attribute_lengths[i] )==0 )
#define CHECK_TYPE(TYPE) \
- if ( pArgs->arg_type[i] != TYPE ) \
+ if ( pArgs->arg_type[i]!=TYPE ) \
{ \
snprintf ( sMessage, MAX_MESSAGE_LENGTH, \
- "%.*s argument must be a string", \
- (int)pArgs->attribute_lengths[i], \
- pArgs->attributes[i] ); \
+ "%.*s argument must be a string", \
+ (int)pArgs->attribute_lengths[i], \
+ pArgs->attributes[i] ); \
bFail = true; \
break; \
} \
- if ( TYPE == STRING_RESULT && !pArgs->args[i] ) \
+ if ( TYPE==STRING_RESULT && !pArgs->args[i] ) \
{ \
snprintf ( sMessage, MAX_MESSAGE_LENGTH, \
- "%.*s argument must be constant (and not NULL)", \
- (int)pArgs->attribute_lengths[i], \
- pArgs->attributes[i] ); \
+ "%.*s argument must be constant (and not NULL)", \
+ (int)pArgs->attribute_lengths[i], \
+ pArgs->attributes[i] ); \
bFail = true; \
break; \
}
@@ -621,7 +624,7 @@ my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessag
{
if ( i < 3 )
{
- if ( pArgs->arg_type[i] != STRING_RESULT )
+ if ( pArgs->arg_type[i]!=STRING_RESULT )
{
strncpy ( sMessage, "first three arguments must be of string type", MAX_MESSAGE_LENGTH );
bFail = true;
@@ -641,21 +644,33 @@ my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessag
KEYWORD("before_match") { STRING; pOpts->m_iBeforeMatch = i; }
KEYWORD("after_match") { STRING; pOpts->m_iAfterMatch = i; }
KEYWORD("chunk_separator") { STRING; pOpts->m_iChunkSeparator = i; }
+ KEYWORD("html_strip_mode") { STRING; pOpts->m_iStripMode = i; }
+ KEYWORD("passage_boundary") { STRING; pOpts->m_iPassageBoundary = i; }
+
KEYWORD("limit") { INT; pOpts->m_iLimit = iValue; }
+ KEYWORD("limit_words") { INT; pOpts->m_iLimitWords = iValue; }
+ KEYWORD("limit_passages") { INT; pOpts->m_iLimitPassages = iValue; }
KEYWORD("around") { INT; pOpts->m_iAround = iValue; }
+ KEYWORD("start_passage_id") { INT; pOpts->m_iPassageId = iValue; }
+
KEYWORD("exact_phrase") { INT; if ( iValue ) pOpts->m_iFlags |= 2; }
KEYWORD("single_passage") { INT; if ( iValue ) pOpts->m_iFlags |= 4; }
KEYWORD("use_boundaries") { INT; if ( iValue ) pOpts->m_iFlags |= 8; }
KEYWORD("weight_order") { INT; if ( iValue ) pOpts->m_iFlags |= 16; }
+ KEYWORD("query_mode") { INT; if ( iValue ) pOpts->m_iFlags |= 32; }
+ KEYWORD("force_all_words") { INT; if ( iValue ) pOpts->m_iFlags |= 64; }
+ KEYWORD("load_files") { INT; if ( iValue ) pOpts->m_iFlags |= 128; }
+ KEYWORD("allow_empty") { INT; if ( iValue ) pOpts->m_iFlags |= 256; }
+ KEYWORD("emit_zones") { INT; if ( iValue ) pOpts->m_iFlags |= 512; }
else
{
snprintf ( sMessage, MAX_MESSAGE_LENGTH, "unrecognized argument: %.*s",
- (int)pArgs->attribute_lengths[i], pArgs->attributes[i] );
+ (int)pArgs->attribute_lengths[i], pArgs->attributes[i] );
bFail = true;
break;
}
}
-
+
if ( bFail )
{
SafeDelete ( pOpts );
@@ -691,15 +706,14 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi
return sResult;
}
- const int iSize =
- 8 + // header
- 8 +
- 4 + pArgs->lengths[1] + // index
- 4 + pArgs->lengths[2] + // words
- 4 + ARG_LEN ( pOpts->m_iBeforeMatch, 3 ) +
- 4 + ARG_LEN ( pOpts->m_iAfterMatch, 4 ) +
- 4 + ARG_LEN ( pOpts->m_iChunkSeparator, 5 ) +
- 12 +
+ const int iSize = 68 +
+ pArgs->lengths[1] + // index
+ pArgs->lengths[2] + // words
+ ARG_LEN ( pOpts->m_iBeforeMatch, 3 ) +
+ ARG_LEN ( pOpts->m_iAfterMatch, 4 ) +
+ ARG_LEN ( pOpts->m_iChunkSeparator, 5 ) +
+ ARG_LEN ( pOpts->m_iStripMode, 5 ) +
+ ARG_LEN ( pOpts->m_iPassageBoundary, 0 ) +
4 + pArgs->lengths[0]; // document
CSphBuffer tBuffer(iSize);
@@ -721,6 +735,13 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi
tBuffer.SendInt ( pOpts->m_iLimit );
tBuffer.SendInt ( pOpts->m_iAround );
+ tBuffer.SendInt ( pOpts->m_iLimitPassages );
+ tBuffer.SendInt ( pOpts->m_iLimitWords );
+ tBuffer.SendInt ( pOpts->m_iPassageId );
+
+ SEND_STRING ( pOpts->m_iStripMode, "index" );
+ SEND_STRING ( pOpts->m_iPassageBoundary, "" );
+
// single document
tBuffer.SendInt ( 1 );
tBuffer.SendString ( ARG(0) );
@@ -733,22 +754,22 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi
my_error ( ER_QUERY_ON_FOREIGN_DATA_SOURCE, MYF(0), "INTERNAL ERROR: failed to build request" );
break;
}
-
+
iSocket = pOpts->m_tUrl.Connect();
- if ( iSocket == -1 ) break;
+ if ( iSocket==-1 ) break;
if ( !sphSend ( iSocket, tBuffer.Ptr(), iSize, sphReportErrors ) ) break;
- CSphResponse * pResponse = CSphResponse::Read ( iSocket, 0x100 );
+ CSphResponse * pResponse = CSphResponse::Read ( iSocket, VER_COMMAND_EXCERPT );
if ( !pResponse ) break;
close ( iSocket );
pOpts->m_pResponse = pResponse;
- *pLength = ntohl( *(DWORD *)pResponse->m_pBody );
+ *pLength = ntohl ( *(DWORD *)pResponse->m_pBody );
return pResponse->m_pBody + sizeof(DWORD);
}
while(0);
- if ( iSocket != -1 )
+ if ( iSocket!=-1 )
close ( iSocket );
*pError = 1;
@@ -756,7 +777,7 @@ char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsi
}
#undef SEND_STRING
-#undef ARG_LEN
+#undef ARG_LEN
#undef ARG
void sphinx_snippets_deinit ( UDF_INIT * pUDF )
@@ -766,5 +787,5 @@ void sphinx_snippets_deinit ( UDF_INIT * pUDF )
}
//
-// $Id: snippets_udf.cc 2058 2009-11-07 04:01:57Z shodan $
+// $Id: snippets_udf.cc 3087 2012-01-30 23:07:35Z shodan $
//
diff --git a/storage/sphinx/sphinx.5.0.22.diff b/storage/sphinx/sphinx.5.0.22.diff
deleted file mode 100644
index 7dd4ebf1410..00000000000
--- a/storage/sphinx/sphinx.5.0.22.diff
+++ /dev/null
@@ -1,284 +0,0 @@
-diff -B -N -r -u mysql-5.0.22/config/ac-macros/ha_sphinx.m4 mysql-5.0.22.sx/config/ac-macros/ha_sphinx.m4
---- mysql-5.0.22/config/ac-macros/ha_sphinx.m4 1970-01-01 01:00:00.000000000 +0100
-+++ mysql-5.0.22.sx/config/ac-macros/ha_sphinx.m4 2006-06-06 19:49:38.000000000 +0200
-@@ -0,0 +1,30 @@
-+dnl ---------------------------------------------------------------------------
-+dnl Macro: MYSQL_CHECK_EXAMPLEDB
-+dnl Sets HAVE_SPHINX_DB if --with-sphinx-storage-engine is used
-+dnl ---------------------------------------------------------------------------
-+AC_DEFUN([MYSQL_CHECK_SPHINXDB], [
-+ AC_ARG_WITH([sphinx-storage-engine],
-+ [
-+ --with-sphinx-storage-engine
-+ Enable the Sphinx Storage Engine],
-+ [sphinxdb="$withval"],
-+ [sphinxdb=no])
-+ AC_MSG_CHECKING([for example storage engine])
-+
-+ case "$sphinxdb" in
-+ yes )
-+ AC_DEFINE([HAVE_SPHINX_DB], [1], [Builds Sphinx Engine])
-+ AC_MSG_RESULT([yes])
-+ [sphinxdb=yes]
-+ ;;
-+ * )
-+ AC_MSG_RESULT([no])
-+ [sphinxdb=no]
-+ ;;
-+ esac
-+
-+])
-+dnl ---------------------------------------------------------------------------
-+dnl END OF MYSQL_CHECK_EXAMPLE SECTION
-+dnl ---------------------------------------------------------------------------
-+
-diff -B -N -r -u mysql-5.0.22/configure.in mysql-5.0.22.sx/configure.in
---- mysql-5.0.22/configure.in 2006-05-25 10:56:45.000000000 +0200
-+++ mysql-5.0.22.sx/configure.in 2006-06-06 19:49:38.000000000 +0200
-@@ -41,6 +41,7 @@
- sinclude(config/ac-macros/ha_berkeley.m4)
- sinclude(config/ac-macros/ha_blackhole.m4)
- sinclude(config/ac-macros/ha_example.m4)
-+sinclude(config/ac-macros/ha_sphinx.m4)
- sinclude(config/ac-macros/ha_federated.m4)
- sinclude(config/ac-macros/ha_innodb.m4)
- sinclude(config/ac-macros/ha_ndbcluster.m4)
-@@ -2450,6 +2451,7 @@
- MYSQL_CHECK_BDB
- MYSQL_CHECK_INNODB
- MYSQL_CHECK_EXAMPLEDB
-+MYSQL_CHECK_SPHINXDB
- MYSQL_CHECK_ARCHIVEDB
- MYSQL_CHECK_CSVDB
- MYSQL_CHECK_BLACKHOLEDB
-diff -B -N -r -u mysql-5.0.22/libmysqld/Makefile.am mysql-5.0.22.sx/libmysqld/Makefile.am
---- mysql-5.0.22/libmysqld/Makefile.am 2006-05-25 10:56:55.000000000 +0200
-+++ mysql-5.0.22.sx/libmysqld/Makefile.am 2006-06-06 19:49:38.000000000 +0200
-@@ -27,7 +27,7 @@
- -DSHAREDIR="\"$(MYSQLSHAREdir)\""
- INCLUDES= @bdb_includes@ \
- -I$(top_builddir)/include -I$(top_srcdir)/include \
-- -I$(top_srcdir)/sql -I$(top_srcdir)/sql/examples \
-+ -I$(top_srcdir)/sql -I$(top_srcdir)/sql/examples -I$(top_srcdir)/sql/sphinx \
- -I$(top_srcdir)/regex \
- $(openssl_includes) $(yassl_includes) @ZLIB_INCLUDES@
-
-@@ -38,6 +38,7 @@
- libmysqlsources = errmsg.c get_password.c libmysql.c client.c pack.c \
- my_time.c
- sqlexamplessources = ha_example.cc ha_tina.cc
-+sqlsphinxsources = ha_sphinx.cc
-
- noinst_HEADERS = embedded_priv.h emb_qcache.h
-
-@@ -65,7 +66,7 @@
- parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \
- ha_blackhole.cc ha_archive.cc my_user.c
-
--libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources)
-+libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources) $(sqlsphinxsources)
- libmysqld_a_SOURCES=
-
- # automake misses these
-@@ -133,12 +134,16 @@
- rm -f $$f; \
- @LN_CP_F@ $(top_srcdir)/sql/examples/$$f $$f; \
- done; \
-+ for f in $(sqlsphinxsources); do \
-+ rm -f $$f; \
-+ @LN_CP_F@ $(top_srcdir)/sql/sphinx/$$f $$f; \
-+ done; \
- rm -f client_settings.h; \
- @LN_CP_F@ $(top_srcdir)/libmysql/client_settings.h client_settings.h
-
-
- clean-local:
-- rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) | sed "s;\.lo;.c;g"` \
-+ rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) $(sqlsphinxsources) | sed "s;\.lo;.c;g"` \
- $(top_srcdir)/linked_libmysqld_sources; \
- rm -f client_settings.h
-
-diff -B -N -r -u mysql-5.0.22/sql/handler.cc mysql-5.0.22.sx/sql/handler.cc
---- mysql-5.0.22/sql/handler.cc 2006-05-25 10:56:42.000000000 +0200
-+++ mysql-5.0.22.sx/sql/handler.cc 2006-06-06 19:49:38.000000000 +0200
-@@ -78,6 +78,15 @@
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- HTON_NO_FLAGS };
- #endif
-+#ifdef HAVE_SPHINX_DB
-+#include "sphinx/ha_sphinx.h"
-+extern handlerton sphinx_hton;
-+#else
-+handlerton sphinx_hton = { "SPHINX", SHOW_OPTION_NO, "SPHINX storage engine",
-+ DB_TYPE_SPHINX_DB, NULL, 0, 0, NULL, NULL,
-+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-+ HTON_NO_FLAGS };
-+#endif
- #ifdef HAVE_INNOBASE_DB
- #include "ha_innodb.h"
- extern handlerton innobase_hton;
-@@ -147,6 +156,7 @@
- &example_hton,
- &archive_hton,
- &tina_hton,
-+ &sphinx_hton,
- &ndbcluster_hton,
- &federated_hton,
- &myisammrg_hton,
-@@ -345,6 +355,12 @@
- return new (alloc) ha_tina(table);
- return NULL;
- #endif
-+#ifdef HAVE_SPHINX_DB
-+ case DB_TYPE_SPHINX_DB:
-+ if (have_sphinx_db == SHOW_OPTION_YES)
-+ return new (alloc) ha_sphinx(table);
-+ return NULL;
-+#endif
- #ifdef HAVE_NDBCLUSTER_DB
- case DB_TYPE_NDBCLUSTER:
- if (have_ndbcluster == SHOW_OPTION_YES)
-diff -B -N -r -u mysql-5.0.22/sql/handler.h mysql-5.0.22.sx/sql/handler.h
---- mysql-5.0.22/sql/handler.h 2006-05-25 10:56:55.000000000 +0200
-+++ mysql-5.0.22.sx/sql/handler.h 2006-06-06 19:49:38.000000000 +0200
-@@ -183,8 +183,9 @@
- DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
- DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
- DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
-- DB_TYPE_FEDERATED_DB,
-+ DB_TYPE_FEDERATED_DB,
- DB_TYPE_BLACKHOLE_DB,
-+ DB_TYPE_SPHINX_DB,
- DB_TYPE_DEFAULT // Must be last
- };
-
-diff -B -N -r -u mysql-5.0.22/sql/Makefile.am mysql-5.0.22.sx/sql/Makefile.am
---- mysql-5.0.22/sql/Makefile.am 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/Makefile.am 2006-06-06 19:49:38.000000000 +0200
-@@ -66,6 +66,7 @@
- sql_array.h sql_cursor.h \
- examples/ha_example.h ha_archive.h \
- examples/ha_tina.h ha_blackhole.h \
-+ sphinx/ha_sphinx.h \
- ha_federated.h
- mysqld_SOURCES = sql_lex.cc sql_handler.cc \
- item.cc item_sum.cc item_buff.cc item_func.cc \
-@@ -102,6 +103,7 @@
- sp_cache.cc parse_file.cc sql_trigger.cc \
- examples/ha_example.cc ha_archive.cc \
- examples/ha_tina.cc ha_blackhole.cc \
-+ sphinx/ha_sphinx.cc \
- ha_federated.cc
-
- gen_lex_hash_SOURCES = gen_lex_hash.cc
-diff -B -N -r -u mysql-5.0.22/sql/mysqld.cc mysql-5.0.22.sx/sql/mysqld.cc
---- mysql-5.0.22/sql/mysqld.cc 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/mysqld.cc 2006-06-06 19:49:38.000000000 +0200
-@@ -6420,6 +6420,11 @@
- #else
- have_csv_db= SHOW_OPTION_NO;
- #endif
-+#ifdef HAVE_SPHINX_DB
-+ have_sphinx_db= SHOW_OPTION_YES;
-+#else
-+ have_sphinx_db= SHOW_OPTION_NO;
-+#endif
- #ifdef HAVE_NDBCLUSTER_DB
- have_ndbcluster=SHOW_OPTION_DISABLED;
- #else
-@@ -7457,6 +7462,7 @@
- #undef have_example_db
- #undef have_archive_db
- #undef have_csv_db
-+#undef have_sphinx_db
- #undef have_federated_db
- #undef have_partition_db
- #undef have_blackhole_db
-@@ -7467,6 +7473,7 @@
- SHOW_COMP_OPTION have_example_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_archive_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_csv_db= SHOW_OPTION_NO;
-+SHOW_COMP_OPTION have_sphinx_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_federated_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_partition_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_blackhole_db= SHOW_OPTION_NO;
-diff -B -N -r -u mysql-5.0.22/sql/mysql_priv.h mysql-5.0.22.sx/sql/mysql_priv.h
---- mysql-5.0.22/sql/mysql_priv.h 2006-05-25 10:56:43.000000000 +0200
-+++ mysql-5.0.22.sx/sql/mysql_priv.h 2006-06-06 19:49:38.000000000 +0200
-@@ -1279,6 +1279,12 @@
- #else
- extern SHOW_COMP_OPTION have_csv_db;
- #endif
-+#ifdef HAVE_SPHINX_DB
-+extern handlerton sphinx_hton;
-+#define have_sphinx_db sphinx_hton.state
-+#else
-+extern SHOW_COMP_OPTION have_sphinx_db;
-+#endif
- #ifdef HAVE_FEDERATED_DB
- extern handlerton federated_hton;
- #define have_federated_db federated_hton.state
-diff -B -N -r -u mysql-5.0.22/sql/set_var.cc mysql-5.0.22.sx/sql/set_var.cc
---- mysql-5.0.22/sql/set_var.cc 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/set_var.cc 2006-06-06 19:49:38.000000000 +0200
-@@ -809,6 +809,7 @@
- {"have_compress", (char*) &have_compress, SHOW_HAVE},
- {"have_crypt", (char*) &have_crypt, SHOW_HAVE},
- {"have_csv", (char*) &have_csv_db, SHOW_HAVE},
-+ {"have_sphinx", (char*) &have_sphinx_db, SHOW_HAVE},
- {"have_example_engine", (char*) &have_example_db, SHOW_HAVE},
- {"have_federated_engine", (char*) &have_federated_db, SHOW_HAVE},
- {"have_geometry", (char*) &have_geometry, SHOW_HAVE},
-diff -B -N -r -u mysql-5.0.22/sql/sql_lex.h mysql-5.0.22.sx/sql/sql_lex.h
---- mysql-5.0.22/sql/sql_lex.h 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/sql_lex.h 2006-06-06 19:49:38.000000000 +0200
-@@ -58,6 +58,7 @@
- SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
- SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_LOGS, SQLCOM_SHOW_STATUS,
- SQLCOM_SHOW_INNODB_STATUS, SQLCOM_SHOW_NDBCLUSTER_STATUS, SQLCOM_SHOW_MUTEX_STATUS,
-+ SQLCOM_SHOW_SPHINX_STATUS,
- SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
- SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
- SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
-diff -B -N -r -u mysql-5.0.22/sql/sql_parse.cc mysql-5.0.22.sx/sql/sql_parse.cc
---- mysql-5.0.22/sql/sql_parse.cc 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/sql_parse.cc 2006-06-06 19:49:38.000000000 +0200
-@@ -25,6 +25,9 @@
- #ifdef HAVE_INNOBASE_DB
- #include "ha_innodb.h"
- #endif
-+#ifdef HAVE_SPHINX_DB
-+#include "sphinx/ha_sphinx.h"
-+#endif
-
- #ifdef HAVE_NDBCLUSTER_DB
- #include "ha_ndbcluster.h"
-@@ -2722,6 +2725,15 @@
- break;
- }
- #endif
-+#ifdef HAVE_SPHINX_DB
-+ case SQLCOM_SHOW_SPHINX_STATUS:
-+ {
-+ if (check_global_access(thd, SUPER_ACL))
-+ goto error;
-+ res = sphinx_show_status(thd);
-+ break;
-+ }
-+#endif
- #ifdef HAVE_REPLICATION
- case SQLCOM_LOAD_MASTER_TABLE:
- {
-diff -B -N -r -u mysql-5.0.22/sql/sql_yacc.yy mysql-5.0.22.sx/sql/sql_yacc.yy
---- mysql-5.0.22/sql/sql_yacc.yy 2006-05-25 10:56:43.000000000 +0200
-+++ mysql-5.0.22.sx/sql/sql_yacc.yy 2006-06-06 19:49:38.000000000 +0200
-@@ -6584,6 +6584,9 @@
- case DB_TYPE_INNODB:
- Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;
- break;
-+ case DB_TYPE_SPHINX_DB:
-+ Lex->sql_command = SQLCOM_SHOW_SPHINX_STATUS;
-+ break;
- default:
- my_error(ER_NOT_SUPPORTED_YET, MYF(0), "STATUS");
- YYABORT;
diff --git a/storage/sphinx/sphinx.5.0.27.diff b/storage/sphinx/sphinx.5.0.27.diff
deleted file mode 100644
index 9ff6cf4fe48..00000000000
--- a/storage/sphinx/sphinx.5.0.27.diff
+++ /dev/null
@@ -1,284 +0,0 @@
-diff -B -N -r -u mysql-5.0.22/config/ac-macros/ha_sphinx.m4 mysql-5.0.22.sx/config/ac-macros/ha_sphinx.m4
---- mysql-5.0.22/config/ac-macros/ha_sphinx.m4 1970-01-01 01:00:00.000000000 +0100
-+++ mysql-5.0.22.sx/config/ac-macros/ha_sphinx.m4 2006-06-06 19:49:38.000000000 +0200
-@@ -0,0 +1,30 @@
-+dnl ---------------------------------------------------------------------------
-+dnl Macro: MYSQL_CHECK_EXAMPLEDB
-+dnl Sets HAVE_SPHINX_DB if --with-sphinx-storage-engine is used
-+dnl ---------------------------------------------------------------------------
-+AC_DEFUN([MYSQL_CHECK_SPHINXDB], [
-+ AC_ARG_WITH([sphinx-storage-engine],
-+ [
-+ --with-sphinx-storage-engine
-+ Enable the Sphinx Storage Engine],
-+ [sphinxdb="$withval"],
-+ [sphinxdb=no])
-+ AC_MSG_CHECKING([for example storage engine])
-+
-+ case "$sphinxdb" in
-+ yes )
-+ AC_DEFINE([HAVE_SPHINX_DB], [1], [Builds Sphinx Engine])
-+ AC_MSG_RESULT([yes])
-+ [sphinxdb=yes]
-+ ;;
-+ * )
-+ AC_MSG_RESULT([no])
-+ [sphinxdb=no]
-+ ;;
-+ esac
-+
-+])
-+dnl ---------------------------------------------------------------------------
-+dnl END OF MYSQL_CHECK_EXAMPLE SECTION
-+dnl ---------------------------------------------------------------------------
-+
-diff -B -N -r -u mysql-5.0.22/configure.in mysql-5.0.22.sx/configure.in
---- mysql-5.0.22/configure.in 2006-05-25 10:56:45.000000000 +0200
-+++ mysql-5.0.22.sx/configure.in 2006-06-06 19:49:38.000000000 +0200
-@@ -41,6 +41,7 @@
- sinclude(config/ac-macros/ha_berkeley.m4)
- sinclude(config/ac-macros/ha_blackhole.m4)
- sinclude(config/ac-macros/ha_example.m4)
-+sinclude(config/ac-macros/ha_sphinx.m4)
- sinclude(config/ac-macros/ha_federated.m4)
- sinclude(config/ac-macros/ha_innodb.m4)
- sinclude(config/ac-macros/ha_ndbcluster.m4)
-@@ -2450,6 +2451,7 @@
- MYSQL_CHECK_BDB
- MYSQL_CHECK_INNODB
- MYSQL_CHECK_EXAMPLEDB
-+MYSQL_CHECK_SPHINXDB
- MYSQL_CHECK_ARCHIVEDB
- MYSQL_CHECK_CSVDB
- MYSQL_CHECK_BLACKHOLEDB
-diff -B -N -r -u mysql-5.0.22/libmysqld/Makefile.am mysql-5.0.22.sx/libmysqld/Makefile.am
---- mysql-5.0.22/libmysqld/Makefile.am 2006-05-25 10:56:55.000000000 +0200
-+++ mysql-5.0.22.sx/libmysqld/Makefile.am 2006-06-06 19:49:38.000000000 +0200
-@@ -27,7 +27,7 @@
- -DSHAREDIR="\"$(MYSQLSHAREdir)\""
- INCLUDES= @bdb_includes@ \
- -I$(top_builddir)/include -I$(top_srcdir)/include \
-- -I$(top_srcdir)/sql -I$(top_srcdir)/sql/examples \
-+ -I$(top_srcdir)/sql -I$(top_srcdir)/sql/examples -I$(top_srcdir)/sql/sphinx \
- -I$(top_srcdir)/regex \
- $(openssl_includes) $(yassl_includes) @ZLIB_INCLUDES@
-
-@@ -38,6 +38,7 @@
- libmysqlsources = errmsg.c get_password.c libmysql.c client.c pack.c \
- my_time.c
- sqlexamplessources = ha_example.cc ha_tina.cc
-+sqlsphinxsources = ha_sphinx.cc
-
- noinst_HEADERS = embedded_priv.h emb_qcache.h
-
-@@ -65,7 +66,7 @@
- parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \
- ha_blackhole.cc ha_archive.cc my_user.c
-
--libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources)
-+libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources) $(sqlsphinxsources)
- libmysqld_a_SOURCES=
-
- # automake misses these
-@@ -133,12 +134,16 @@
- rm -f $$f; \
- @LN_CP_F@ $(top_srcdir)/sql/examples/$$f $$f; \
- done; \
-+ for f in $(sqlsphinxsources); do \
-+ rm -f $$f; \
-+ @LN_CP_F@ $(top_srcdir)/sql/sphinx/$$f $$f; \
-+ done; \
- rm -f client_settings.h; \
- @LN_CP_F@ $(top_srcdir)/libmysql/client_settings.h client_settings.h
-
-
- clean-local:
-- rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) | sed "s;\.lo;.c;g"` \
-+ rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) $(sqlsphinxsources) | sed "s;\.lo;.c;g"` \
- $(top_srcdir)/linked_libmysqld_sources; \
- rm -f client_settings.h
-
-diff -B -N -r -u mysql-5.0.22/sql/handler.cc mysql-5.0.22.sx/sql/handler.cc
---- mysql-5.0.22/sql/handler.cc 2006-05-25 10:56:42.000000000 +0200
-+++ mysql-5.0.22.sx/sql/handler.cc 2006-06-06 19:49:38.000000000 +0200
-@@ -78,6 +78,15 @@
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- HTON_NO_FLAGS };
- #endif
-+#ifdef HAVE_SPHINX_DB
-+#include "sphinx/ha_sphinx.h"
-+extern handlerton sphinx_hton;
-+#else
-+handlerton sphinx_hton = { "SPHINX", SHOW_OPTION_NO, "SPHINX storage engine",
-+ DB_TYPE_SPHINX_DB, NULL, 0, 0, NULL, NULL,
-+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-+ HTON_NO_FLAGS };
-+#endif
- #ifdef HAVE_INNOBASE_DB
- #include "ha_innodb.h"
- extern handlerton innobase_hton;
-@@ -147,6 +156,7 @@
- &example_hton,
- &archive_hton,
- &tina_hton,
-+ &sphinx_hton,
- &ndbcluster_hton,
- &federated_hton,
- &myisammrg_hton,
-@@ -345,6 +355,12 @@
- return new (alloc) ha_tina(table);
- return NULL;
- #endif
-+#ifdef HAVE_SPHINX_DB
-+ case DB_TYPE_SPHINX_DB:
-+ if (have_sphinx_db == SHOW_OPTION_YES)
-+ return new (alloc) ha_sphinx(table);
-+ return NULL;
-+#endif
- #ifdef HAVE_NDBCLUSTER_DB
- case DB_TYPE_NDBCLUSTER:
- if (have_ndbcluster == SHOW_OPTION_YES)
-diff -B -N -r -u mysql-5.0.22/sql/handler.h mysql-5.0.22.sx/sql/handler.h
---- mysql-5.0.22/sql/handler.h 2006-05-25 10:56:55.000000000 +0200
-+++ mysql-5.0.22.sx/sql/handler.h 2006-06-06 19:49:38.000000000 +0200
-@@ -183,8 +183,9 @@
- DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
- DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
- DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
-- DB_TYPE_FEDERATED_DB,
-+ DB_TYPE_FEDERATED_DB,
- DB_TYPE_BLACKHOLE_DB,
-+ DB_TYPE_SPHINX_DB,
- DB_TYPE_DEFAULT // Must be last
- };
-
-diff -B -N -r -u mysql-5.0.22/sql/Makefile.am mysql-5.0.22.sx/sql/Makefile.am
---- mysql-5.0.22/sql/Makefile.am 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/Makefile.am 2006-06-06 19:49:38.000000000 +0200
-@@ -66,6 +66,7 @@
- sql_array.h sql_cursor.h \
- examples/ha_example.h ha_archive.h \
- examples/ha_tina.h ha_blackhole.h \
-+ sphinx/ha_sphinx.h \
- ha_federated.h
- mysqld_SOURCES = sql_lex.cc sql_handler.cc \
- item.cc item_sum.cc item_buff.cc item_func.cc \
-@@ -102,6 +103,7 @@
- sp_cache.cc parse_file.cc sql_trigger.cc \
- examples/ha_example.cc ha_archive.cc \
- examples/ha_tina.cc ha_blackhole.cc \
-+ sphinx/ha_sphinx.cc \
- ha_federated.cc
-
- gen_lex_hash_SOURCES = gen_lex_hash.cc
-diff -B -N -r -u mysql-5.0.22/sql/mysqld.cc mysql-5.0.22.sx/sql/mysqld.cc
---- mysql-5.0.22/sql/mysqld.cc 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/mysqld.cc 2006-06-06 19:49:38.000000000 +0200
-@@ -6420,6 +6420,11 @@
- #else
- have_csv_db= SHOW_OPTION_NO;
- #endif
-+#ifdef HAVE_SPHINX_DB
-+ have_sphinx_db= SHOW_OPTION_YES;
-+#else
-+ have_sphinx_db= SHOW_OPTION_NO;
-+#endif
- #ifdef HAVE_NDBCLUSTER_DB
- have_ndbcluster=SHOW_OPTION_DISABLED;
- #else
-@@ -7457,6 +7462,7 @@
- #undef have_example_db
- #undef have_archive_db
- #undef have_csv_db
-+#undef have_sphinx_db
- #undef have_federated_db
- #undef have_partition_db
- #undef have_blackhole_db
-@@ -7467,6 +7473,7 @@
- SHOW_COMP_OPTION have_example_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_archive_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_csv_db= SHOW_OPTION_NO;
-+SHOW_COMP_OPTION have_sphinx_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_federated_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_partition_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_blackhole_db= SHOW_OPTION_NO;
-diff -B -N -r -u mysql-5.0.22/sql/mysql_priv.h mysql-5.0.22.sx/sql/mysql_priv.h
---- mysql-5.0.22/sql/mysql_priv.h 2006-05-25 10:56:43.000000000 +0200
-+++ mysql-5.0.22.sx/sql/mysql_priv.h 2006-06-06 19:49:38.000000000 +0200
-@@ -1279,6 +1279,12 @@
- #else
- extern SHOW_COMP_OPTION have_csv_db;
- #endif
-+#ifdef HAVE_SPHINX_DB
-+extern handlerton sphinx_hton;
-+#define have_sphinx_db sphinx_hton.state
-+#else
-+extern SHOW_COMP_OPTION have_sphinx_db;
-+#endif
- #ifdef HAVE_FEDERATED_DB
- extern handlerton federated_hton;
- #define have_federated_db federated_hton.state
-diff -B -N -r -u mysql-5.0.22/sql/set_var.cc mysql-5.0.22.sx/sql/set_var.cc
---- mysql-5.0.22/sql/set_var.cc 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/set_var.cc 2006-06-06 19:49:38.000000000 +0200
-@@ -864,6 +864,7 @@
- {"have_compress", (char*) &have_compress, SHOW_HAVE},
- {"have_crypt", (char*) &have_crypt, SHOW_HAVE},
- {"have_csv", (char*) &have_csv_db, SHOW_HAVE},
-+ {"have_sphinx", (char*) &have_sphinx_db, SHOW_HAVE},
- {"have_dynamic_loading", (char*) &have_dlopen, SHOW_HAVE},
- {"have_example_engine", (char*) &have_example_db, SHOW_HAVE},
- {"have_federated_engine", (char*) &have_federated_db, SHOW_HAVE},
-diff -B -N -r -u mysql-5.0.22/sql/sql_lex.h mysql-5.0.22.sx/sql/sql_lex.h
---- mysql-5.0.22/sql/sql_lex.h 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/sql_lex.h 2006-06-06 19:49:38.000000000 +0200
-@@ -58,6 +58,7 @@
- SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
- SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_LOGS, SQLCOM_SHOW_STATUS,
- SQLCOM_SHOW_INNODB_STATUS, SQLCOM_SHOW_NDBCLUSTER_STATUS, SQLCOM_SHOW_MUTEX_STATUS,
-+ SQLCOM_SHOW_SPHINX_STATUS,
- SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
- SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
- SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
-diff -B -N -r -u mysql-5.0.22/sql/sql_parse.cc mysql-5.0.22.sx/sql/sql_parse.cc
---- mysql-5.0.22/sql/sql_parse.cc 2006-05-25 10:56:41.000000000 +0200
-+++ mysql-5.0.22.sx/sql/sql_parse.cc 2006-06-06 19:49:38.000000000 +0200
-@@ -25,6 +25,9 @@
- #ifdef HAVE_INNOBASE_DB
- #include "ha_innodb.h"
- #endif
-+#ifdef HAVE_SPHINX_DB
-+#include "sphinx/ha_sphinx.h"
-+#endif
-
- #ifdef HAVE_NDBCLUSTER_DB
- #include "ha_ndbcluster.h"
-@@ -2722,6 +2725,15 @@
- break;
- }
- #endif
-+#ifdef HAVE_SPHINX_DB
-+ case SQLCOM_SHOW_SPHINX_STATUS:
-+ {
-+ if (check_global_access(thd, SUPER_ACL))
-+ goto error;
-+ res = sphinx_show_status(thd);
-+ break;
-+ }
-+#endif
- #ifdef HAVE_REPLICATION
- case SQLCOM_LOAD_MASTER_TABLE:
- {
-diff -B -N -r -u mysql-5.0.22/sql/sql_yacc.yy mysql-5.0.22.sx/sql/sql_yacc.yy
---- mysql-5.0.22/sql/sql_yacc.yy 2006-05-25 10:56:43.000000000 +0200
-+++ mysql-5.0.22.sx/sql/sql_yacc.yy 2006-06-06 19:49:38.000000000 +0200
-@@ -6584,6 +6584,9 @@
- case DB_TYPE_INNODB:
- Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;
- break;
-+ case DB_TYPE_SPHINX_DB:
-+ Lex->sql_command = SQLCOM_SHOW_SPHINX_STATUS;
-+ break;
- default:
- my_error(ER_NOT_SUPPORTED_YET, MYF(0), "STATUS");
- YYABORT;
diff --git a/storage/sphinx/sphinx.5.0.37.diff b/storage/sphinx/sphinx.5.0.37.diff
deleted file mode 100644
index 3f86e545b4d..00000000000
--- a/storage/sphinx/sphinx.5.0.37.diff
+++ /dev/null
@@ -1,338 +0,0 @@
---- mysql-5.0.67/config/ac-macros/ha_sphinx.m4 1970-01-01 10:00:00.000000000 +1000
-+++ mysql-5.0.67-sphinx/config/ac-macros/ha_sphinx.m4 2009-02-14 09:15:48.000000000 +1000
-@@ -0,0 +1,30 @@
-+dnl ---------------------------------------------------------------------------
-+dnl Macro: MYSQL_CHECK_EXAMPLEDB
-+dnl Sets HAVE_SPHINX_DB if --with-sphinx-storage-engine is used
-+dnl ---------------------------------------------------------------------------
-+AC_DEFUN([MYSQL_CHECK_SPHINXDB], [
-+ AC_ARG_WITH([sphinx-storage-engine],
-+ [
-+ --with-sphinx-storage-engine
-+ Enable the Sphinx Storage Engine],
-+ [sphinxdb="$withval"],
-+ [sphinxdb=no])
-+ AC_MSG_CHECKING([for example storage engine])
-+
-+ case "$sphinxdb" in
-+ yes )
-+ AC_DEFINE([HAVE_SPHINX_DB], [1], [Builds Sphinx Engine])
-+ AC_MSG_RESULT([yes])
-+ [sphinxdb=yes]
-+ ;;
-+ * )
-+ AC_MSG_RESULT([no])
-+ [sphinxdb=no]
-+ ;;
-+ esac
-+
-+])
-+dnl ---------------------------------------------------------------------------
-+dnl END OF MYSQL_CHECK_EXAMPLE SECTION
-+dnl ---------------------------------------------------------------------------
-+
---- mysql-5.0.67/configure.in 2008-08-04 23:19:07.000000000 +1100
-+++ mysql-5.0.67-sphinx/configure.in 2009-02-14 09:15:48.000000000 +1000
-@@ -58,6 +58,7 @@
- sinclude(config/ac-macros/ha_berkeley.m4)
- sinclude(config/ac-macros/ha_blackhole.m4)
- sinclude(config/ac-macros/ha_example.m4)
-+sinclude(config/ac-macros/ha_sphinx.m4)
- sinclude(config/ac-macros/ha_federated.m4)
- sinclude(config/ac-macros/ha_innodb.m4)
- sinclude(config/ac-macros/ha_ndbcluster.m4)
-@@ -2625,6 +2626,7 @@
- MYSQL_CHECK_BDB
- MYSQL_CHECK_INNODB
- MYSQL_CHECK_EXAMPLEDB
-+MYSQL_CHECK_SPHINXDB
- MYSQL_CHECK_ARCHIVEDB
- MYSQL_CHECK_CSVDB
- MYSQL_CHECK_BLACKHOLEDB
---- mysql-5.0.67/libmysqld/Makefile.am 2008-08-04 23:19:18.000000000 +1100
-+++ mysql-5.0.67-sphinx/libmysqld/Makefile.am 2009-02-14 09:15:48.000000000 +1000
-@@ -29,6 +29,7 @@
- -I$(top_builddir)/include -I$(top_srcdir)/include \
- -I$(top_builddir)/sql -I$(top_srcdir)/sql \
- -I$(top_srcdir)/sql/examples \
-+ -I$(top_srcdir)/sql/sphinx \
- -I$(top_srcdir)/regex \
- $(openssl_includes) @ZLIB_INCLUDES@
-
-@@ -39,6 +40,7 @@
- libmysqlsources = errmsg.c get_password.c libmysql.c client.c pack.c \
- my_time.c
- sqlexamplessources = ha_example.cc ha_tina.cc
-+sqlsphinxsources = ha_sphinx.cc
-
- noinst_HEADERS = embedded_priv.h emb_qcache.h
-
-@@ -67,7 +69,7 @@
- parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \
- ha_blackhole.cc ha_archive.cc my_user.c
-
--libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources)
-+libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources) $(sqlsphinxsources)
- libmysqld_a_SOURCES=
-
- # automake misses these
-@@ -147,12 +149,16 @@
- rm -f $$f; \
- @LN_CP_F@ $(top_srcdir)/sql/examples/$$f $$f; \
- done; \
-+ for f in $(sqlsphinxsources); do \
-+ rm -f $$f; \
-+ @LN_CP_F@ $(top_srcdir)/sql/sphinx/$$f $$f; \
-+ done; \
- rm -f client_settings.h; \
- @LN_CP_F@ $(top_srcdir)/libmysql/client_settings.h client_settings.h
-
-
- clean-local:
-- rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) | sed "s;\.lo;.c;g"` \
-+ rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlexamplessources) $(sqlsphinxsources) | sed "s;\.lo;.c;g"` \
- $(top_srcdir)/linked_libmysqld_sources; \
- rm -f client_settings.h
-
---- mysql-5.0.67/sql/handler.cc 2008-08-04 23:20:04.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/handler.cc 2009-02-14 09:15:48.000000000 +1000
-@@ -77,6 +77,15 @@
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- HTON_NO_FLAGS };
- #endif
-+#ifdef HAVE_SPHINX_DB
-+#include "sphinx/ha_sphinx.h"
-+extern handlerton sphinx_hton;
-+#else
-+handlerton sphinx_hton = { "SPHINX", SHOW_OPTION_NO, "SPHINX storage engine",
-+ DB_TYPE_SPHINX_DB, NULL, 0, 0, NULL, NULL,
-+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-+ HTON_NO_FLAGS };
-+#endif
- #ifdef HAVE_INNOBASE_DB
- #include "ha_innodb.h"
- extern handlerton innobase_hton;
-@@ -141,6 +150,7 @@
- &example_hton,
- &archive_hton,
- &tina_hton,
-+ &sphinx_hton,
- &ndbcluster_hton,
- &federated_hton,
- &myisammrg_hton,
-@@ -341,6 +351,12 @@
- return new (alloc) ha_tina(table);
- return NULL;
- #endif
-+#ifdef HAVE_SPHINX_DB
-+ case DB_TYPE_SPHINX_DB:
-+ if (have_sphinx_db == SHOW_OPTION_YES)
-+ return new (alloc) ha_sphinx(table);
-+ return NULL;
-+#endif
- #ifdef HAVE_NDBCLUSTER_DB
- case DB_TYPE_NDBCLUSTER:
- if (have_ndbcluster == SHOW_OPTION_YES)
---- mysql-5.0.67/sql/handler.h 2008-08-04 23:20:04.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/handler.h 2009-02-14 09:15:48.000000000 +1000
-@@ -186,8 +186,9 @@
- DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
- DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
- DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
-- DB_TYPE_FEDERATED_DB,
-+ DB_TYPE_FEDERATED_DB,
- DB_TYPE_BLACKHOLE_DB,
-+ DB_TYPE_SPHINX_DB,
- DB_TYPE_DEFAULT // Must be last
- };
-
---- mysql-5.0.67/sql/Makefile.am 2008-08-04 23:20:02.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/Makefile.am 2009-02-14 09:23:28.000000000 +1000
-@@ -68,6 +68,7 @@
- sql_array.h sql_cursor.h \
- examples/ha_example.h ha_archive.h \
- examples/ha_tina.h ha_blackhole.h \
-+ sphinx/ha_sphinx.h \
- ha_federated.h
- mysqld_SOURCES = sql_lex.cc sql_handler.cc \
- item.cc item_sum.cc item_buff.cc item_func.cc \
-@@ -105,6 +106,7 @@
- sp_cache.cc parse_file.cc sql_trigger.cc \
- examples/ha_example.cc ha_archive.cc \
- examples/ha_tina.cc ha_blackhole.cc \
-+ sphinx/ha_sphinx.cc \
- ha_federated.cc
-
- gen_lex_hash_SOURCES = gen_lex_hash.cc
-@@ -174,6 +176,10 @@
- udf_example_la_SOURCES= udf_example.c
- udf_example_la_LDFLAGS= -module -rpath $(pkglibdir)
-
-+pkglib_LTLIBRARIES = sphinx/sphinx.la
-+sphinx_sphinx_la_SOURCES = sphinx/snippets_udf.cc
-+sphinx_sphinx_la_LDFLAGS = -module
-+
-
- # Don't update the files from bitkeeper
- %::SCCS/s.%
---- mysql-5.0.67/sql/mysqld.cc 2008-08-04 23:20:07.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/mysqld.cc 2009-02-14 09:15:48.000000000 +1000
-@@ -36,6 +36,10 @@
- #include <sys/prctl.h>
- #endif
-
-+#ifdef HAVE_SPHINX_DB
-+#include "sphinx/ha_sphinx.h"
-+#endif
-+
- #ifdef HAVE_INNOBASE_DB
- #define OPT_INNODB_DEFAULT 1
- #else
-@@ -6633,6 +6637,13 @@
- {"Threads_running", (char*) &thread_running, SHOW_INT_CONST},
- {"Uptime", (char*) 0, SHOW_STARTTIME},
- {"Uptime_since_flush_status",(char*) 0, SHOW_FLUSHTIME},
-+#ifdef HAVE_SPHINX_DB
-+ {"sphinx_total", (char *)sphinx_showfunc_total, SHOW_SPHINX_FUNC},
-+ {"sphinx_total_found", (char *)sphinx_showfunc_total_found, SHOW_SPHINX_FUNC},
-+ {"sphinx_time", (char *)sphinx_showfunc_time, SHOW_SPHINX_FUNC},
-+ {"sphinx_word_count", (char *)sphinx_showfunc_word_count, SHOW_SPHINX_FUNC},
-+ {"sphinx_words", (char *)sphinx_showfunc_words, SHOW_SPHINX_FUNC},
-+#endif
- {NullS, NullS, SHOW_LONG}
- };
-
-@@ -6875,6 +6886,11 @@
- #else
- have_csv_db= SHOW_OPTION_NO;
- #endif
-+#ifdef HAVE_SPHINX_DB
-+ have_sphinx_db= SHOW_OPTION_YES;
-+#else
-+ have_sphinx_db= SHOW_OPTION_NO;
-+#endif
- #ifdef HAVE_NDBCLUSTER_DB
- have_ndbcluster=SHOW_OPTION_DISABLED;
- #else
-@@ -7983,6 +7999,7 @@
- #undef have_example_db
- #undef have_archive_db
- #undef have_csv_db
-+#undef have_sphinx_db
- #undef have_federated_db
- #undef have_partition_db
- #undef have_blackhole_db
-@@ -7993,6 +8010,7 @@
- SHOW_COMP_OPTION have_example_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_archive_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_csv_db= SHOW_OPTION_NO;
-+SHOW_COMP_OPTION have_sphinx_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_federated_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_partition_db= SHOW_OPTION_NO;
- SHOW_COMP_OPTION have_blackhole_db= SHOW_OPTION_NO;
---- mysql-5.0.67/sql/mysql_priv.h 2008-08-04 23:20:07.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/mysql_priv.h 2009-02-14 09:15:48.000000000 +1000
-@@ -1439,6 +1439,12 @@
- #else
- extern SHOW_COMP_OPTION have_csv_db;
- #endif
-+#ifdef HAVE_SPHINX_DB
-+extern handlerton sphinx_hton;
-+#define have_sphinx_db sphinx_hton.state
-+#else
-+extern SHOW_COMP_OPTION have_sphinx_db;
-+#endif
- #ifdef HAVE_FEDERATED_DB
- extern handlerton federated_hton;
- #define have_federated_db federated_hton.state
---- mysql-5.0.67/sql/set_var.cc 2008-08-04 23:20:08.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/set_var.cc 2009-02-14 09:15:48.000000000 +1000
-@@ -888,6 +888,7 @@
- {"have_compress", (char*) &have_compress, SHOW_HAVE},
- {"have_crypt", (char*) &have_crypt, SHOW_HAVE},
- {"have_csv", (char*) &have_csv_db, SHOW_HAVE},
-+ {"have_sphinx", (char*) &have_sphinx_db, SHOW_HAVE},
- {"have_dynamic_loading", (char*) &have_dlopen, SHOW_HAVE},
- {"have_example_engine", (char*) &have_example_db, SHOW_HAVE},
- {"have_federated_engine", (char*) &have_federated_db, SHOW_HAVE},
---- mysql-5.0.67/sql/sql_lex.h 2008-08-04 23:20:10.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/sql_lex.h 2009-02-14 09:15:48.000000000 +1000
-@@ -57,6 +57,7 @@
- SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
- SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_LOGS, SQLCOM_SHOW_STATUS,
- SQLCOM_SHOW_INNODB_STATUS, SQLCOM_SHOW_NDBCLUSTER_STATUS, SQLCOM_SHOW_MUTEX_STATUS,
-+ SQLCOM_SHOW_SPHINX_STATUS,
- SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
- SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
- SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
---- mysql-5.0.67/sql/sql_parse.cc 2008-08-04 23:20:10.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/sql_parse.cc 2009-02-14 09:15:48.000000000 +1000
-@@ -24,6 +24,9 @@
- #ifdef HAVE_INNOBASE_DB
- #include "ha_innodb.h"
- #endif
-+#ifdef HAVE_SPHINX_DB
-+#include "sphinx/ha_sphinx.h"
-+#endif
-
- #ifdef HAVE_NDBCLUSTER_DB
- #include "ha_ndbcluster.h"
-@@ -3006,6 +3009,15 @@
- break;
- }
- #endif
-+#ifdef HAVE_SPHINX_DB
-+ case SQLCOM_SHOW_SPHINX_STATUS:
-+ {
-+ if (check_global_access(thd, SUPER_ACL))
-+ goto error;
-+ res = sphinx_show_status(thd);
-+ break;
-+ }
-+#endif
- #ifdef HAVE_REPLICATION
- case SQLCOM_LOAD_MASTER_TABLE:
- {
---- mysql-5.0.67/sql/sql_yacc.yy 2008-08-04 23:20:12.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/sql_yacc.yy 2009-02-14 09:15:48.000000000 +1000
-@@ -7393,6 +7393,9 @@
- case DB_TYPE_INNODB:
- Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;
- break;
-+ case DB_TYPE_SPHINX_DB:
-+ Lex->sql_command = SQLCOM_SHOW_SPHINX_STATUS;
-+ break;
- default:
- my_error(ER_NOT_SUPPORTED_YET, MYF(0), "STATUS");
- MYSQL_YYABORT;
---- mysql-5.0.67/sql/structs.h 2008-08-04 23:20:12.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/structs.h 2009-02-14 09:15:48.000000000 +1000
-@@ -188,6 +188,9 @@
- SHOW_SSL_CTX_SESS_TIMEOUTS, SHOW_SSL_CTX_SESS_CACHE_FULL,
- SHOW_SSL_GET_CIPHER_LIST,
- #endif /* HAVE_OPENSSL */
-+#ifdef HAVE_SPHINX_DB
-+ SHOW_SPHINX_FUNC,
-+#endif
- SHOW_NET_COMPRESSION,
- SHOW_RPL_STATUS, SHOW_SLAVE_RUNNING, SHOW_SLAVE_RETRIED_TRANS,
- SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_CONST_LONG, SHOW_KEY_CACHE_LONGLONG,
---- mysql-5.0.67/sql/sql_show.cc 2008-08-04 23:20:11.000000000 +1100
-+++ mysql-5.0.67-sphinx/sql/sql_show.cc 2009-02-14 09:15:48.000000000 +1000
-@@ -1473,6 +1473,16 @@
- value= (char*) ((sys_var*) value)->value_ptr(thd, value_type,
- &null_lex_str);
- }
-+ #ifdef HAVE_SPHINX_DB
-+ else if (show_type == SHOW_SPHINX_FUNC)
-+ {
-+ SHOW_VAR var;
-+ ((int (*)(THD *, SHOW_VAR *, char *))value)(thd, &var, buff);
-+
-+ value = var.value;
-+ show_type = var.type;
-+ }
-+ #endif /* HAVE_SPHINX_DB */
-
- pos= end= buff;
- switch (show_type) {